Skip to content

Trait bound requiring the same trait with different lifetimes results in a compile error #129950

Closed as not planned
@theemathas

Description

@theemathas

I tried this code:

trait SomeTrait<'a> {}

fn foo<'a, 'b, T: SomeTrait<'a> + SomeTrait<'b>>() {}

I expected this code to compile, but instead I got this error:

   Compiling playground v0.0.1 (/playground)
error[E0283]: type annotations needed: cannot satisfy `T: SomeTrait<'a>`
 --> src/lib.rs:3:19
  |
3 | fn foo<'a, 'b, T: SomeTrait<'a> + SomeTrait<'b>>() {}
  |                   ^^^^^^^^^^^^^
  |
note: multiple `impl`s or `where` clauses satisfying `T: SomeTrait<'a>` found
 --> src/lib.rs:3:19
  |
3 | fn foo<'a, 'b, T: SomeTrait<'a> + SomeTrait<'b>>() {}
  |                   ^^^^^^^^^^^^^   ^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0283`.
error: could not compile `playground` (lib) due to 1 previous error

Meta

Reproduces on the playground on "Stable version: 1.80.1" and "Nightly version: 1.83.0-nightly (2024-09-03 d6c8169)"

This compiles in rust 1.3.0. ICEs in rust 1.4.0-1.6.0. Fails to compile in rust 1.7.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemC-bugCategory: This is a bug.E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustcT-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions