incorrect type resolution during conflict checking from extern crate
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
// sub-crate "inner":
pub trait TryFromBits: Sized {
const BITS: u8;
type Inner;
}
pub struct Bits<const N: u8>(<Self as TryFromBits>::Inner)
where
Self: TryFromBits;
impl TryFromBits for Bits<4> {
const BITS: u8 = 4;
type Inner = u8;
}
// main crate
use inner::{Bits, TryFromBits};
pub struct Abcd {}
impl TryFromBits for Abcd {
const BITS: u8 = 4;
type Inner = <Bits<{ <Self as TryFromBits>::BITS }> as TryFromBits>::Inner; // should be `u8`
}
pub trait ConvFrom<Src>: Sized {}
impl<T> ConvFrom<T> for T {}
impl ConvFrom<<Self as TryFromBits>::Inner> for Abcd {}
I expected to see this happen: successful compilation
Instead, this happened: compile error
error[E0119]: conflicting implementations of trait `ConvFrom<Abcd>` for type `Abcd`
--> src/main.rs:11:1
|
10 | impl<T> ConvFrom<T> for T {}
| ------------------------- first implementation here
11 | impl ConvFrom<<Self as TryFromBits>::Inner> for Abcd {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Abcd`
The compiler "thinks" <Abcd as TryFromBits>::Inner is Abcd but the actual type is u8.
Commenting-out the offending line and adding the following code confirms it:
fn main() {
println!("{}", std::any::type_name::<<Abcd as TryFromBits>::Inner>());
}
minimal reproduction repository
Notes:
- this only happens if
Bitsstruct is defined in extern crate - the code compiles fine within single crate - does not seem to be a regression, reproducible back to 1.56 (haven't tested any further)
Meta
rustc --version --verbose:
rustc --version --verbose
rustc 1.98.0-nightly (cb46fbb8c 2026-06-08)
binary: rustc
commit-hash: cb46fbb8c6ea799c6fba9188ed889275c35a8c28
commit-date: 2026-06-08
host: x86_64-unknown-linux-gnu
release: 1.98.0-nightly
LLVM version: 22.1.6
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 by building the minimal reproduction repository linked in the issue and compare the extern-crate case with the single-crate case. The reported example is in src/main.rs; inspect rustc's trait conflict-checking and type-resolution paths to trace why the associated type is treated as Abcd rather than u8. Done means the reproduction compiles successfully while the existing conflict diagnostics remain correct.
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
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100