E0195 when method lifetime used on a GAT inside an APIT in trait is inlined and unused
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 Query<'a, 's> {}
impl<'a, 's> Query<'a, 's> for &'a i32 {}
trait Foo {
type Query<'a, 's>: Query<'a, 's>;
fn read<'a, 's>(arg: impl Iterator<Item = Self::Query<'a, 's>>);
}
struct Bar;
impl Foo for Bar {
type Query<'a, 's> = &'a i32;
fn read<'a, 's>(_arg: impl Iterator<Item = &'a i32>) {}
}
I expected to see this happen:
This should compile since the Foo for Bar impl just resolved Self::Query<'a, 's> into its real type (&'a i32).
Instead, this happened:
error[E0195]: lifetime parameters or bounds on associated function `read` do not match the trait declaration
--> src/lib.rs:14:12
|
7 | fn read<'a, 's>(arg: impl Iterator<Item = Self::Query<'a, 's>>);
| -------- lifetimes in impl do not match this associated function in trait
...
14 | fn read<'a, 's>(_arg: impl Iterator<Item = &'a i32>) {}
| ^^^^^^^^ lifetimes do not match associated function in trait
However, if we change impl Iterator<Item = Xxx> to Xxx in both the trait and the impl, it compiles:
trait Query<'a, 's> {}
impl<'a, 's> Query<'a, 's> for &'a i32 {}
trait Foo {
type Query<'a, 's>: Query<'a, 's>;
fn read<'a, 's>(arg: Self::Query<'a, 's>);
}
struct Bar;
impl Foo for Bar {
type Query<'a, 's> = &'a i32;
fn read<'a, 's>(_arg: &'a i32) {}
}
Also works when the APIT is changed to a &dyn Iterator<Item = Xxx>:
trait Query<'a, 's> {}
impl<'a, 's> Query<'a, 's> for &'a i32 {}
trait Foo {
type Query<'a, 's>: Query<'a, 's>;
fn read<'a, 's>(arg: &dyn Iterator<Item = Self::Query<'a, 's>>);
}
struct Bar;
impl Foo for Bar {
type Query<'a, 's> = &'a i32;
fn read<'a, 's>(_arg: &dyn Iterator<Item = &'a i32>) {}
}
Meta
rustc --version --verbose:
1.92.0-nightly (2025-10-01 4da69dfff1929cc79872)
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 reproducer shown for src/lib.rs with the reported nightly rustc version and compare it with the working non-APIT variants. Trace handling of E0195 for a GAT used through an associated type in an argument-position impl Trait. Done means the APIT example compiles without the lifetime mismatch while the relevant regression behavior remains covered.
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