Can't override trait method with RPITIT if there's an unconstrained lifetime parameter.
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
trait Trait<'a> {}
trait Foo {
fn lol() -> impl Sized + use<Self>;
}
impl<'a, T: Trait<'a>> Foo for T {
fn lol() -> impl Sized + use<T> {}
}
I expected the above code to compile. Instead, I got the following error:
error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates
--> src/lib.rs:6:6
|
6 | impl<'a, T: Trait<'a>> Foo for T {
| ^^ unconstrained lifetime parameter
For more information about this error, try `rustc --explain E0207`.
Changing use<T> to use<'a, T> or use<Self> doesn't fix the error.
In contrast, the default trait method body can be "inherited" without any errors:
// compiles without errors
trait Trait<'a> {}
trait Foo {
fn lol() -> impl Sized + use<Self> {}
}
impl<'a, T: Trait<'a>> Foo for T {}
This seems very strange.
Meta
Reproducible on the playground with version 1.97.0-nightly (2026-05-04 cb40c25f6aebb637163d)
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 with the minimal reproducer in the Playground using the reported nightly version, and compare the explicit RPITIT implementation with the inherited default method. Confirm the E0207 diagnostic for the implementation and the successful compilation of the default; done means the behavior is resolved consistently with the intended lifetime handling.
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
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100