Impl has "stricter" requirement that is implied by existing requirement
Open
@compiler-errors is already working on this.
Since Dec 31, 2024.
A-implied-bounds
A-trait-system
C-bug
S-has-mcve
T-types
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
trait Foo {
type Assoc;
fn bar<'x>()
where
Self::Assoc: 'x;
}
impl<A: Foo> Foo for Option<A> {
type Assoc = Option<A::Assoc>;
fn bar<'x>()
where
Self::Assoc: 'x,
{
todo!()
}
}
I expect this to compile, but it gives the following error
error[E0276]: impl has stricter requirements than trait
--> src/lib.rs:14:22
|
4 | / fn bar<'x>()
5 | | where
6 | | Self::Assoc: 'x;
| |________________________- definition of `bar` from trait
...
14 | Self::Assoc: 'x,
| ^^ impl has extra requirement `<A as Foo>::Assoc: 'x`
The extra requirement <A as Foo>::Assoc: 'x that it mentions is actually implied by the real requirement Self::Assoc: 'x.
I think rust should always accept trait impls that have the exact same bounds as the trait defintion, that is why I labeled this as a bug.
Meta
rustc --version --verbose:
rustc 1.85.0-nightly (426d17342 2024-12-21)
binary: rustc
commit-hash: 426d1734238e3c5f52e935ba4f617f3a9f43b59d
commit-date: 2024-12-21
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.6
Same result on stable
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.
Assessment
This issue has not been assessed yet.