Skip to content

Adding where clause already filled relax traits bounds in impl #141721

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

Open
supersurviveur opened this issue May 29, 2025 · 0 comments
Open

Adding where clause already filled relax traits bounds in impl #141721

supersurviveur opened this issue May 29, 2025 · 0 comments
Labels
C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged.

Comments

@supersurviveur
Copy link

supersurviveur commented May 29, 2025

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
@supersurviveur supersurviveur added the C-bug Category: This is a bug. label May 29, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged.
Projects
None yet
Development

No branches or pull requests

2 participants