A lifetime-dependent bound is not merged into a higher-ranked lifetime bound
Open
Nobody has claimed this yet.
A-lifetimes
A-trait-system
C-bug
fixed-by-next-solver
T-compiler
T-types
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
MRE:
trait Lifetime<'a> {}
trait AnyLifetime: for<'a> Lifetime<'a> {}
struct A<T: AnyLifetime>(core::marker::PhantomData<T>);
trait MyTrait<'a> {}
impl<'a, T: AnyLifetime + Lifetime<'a>> MyTrait<'a> for A<T> {}
The last line produces an error
error[E0283]: type annotations needed: cannot satisfy `T: Lifetime<'a>`
--> src/main.rs:10:27
|
10 | impl<'a, T: AnyLifetime + Lifetime<'a>> MyTrait<'a> for A<T> {}
| ^^^^^^^^^^^^
|
note: multiple `impl`s or `where` clauses satisfying `T: Lifetime<'a>` found
--> src/main.rs:10:13
|
10 | impl<'a, T: AnyLifetime + Lifetime<'a>> MyTrait<'a> for A<T> {}
Clearly, if T: for<'a> Lifetime<'a> then T: Lifetime<'a>, so the second bound should have just been ignored.
This issue arises in a generated code (in my case, in serde-generated impls), so the additional bound cannot be removed manually.
Meta
rustc 1.88.0 (6b00bc388 2025-06-23)
binary: rustc
commit-hash: 6b00bc3880198600130e1cf62b8f8a93494488cc
commit-date: 2025-06-23
host: aarch64-apple-darwin
release: 1.88.0
LLVM version: 20.1.5
(same behavior on nightly)
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
Reproduce the MRE in src/main.rs with rustc 1.88.0 and nightly, then trace the compiler path handling lifetime bounds and higher-ranked lifetime bounds. Done means the impl is accepted without requiring the redundant Lifetime<'a> bound to be removed manually, with regression coverage for the reported case.
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
- 45/100