Compiling this code caused the compiler to block
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
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)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by compiling the standalone Rust reproducer with the stable and nightly rustc versions listed in the issue, confirming whether compilation still consumes excessive CPU and memory. Trace the compiler path involved in resolving the recursive trait and lifetime bounds; done means the example terminates with either a binary or a diagnostic instead of blocking indefinitely.
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
- Clearly specified
- Newbie friendliness
- 45/100