rust-lang / rust-lang/rust

Compiler hangs and consumes unbounded memory with complex trait bounds

Open
#126,952 8 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-trait-system C-bug fixed-by-next-solver I-compilemem I-hang T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

trait TraitWithOneGeneric<P> {
    fn method(&self);
}

impl<C, P1, P2> TraitWithOneGeneric<(P1, P2)> for C
where
    C: TraitWithOneGeneric<P1> + TraitWithOneGeneric<P2>,
{
    fn method(&self) {}
}

// Generic instead of impl trait also doesn't work
fn do_smth<P>(a: &&impl TraitWithOneGeneric<P>) {
    a.method(1, 2, 3, 4)
}

I expected to see this happen: Code should throw an error and rustc should exit (or compile)

Instead, this happened: rustc doesn't exit at all and leaks memory infinitely.

Meta

I ran this code either on rust playground or via rustc --crate-type rlib -v lib.rs

rustc --version --verbose:

rustc 1.81.0-nightly (6b0f4b5ec 2024-06-24)
binary: rustc
commit-hash: 6b0f4b5ec3aa707ecaa78230722117324a4ce23c
commit-date: 2024-06-24
host: x86_64-unknown-linux-gnu
release: 1.81.0-nightly
LLVM version: 18.1.7

Same behavior on stable:
rustc --version --verbose:

rustc 1.79.0 (129f3b996 2024-06-10)
binary: rustc
commit-hash: 129f3b9964af4d4a709d1383930ade12dfe7c081
commit-date: 2024-06-10
host: x86_64-unknown-linux-gnu
release: 1.79.0
LLVM version: 18.1.7

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by compiling the reproducer with rustc --crate-type rlib -v lib.rs and compare the stable and nightly behavior described in the issue. The work is done when rustc terminates with a diagnostic or successfully compiles without unbounded memory growth.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.