Statement about impls in non-generic orphan rule diagnostic is incorrect and badly worded

Aperta Adatta ai principianti
#166,834 3 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@shamnad-sherief ci sta già lavorando.

Dal 2/12/2026.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
70/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
compilers

Direzione di ricerca

Cerca nei diagnostic di rustc la formulazione di E0117 mostrata nell’issue e leggi il codice che seleziona il diagnostic per i trait non generici. Confronta la formulazione con quella del diagnostic della regola orphan generica e con l’esempio nell’issue. Il lavoro è completato quando il messaggio per i trait non generici non fa più l’affermazione errata, continuando però a spiegare la restrizione e a rimandare alle regole orphan.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

A-coherence A-diagnostics D-incorrect D-non-disjoint-spans D-papercut E-easy T-compiler
Code
struct Local;
impl Clone for &'static [Local] {
    fn clone(&self) -> Self {
        todo!()
    }
}
Current output
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
 --> src/main.rs:2:1
  |
2 | impl Clone for &'static [Local] {
  | ^^^^^^^^^^^^^^^----------------
  |                |
  |                this is not defined in the current crate because slices are always foreign
  |
  = 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

(counterexample: impl From<LocalType> for i32 impls a trait defined in core for a type defined in core, but is legal)

Desired output
error[E0117]: non-generic traits defined outside the current crate can only be implemented for local types
 --> src/main.rs:2:1
  |
2 | impl Clone for &'static [Local] {
  | ^^^^^^^^^^^^^^^----------------
  |                |
  |                this is not defined in the current crate because slices are always foreign
  |
  = 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
Rationale and extra context

Note that this message is special for non-generic traits, but makes a general statement that is incorrect for generic traits. See also #166793, which complains about the generic case not having a special message.

Other cases

The "arbitrary types" wording is odd and not used for other types, e.g.

error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
 --> src/main.rs:1:1
  |
1 | impl Copy for std::ops::Range<i32> {}

the other problem of the statement in the error being incorrect applies here as well.

Rust Version
rustc 1.102.0-nightly (c82ce1563 2026-11-27)
binary: rustc
commit-hash: c82ce15637153c025d29abbaff6035a177361788
commit-date: 2026-11-27
host: x86_64-unknown-linux-gnu
release: 1.102.0-nightly
LLVM version: 23.1.6
Anything else?

No response

Lingua principale
Rust
Stelle
123k
Fork
16.6k
Merge medio
2g 17h
PR unite (30g)
515

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rust-lang/rust

Tutte le issue di rust-lang/rust

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.