-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.
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)
Metadata
Metadata
Assignees
Labels
A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.