Unexpected "impl has stricter requirements" with identical bounds
Open
Nobody has claimed this yet.
A-trait-system
C-bug
fixed-by-next-solver
T-types
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the linked playground reproducer on stable 1.85, beta, and nightly-2025-02-24, then compare the diagnostics with the expected successful compilation. Trace the compiler handling of the identical Self::A and () bounds in the Quux implementation. Done means the example compiles without E0276 or E0277 and regression coverage is added where appropriate.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100