Unify E0117 foreign-trait label for ADT/primitive types with existing Slice/Array/Tuple handling - #160767
Merged
rust-bors[bot] merged 1 commit intoAug 19, 2026
Conversation
… orphan check
`emit_orphan_check_error` already special-cases non-local types that
appear in a foreign trait's own parameter position (as opposed to
Self): for Slice, Array, and Tuple, the label reads "this is
not defined in the current crate because this is a foreign trait"
instead of naming the type. The Adt arm and the primitive/catch-all
arm never checked this and always named the type instead, even in the
same non-Self position.
This produced a confusing diagnostic for impls like
impl PartialEq for u32 {}
where Rhs defaults to Self (u32), so both the Self label and
the Rhs label read `u32` is not defined in the current crate,
with the second one visually landing under PartialEq since the
defaulted Rhs has no span of its own.
Extend the existing is_foreign check to the Adt and catch-all arms
so all four cases behave consistently.
Addresses rust-lang#160648
Collaborator
|
Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @petrochenkov (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
Why was this reviewer chosen?The reviewer was selected based on:
|
Collaborator
|
Contributor
|
@bors r+ |
Contributor
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Aug 18, 2026
…x, r=petrochenkov
Unify E0117 foreign-trait label for ADT/primitive types with existing Slice/Array/Tuple handling
### What this does
`emit_orphan_check_error` (in `compiler/rustc_hir_analysis/src/coherence/orphan.rs`) already has an `is_foreign` flag, true whenever a non-local type sits in one of the *trait's own* parameter positions rather than `Self`. The `Slice`, `Array`, and `Tuple` arms already use it to switch their label to a generic "this is not defined in the current crate because this is a foreign trait" message instead of naming the type. The `Adt` arm and the catch-all `_` arm (covering primitives) never checked `is_foreign` and always named the type, even in the same non-Self position.
This PR extends the same `is_foreign` branch to those two arms, so all four are consistent. No new types or subdiagnostics reuses the existing `OnlyCurrentTraitsForeign` struct already used a few lines above.
LLM use :
I used LLM to explore the project and find where code that tags labels
### Before / after
```rust
impl PartialEq for u32 {
fn eq(&self, _other: &Self) -> bool { todo!() }
}
```
Before :
```Plaintext
| | `u32` is not defined in the current crate
| `u32` is not defined in the current crate
```
After :
```Plaintext
| | `u32` is not defined in the current crate
| this is not defined in the current crate because this is a foreign trait
```
Addresses rust-lang#160648
r? compiler
rust-bors Bot
pushed a commit
that referenced
this pull request
Aug 18, 2026
…uwer Rollup of 8 pull requests Successful merges: - #154210 (fix: fix the capture behavior of `if let` in closures) - #156176 (Initial implementation of `FnPtr` trait) - #160767 (Unify E0117 foreign-trait label for ADT/primitive types with existing Slice/Array/Tuple handling) - #160489 (Adding diagnostic item markers for multiple fs functions and structs) - #161220 (bootstrap: Allow `./x fix --allow-dirty`) - #161291 (Rename `ProjectionPredicate` and `TraitPredicate`) - #161296 (Enable overflow checks in `rustc_thread_pool`) - #161304 (Rename test so it matches the issue)
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Aug 18, 2026
…x, r=petrochenkov
Unify E0117 foreign-trait label for ADT/primitive types with existing Slice/Array/Tuple handling
### What this does
`emit_orphan_check_error` (in `compiler/rustc_hir_analysis/src/coherence/orphan.rs`) already has an `is_foreign` flag, true whenever a non-local type sits in one of the *trait's own* parameter positions rather than `Self`. The `Slice`, `Array`, and `Tuple` arms already use it to switch their label to a generic "this is not defined in the current crate because this is a foreign trait" message instead of naming the type. The `Adt` arm and the catch-all `_` arm (covering primitives) never checked `is_foreign` and always named the type, even in the same non-Self position.
This PR extends the same `is_foreign` branch to those two arms, so all four are consistent. No new types or subdiagnostics reuses the existing `OnlyCurrentTraitsForeign` struct already used a few lines above.
LLM use :
I used LLM to explore the project and find where code that tags labels
### Before / after
```rust
impl PartialEq for u32 {
fn eq(&self, _other: &Self) -> bool { todo!() }
}
```
Before :
```Plaintext
| | `u32` is not defined in the current crate
| `u32` is not defined in the current crate
```
After :
```Plaintext
| | `u32` is not defined in the current crate
| this is not defined in the current crate because this is a foreign trait
```
Addresses rust-lang#160648
r? compiler
jhpratt
added a commit
to jhpratt/rust
that referenced
this pull request
Aug 19, 2026
…x, r=petrochenkov
Unify E0117 foreign-trait label for ADT/primitive types with existing Slice/Array/Tuple handling
### What this does
`emit_orphan_check_error` (in `compiler/rustc_hir_analysis/src/coherence/orphan.rs`) already has an `is_foreign` flag, true whenever a non-local type sits in one of the *trait's own* parameter positions rather than `Self`. The `Slice`, `Array`, and `Tuple` arms already use it to switch their label to a generic "this is not defined in the current crate because this is a foreign trait" message instead of naming the type. The `Adt` arm and the catch-all `_` arm (covering primitives) never checked `is_foreign` and always named the type, even in the same non-Self position.
This PR extends the same `is_foreign` branch to those two arms, so all four are consistent. No new types or subdiagnostics reuses the existing `OnlyCurrentTraitsForeign` struct already used a few lines above.
LLM use :
I used LLM to explore the project and find where code that tags labels
### Before / after
```rust
impl PartialEq for u32 {
fn eq(&self, _other: &Self) -> bool { todo!() }
}
```
Before :
```Plaintext
| | `u32` is not defined in the current crate
| `u32` is not defined in the current crate
```
After :
```Plaintext
| | `u32` is not defined in the current crate
| this is not defined in the current crate because this is a foreign trait
```
Addresses rust-lang#160648
r? compiler
This was referenced Aug 19, 2026
rust-bors Bot
pushed a commit
that referenced
this pull request
Aug 19, 2026
Rollup of 18 pull requests Successful merges: - #154210 (fix: fix the capture behavior of `if let` in closures) - #156176 (Initial implementation of `FnPtr` trait) - #160767 (Unify E0117 foreign-trait label for ADT/primitive types with existing Slice/Array/Tuple handling) - #161297 (std: use UNIX's `Instant` and `SystemTime` on Hermit) - #160489 (Adding diagnostic item markers for multiple fs functions and structs) - #160643 (Require windowed (and exception) for Xtensa ABI) - #161088 (suppress projection errors already covered by a trait error) - #161114 (Remove fields from TypeKind: Struct, Enum, Union and Tuple) - #161115 (Assorted allocator nitpicks) - #161220 (bootstrap: Allow `./x fix --allow-dirty`) - #161296 (Enable overflow checks in `rustc_thread_pool`) - #161298 (remove rustc_error_messages dependency) - #161304 (Rename test so it matches the issue) - #161309 (`allow(non_camel_case_types)` in `minicore.rs`) - #161315 (Relax codgen test variable regex) - #161318 (Doc: clarify how `Read::bytes` handling Interrupted errors) - #161321 (Update books) - #161335 ([compiletest] Use the correct rustc lib directory for query_rustc_output)
rust-bors Bot
pushed a commit
that referenced
this pull request
Aug 19, 2026
Rollup merge of #160767 - Omar1H1:diagnostics/e0117-label-fix, r=petrochenkov Unify E0117 foreign-trait label for ADT/primitive types with existing Slice/Array/Tuple handling ### What this does `emit_orphan_check_error` (in `compiler/rustc_hir_analysis/src/coherence/orphan.rs`) already has an `is_foreign` flag, true whenever a non-local type sits in one of the *trait's own* parameter positions rather than `Self`. The `Slice`, `Array`, and `Tuple` arms already use it to switch their label to a generic "this is not defined in the current crate because this is a foreign trait" message instead of naming the type. The `Adt` arm and the catch-all `_` arm (covering primitives) never checked `is_foreign` and always named the type, even in the same non-Self position. This PR extends the same `is_foreign` branch to those two arms, so all four are consistent. No new types or subdiagnostics reuses the existing `OnlyCurrentTraitsForeign` struct already used a few lines above. LLM use : I used LLM to explore the project and find where code that tags labels ### Before / after ```rust impl PartialEq for u32 { fn eq(&self, _other: &Self) -> bool { todo!() } } ``` Before : ```Plaintext | | `u32` is not defined in the current crate | `u32` is not defined in the current crate ``` After : ```Plaintext | | `u32` is not defined in the current crate | this is not defined in the current crate because this is a foreign trait ``` Addresses #160648 r? compiler
RalfJung
pushed a commit
to RalfJung/miri
that referenced
this pull request
Aug 19, 2026
Rollup of 18 pull requests Successful merges: - rust-lang/rust#154210 (fix: fix the capture behavior of `if let` in closures) - rust-lang/rust#156176 (Initial implementation of `FnPtr` trait) - rust-lang/rust#160767 (Unify E0117 foreign-trait label for ADT/primitive types with existing Slice/Array/Tuple handling) - rust-lang/rust#161297 (std: use UNIX's `Instant` and `SystemTime` on Hermit) - rust-lang/rust#160489 (Adding diagnostic item markers for multiple fs functions and structs) - rust-lang/rust#160643 (Require windowed (and exception) for Xtensa ABI) - rust-lang/rust#161088 (suppress projection errors already covered by a trait error) - rust-lang/rust#161114 (Remove fields from TypeKind: Struct, Enum, Union and Tuple) - rust-lang/rust#161115 (Assorted allocator nitpicks) - rust-lang/rust#161220 (bootstrap: Allow `./x fix --allow-dirty`) - rust-lang/rust#161296 (Enable overflow checks in `rustc_thread_pool`) - rust-lang/rust#161298 (remove rustc_error_messages dependency) - rust-lang/rust#161304 (Rename test so it matches the issue) - rust-lang/rust#161309 (`allow(non_camel_case_types)` in `minicore.rs`) - rust-lang/rust#161315 (Relax codgen test variable regex) - rust-lang/rust#161318 (Doc: clarify how `Read::bytes` handling Interrupted errors) - rust-lang/rust#161321 (Update books) - rust-lang/rust#161335 ([compiletest] Use the correct rustc lib directory for query_rustc_output)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
emit_orphan_check_error(incompiler/rustc_hir_analysis/src/coherence/orphan.rs) already has anis_foreignflag, true whenever a non-local type sits in one of the trait's own parameter positions rather thanSelf. TheSlice,Array, andTuplearms already use it to switch their label to a generic "this is not defined in the current crate because this is a foreign trait" message instead of naming the type. TheAdtarm and the catch-all_arm (covering primitives) never checkedis_foreignand always named the type, even in the same non-Self position.This PR extends the same
is_foreignbranch to those two arms, so all four are consistent. No new types or subdiagnostics reuses the existingOnlyCurrentTraitsForeignstruct already used a few lines above.LLM use :
I used LLM to explore the project and find where code that tags labels
Before / after
Before :
After :
Addresses #160648
r? compiler