Adding where clause already filled relax traits bounds in impl
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.2k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
trait Foo {
type B;
}
struct A<T> {
a: T
}
trait Bar<T> {
fn bar(a: <A<T> as Foo>::B) {}
}
impl<T> Bar<T> for T
where
A<T>: Foo
{
fn bar(a: u32) {}
}
impl<T> Foo for A<T> {
type B = u32;
}
I expected it to compile, but instead I get the error
error[E0053]: method `bar` has an incompatible type for trait
--> src/main.rs:17:15
|
17 | fn bar(a: u32) {}
| ^^^ expected associated type, found `u32`
|
note: type in trait
--> src/main.rs:10:15
|
10 | fn bar(a: <A<T> as Foo>::B) {}
| ^^^^^^^^^^^^^^^^
= note: expected signature `fn(<A<T> as Foo>::B)`
found signature `fn(u32)`
help: change the parameter type to match the trait
|
17 - fn bar(a: u32) {}
17 + fn bar(a: <A<T> as Foo>::B) {}
The error disappears when I remove the where clause in Bar implementation.
I expected both code to compile since the where clause should only add trait bounds, and A<T>::B is u32 in both cases.
rustc --version --verbose:
rustc 1.89.0-nightly (ce7e97f73 2025-05-11)
binary: rustc
commit-hash: ce7e97f7371af47e0786f74aa169f6ac9473ff4e
commit-date: 2025-05-11
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.4
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 with the reproducer in src/main.rs and compare compilation with and without the where clause. Trace the compiler's trait and associated-type checking for the impl, then add a regression test showing that the bounded implementation accepts the concrete u32 parameter while preserving the reported incompatible-signature case.
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