Skip to content

Compiler Hang with High Memory Consumption during Compilation with Trait Implementation #117257

Open
@iamanonymouscs

Description

@iamanonymouscs

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-hangIssue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions