Skip to content

Compiler hangs and consumes unbounded memory with complex trait boundsΒ #126952

Open
@i1i1

Description

@i1i1

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemC-bugCategory: This is a bug.I-compilememIssue: Problems and improvements with respect to memory usage during compilation.I-hangIssue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.T-typesRelevant to the types team, which will review and decide on the PR/issue.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions