Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
theemathas opened this issue Sep 4, 2024 · 5 comments
Labels
A-trait-system Area: Trait system C-bug Category: This is a bug. E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@theemathas
Copy link
Contributor

theemathas commented Sep 4, 2024

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.

@theemathas theemathas added the C-bug Category: This is a bug. label Sep 4, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 4, 2024
@fmease fmease added A-trait-system Area: Trait system T-types Relevant to the types team, which will review and decide on the PR/issue. labels Sep 4, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 4, 2024
@workingjubilee workingjubilee added the E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc label Sep 5, 2024
@workingjubilee
Copy link
Member

Oh.

This is #30389

@workingjubilee workingjubilee closed this as not planned Won't fix, can't repro, duplicate, stale Sep 5, 2024
@theemathas
Copy link
Contributor Author

@workingjubilee How does this relate to RFC 1214? The RFC seems to imply that errors caused by the changes could be fixed by adding more bounds somewhere. And I can't figure out how to add such a bound for this case.

@compiler-errors
Copy link
Member

If you want to fix this, you need to write T: for<'r> SomeTrait<'r>. This is not fixable under the way the type system works today.

@workingjubilee
Copy link
Member

@theemathas The RFC is incomplete, I refer to this comment:

                // Typically, this ambiguity should only happen if
                // there are unresolved type inference variables
                // (otherwise it would suggest a coherence
                // failure). But given #21974 that is not necessarily
                // the case -- we can have multiple where clauses that
                // are only distinguished by a region, which results
                // in an ambiguity even when all types are fully
                // known, since we don't dispatch based on region
                // relationships.

@workingjubilee
Copy link
Member

alternatively this could also be considered a duplicate of #21974

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trait-system Area: Trait system C-bug Category: This is a bug. E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants