Code
impl PartialEq for u32 {
fn eq(&self, _other: &Self) -> bool {
todo!()
}
}
Current output
error[E0117]: only traits defined in the current crate can be implemented for primitive types
--> src/lib.rs:1:1
|
1 | impl PartialEq for u32 {
| ^^^^^---------^^^^^---
| | |
| | `u32` is not defined in the current crate
| `u32` is not defined in the current crate
|
= note: impl doesn't have any local type before any uncovered type parameters
= note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
= note: define and implement a trait or new type instead
For more information about this error, try `rustc --explain E0117`.
Desired output
| impl PartialEq for u32 {
| ^^^^^---------^^^^^---
| | |
| | `u32` is not defined in the current crate
| this is not defined in the current crate because this is a foreign trait
Rationale and extra context
Original diagnosis in this issue was incorrect. see the comment below for the corrected root cause. Leaving the original text below for context.
In compiler/rustc_hir_analysis/src/coherence/orphan.rs, emit_orphan_check_error iterates through non-local input types. When processing the trait (is_target_ty == IsFirstInputType::No), it passes the target type's subdiagnostic message template (OnlyCurrentTraitsTy), causing the type name (u32) to be formatted for both the type and trait span labels.
Other cases
Rust Version
❯ rustc --version --verbose
rustc 1.97.1 (8bab26f4f 2026-07-14)
binary: rustc
commit-hash: 8bab26f4f68e0e26f0bb7960be334d5b520ea452
commit-date: 2026-07-14
host: x86_64-unknown-linux-gnu
release: 1.97.1
LLVM version: 22.1.6
Anything else?
I would like to work on a PR to fix this issue !
Code
Current output
Desired output
Rationale and extra context
Original diagnosis in this issue was incorrect. see the comment below for the corrected root cause. Leaving the original text below for context.
In
compiler/rustc_hir_analysis/src/coherence/orphan.rs,emit_orphan_check_erroriterates through non-local input types. When processing the trait (is_target_ty == IsFirstInputType::No), it passes the target type's subdiagnostic message template (OnlyCurrentTraitsTy), causing the type name (u32) to be formatted for both the type and trait span labels.Other cases
Rust Version
Anything else?
I would like to work on a PR to fix this issue !