Const-generic trait coherence / normalization issue?
⚓ Rust 📅 2025-08-15 👤 surdeus 👁️ 12I'm having an issue I can't wrap my head around.
I have a struct B for which I implement AsRef<String>. I now want to implement another AsRef<T>, with T being the associated type of a const-generic trait, implemented for some other A.
See the condensed example below. You can assume the modules a and c are identical (well, a is a crate, and b a local module, but otherwise they are "the same"), and ::T isn't a String.
// b/src/lib.rs
impl AsRef<String> for B { ... }
// Enable one of the lines below; a::A fails, c::A works.
impl AsRef<<a::A as Numbered<0>>::T> for B { ... }
impl AsRef<<c::A as Numbered<0>>::T> for B { ... }
The issue is, if the 'same struct and trait impl' resides in the current crate this works, if it resides in another crate, this fails with:
error[E0119]: conflicting implementations of trait `AsRef<String>` for type `B`
--> b\src\lib.rs:19:1
|
15 | impl AsRef<String> for B { fn as_ref(&self) -> &String { unimplemented!() }}
| ------------------------ first implementation here
...
19 | impl AsRef<<a::A as Numbered<0>>::T> for B { fn as_ref( & self ) -> &<a::A as Numbered<0>>::T { unimplemented!() }}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `B`
This feels like a compiler bug, or am I missing something?
[Edit, just realized the <0> const generic has nothing to do with that, even without it this has issues]
[Edit 2, this might actually be #51445]
1 post - 1 participant
🏷️ Rust_feed