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

Abierto Apto para principiantes
#166,834 3 comentarios 0 reacciones 1 asignado Ver en GitHub

Los mantenedores suelen responder en 1 día

@shamnad-sherief ya está trabajando en esto.

Desde el 2/12/2026.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
70/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust
Área
compilers

Línea de trabajo

Busca en los diagnósticos de rustc la redacción de E0117 que aparece en el issue y lee el código que selecciona el diagnóstico para traits no genéricos. Compara su redacción con el diagnóstico de la regla de orphan genérica y con el ejemplo del issue. Se considera terminado cuando el mensaje para traits no genéricos ya no afirma algo incorrecto, mientras sigue explicando la restricción y remitiendo a las reglas de orphan.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
Rust
Estrellas
123k
Forks
16.6k
Merge medio
2 d 17 h
PR fusionados (30 d)
515

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de rust-lang/rust

Todos los issues de rust-lang/rust

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.