rust-lang / rust-lang/rust

Compiler Hang with High Memory Consumption during Compilation with Trait Implementation

Open
#117,257 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-hang T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

cat hang.rs

trait Trait {}
impl<T, U> Trait for (T, U)
where
    (U, T): Trait,
    (T, U): Trait {}
fn impls_constraint<T, U>()
where
    (T, U): ConstrainToU32<T>,
{
}
trait ConstrainToU32<T> {}
impl ConstrainToU32<u32> for () {}
fn impls_trait<T, U>()
where
    (T, U): Trait,
{
}
fn main() {
    impls_trait::<_, _>();
}

I expected to see this happen: The compiler compiles successfully or outputs an error message.

Instead, this happened: The code, as provided below, appears to encounter a hang. The code compilation consumes a lot of memory and eventually exits with return code 137.

Command

rustc hang.rs

Meta

rustc --version --verbose:

rustc 1.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: x86_64-unknown-linux-gnu
release: 1.73.0
LLVM version: 17.0.2

The same problem is reproduced on the nightly version(1.75.0-nightly (aa1a71e9e 2023-10-26))

what's more, to get more information,I also tried '-Z time-passes' (using nighly version):

Output

$ rustc hang.rs -Z time-passes
time:   0.000; rss:   29MB ->   32MB (   +2MB)  parse_crate
time:   0.003; rss:   36MB ->   49MB (  +14MB)  expand_crate
time:   0.003; rss:   36MB ->   49MB (  +14MB)  macro_expand_crate
time:   0.000; rss:   49MB ->   52MB (   +3MB)  prepare_outputs
time:   0.000; rss:   52MB ->   56MB (   +4MB)  type_collecting

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 provided hang.rs with rustc and, on nightly, -Z time-passes to confirm the hang and memory growth. The reported work reaches type_collecting; investigate that compiler stage and use the minimal example to isolate the trait-implementation cycle. Done means rustc terminates with an error or successful compilation without excessive memory use.

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.