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

Unexpected "impl has stricter requirements" with identical bounds #137639

Open
afetisov opened this issue Feb 25, 2025 · 1 comment
Open

Unexpected "impl has stricter requirements" with identical bounds #137639

afetisov opened this issue Feb 25, 2025 · 1 comment
Labels
A-trait-system Area: Trait system C-bug Category: This is a bug. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@afetisov
Copy link

I tried this code (playground):

trait Bar<T> {}

impl<T> Bar<T> for () {}

trait Foo<C> {
    type Out;
}

trait Quux {
    type A;

    fn quux<R>()
    where
        R: Foo<Self::A>,
        (): Bar<<R as Foo<Self::A>>::Out>,
    ;
}

impl Quux for () {
    type A = ();

    fn quux<R>()
    where
        R: Foo<Self::A>,
        (): Bar<<R as Foo<Self::A>>::Out>,
    {}
}

I expected to see this happen: the code compiles successfully.

Instead, this happened:

error[E0277]: the trait bound `R: Foo<()>` is not satisfied
  --> src/lib.rs:22:5
   |
22 | /     fn quux<R>()
23 | |     where
24 | |         R: Foo<Self::A>,
25 | |         (): Bar<<R as Foo<Self::A>>::Out>,
   | |__________________________________________^ the trait `Foo<()>` is not implemented for `R`

error[E0276]: impl has stricter requirements than trait
  --> src/lib.rs:24:12
   |
12 | /     fn quux<R>()
13 | |     where
14 | |         R: Foo<Self::A>,
15 | |         (): Bar<<R as Foo<Self::A>>::Out>,
16 | |     ;
   | |_____- definition of `quux` from trait
...
24 |           R: Foo<Self::A>,
   |              ^^^^^^^^^^^^ impl has extra requirement `R: Foo<()>`

error[E0277]: the trait bound `R: Foo<()>` is not satisfied
  --> src/lib.rs:22:8
   |
22 |     fn quux<R>()
   |        ^^^^ the trait `Foo<()>` is not implemented for `R`

error[E0277]: the trait bound `R: Foo<()>` is not satisfied
  --> src/lib.rs:25:13
   |
25 |         (): Bar<<R as Foo<Self::A>>::Out>,
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo<()>` is not implemented for `R`
   |
note: required by a bound in `Bar`
  --> src/lib.rs:1:11
   |
1  | trait Bar<T> {}
   |           ^ required by this bound in `Bar`

This error reproduces on stable-1.85, corresponding beta branch, and the nightly-2025-02-24 compiler.

@afetisov afetisov added the C-bug Category: This is a bug. label Feb 25, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 25, 2025
@compiler-errors
Copy link
Member

There's a few other bugs of this sort, perhaps take a look at the label fixed-by-next-solver. It has to do with certain kinds of conditions where the old trait solver gets confused about associated type bounds that can be "normalized" or simplified using themselves.

@compiler-errors compiler-errors added the fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. label Feb 25, 2025
@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. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 25, 2025
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. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. 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

4 participants