Polynomial slowdown in `impl Trait` composition
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.2k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
pub trait A<'a> {
fn or(&self, other: impl A<'a>) -> impl A<'a> {
()
}
}
impl<'a> A<'a> for () {
}
pub fn main() {
let x = ().or(()).or(());
let x = x.or(x).or(x).or(x);
let x = x.or(x).or(x).or(x);
let x = x.or(x).or(x).or(x);
let x = x.or(x).or(x).or(x);
let x = x.or(x).or(x).or(x);
let x = x.or(x).or(x).or(x);
let x = x.or(x).or(x).or(x);
let x = x.or(x).or(x).or(x);
let x = x.or(x).or(x).or(x);
let x = x.or(x).or(x).or(x);
}
I expected to see this happen: Give me lots of errors
Instead, this happened: Hang for a lot of time, then give me lots of errors
Meta
The issue persists both in stable and nightly.
I distilled this code from a real slowdown I encountered in a large code-base.
rustc --version --verbose:
rustc 1.87.0-nightly (617aad8c2 2025-02-24)
binary: rustc
commit-hash: 617aad8c2e8783f6df8e5d1f8bb1e4bcdc70aa7b
commit-date: 2025-02-24
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0
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
Use the supplied Rust reproducer and Playground link as the entry point; first reproduce the hang with the reported stable and nightly rustc versions and measure how compilation time grows. Done means a confirmed compiler diagnosis and an actionable fix or report; the issue names no source file or regression test.
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
- 38/100