Skip to content

A lifetime-dependent bound is not merged into a higher-ranked lifetime bound #143304

Open
@fjarri

Description

@fjarri

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

No one assigned

    Labels

    C-bugCategory: This is a bug.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions