rust-lang / rust-lang/rust

Can't override trait method with RPITIT if there's an unconstrained lifetime parameter.

Open
#156,178 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-coherence A-impl-trait A-lifetimes A-trait-system C-bug T-types
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.