- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Open
Labels
C-bugCategory: This is a bug.Category: This is a bug.I-hangIssue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.Issue: 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.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
I tried this code:
pub trait Trait<T> {
    fn f(&self) -> T;
}
pub struct S1<'a>(pub &'a Box<S3<'a>>);
pub struct S2<'a>(pub Vec<S1<'a>>);
pub struct S3<'a>(pub Vec<S2<'a>>);
impl<T> Trait<T> for S1<'_>
where
    for<'a> S1<'a>: Trait<T>,
    for<'a> S3<'a>: Trait<T>,
{
    fn f(&self) -> T {
        self.0.f()
    }
}
impl<T> Trait<T> for S2<'_>
where
    for<'a> S1<'a>: Trait<T>,
{
    fn f(&self) -> T {
        _ = self.0.iter().map(|s| s.f());
        todo!()
    }
}
impl<T> Trait<T> for S3<'_>
where
    for<'a> S2<'a>: Trait<T>,
{
    fn f(&self) -> T {
        _ = self.0.iter().map(|s| s.f());
        todo!()
    }
}
fn main() {
    S3(vec![]).f();
}I expected to see this happen: Compilation completed to obtain binary file, or compiler returns an error.
Instead, this happened: Increased CPU and memory usage, unable to compile or exit for a long time.
Meta
rustc --version --verbose:
rustc 1.78.0 (9b00956e5 2024-04-29)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: aarch64-apple-darwin
release: 1.78.0
LLVM version: 18.1.2
rustc +nightly --version --verbose:
rustc 1.80.0-nightly (791adf759 2024-05-21)
binary: rustc
commit-hash: 791adf759cc065316f054961875052d5bc03e16c
commit-date: 2024-05-21
host: aarch64-apple-darwin
release: 1.80.0-nightly
LLVM version: 18.1.6
Backtrace
RUST_BACKTRACE=1 cargo build:
   Compiling rs_block_compile v0.1.0 (/Users/umoho/Devs/rs_block_compile)
    Building [                             ] 0/1: rs_block_compile(bin) 
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.I-hangIssue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.Issue: 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.Relevant to the compiler team, which will review and decide on the PR/issue.