rust-lang / rust-lang/rust

Conflicting implementations with unresolved associated types

Open
#146,202 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
trait A {
    type B: A<B = Self::B>;
}
struct C;
trait X<T> { }
impl<T: A<B = T>> X<T> for C { }

struct D<T>(T);
impl<T: A<B = T>> A for D<T> {
    //type B = T; // tastcase 1: this is fine
    type B = T::B; // testcase 2: this causes an error even though it's the same!
}
impl<T: A<B = T>> X<D<T>> for C { }
Current output
error[E0119]: conflicting implementations of trait `X<D<_>>` for type `C`
  --> src/main.rs:13:1
   |
 6 | impl<T: A<B = T>> X<T> for C { }
   | ---------------------------- first implementation here
...
13 | impl<T: A<B = T>> X<D<T>> for C { }
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `C`

For more information about this error, try `rustc --explain E0119`.
Desired output
warn[E....]: using an indirect reference to a fixed associated type
  --> src/main.rs:11:13
   |
   |     type B = T::B; // testcase 2: this causes an error even though it's the same!
   |              ^^^^
note: the associated type is fixed here
 --> src/main.rs:9:10
  |
9 | impl<T: A<B = T>> A for D<T> {
  |           ^^^^^
note: consider using the value of the associated type directly
 --> src/main.rs:11:13
   |
11 |     type B = T; // testcase 2: this causes an error even though it's the same!
   |              +
error[E0119]: conflicting implementations of trait `X<D<_>>` for type `C`
  --> src/main.rs:13:1
   |
 6 | impl<T: A<B = T>> X<T> for C { }
   | ---------------------------- first implementation here
...
13 | impl<T: A<B = T>> X<D<T>> for C { }
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `C`

For more information about this error, try `rustc --explain E0119`.
Rationale and extra context

I expected both testcases 1, 2 to work fine, as it's trivial for the rustcompiler to look up what T::B is in this case, however instead it required me to explicitly specify T. This would not have been a problem, if the compiler would have told me, that that is the problem. Instead the compiler tells me that there is conflicting implementations. I would therefore expect to either have both cases working (which doesn't add any real functionallity afaict) or have a compiler warning, which tells me that I specified a type which is known, but can not be automatically resolved (which would probably make my code cleaner in this case).

Other cases

Rust Version
rustc 1.91.0-nightly (a1208bf76 2025-09-03)
binary: rustc
commit-hash: a1208bf765ba783ee4ebdc4c29ab0a0c215806ef
commit-date: 2025-09-03
host: x86_64-unknown-linux-gnu
release: 1.91.0-nightly
LLVM version: 21.1.0
Anything else?

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example in src/main.rs with the reported rustc 1.91.0-nightly version, comparing the two associated-type implementations and the resulting E0119 diagnostic. Trace the compiler's handling of the fixed associated type; done when the valid case is accepted or the diagnostic clearly explains the unresolved indirect reference.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.