Skip to content

Unify E0117 foreign-trait label for ADT/primitive types with existing Slice/Array/Tuple handling - #160767

Open
Omar1H1 wants to merge 1 commit into
rust-lang:mainfrom
Omar1H1:diagnostics/e0117-label-fix
Open

Unify E0117 foreign-trait label for ADT/primitive types with existing Slice/Array/Tuple handling#160767
Omar1H1 wants to merge 1 commit into
rust-lang:mainfrom
Omar1H1:diagnostics/e0117-label-fix

Conversation

@Omar1H1

@Omar1H1 Omar1H1 commented Aug 8, 2026

Copy link
Copy Markdown

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

impl PartialEq for u32 {
    fn eq(&self, _other: &Self) -> bool { todo!() }
}

Before :

   |      |             `u32` is not defined in the current crate
   |      `u32` is not defined in the current crate

After :

   |      |       `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

  • [] I did not use an LLM to create a change in this PR.
  • I used an LLM to create a change in this PR, and I have explained below how it was used.

… 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
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 8, 2026
@rustbot

rustbot commented Aug 8, 2026

Copy link
Copy Markdown
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 (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue
Why was this reviewer chosen?

The reviewer was selected based on:

  • compiler expanded to 75 candidates
  • Random selection from 19 candidates

@rustbot

rustbot commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

⚠️ Warning ⚠️

  • There are issue links (such as #123) in the commit messages of the following commits.
    Please move them to the PR description, to avoid spamming the issues with references to the commit, and so this bot can automatically canonicalize them to avoid issues with subtree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants