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

オープン 初心者向け
#166,834 コメント 3 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@shamnad-sherief がすでに取り組んでいます。

2026年12月2日 から。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
70/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
rust
領域
compilers

調査の方向性

issueに示されているE0117の文言をrustcの診断から探し、ジェネリックでないトレイト向けの診断を選択するコードを読んでください。その文言を、ジェネリックな孤児ルールの診断およびissueの例と比較してください。ジェネリックでないトレイト向けのメッセージが誤った主張をしなくなり、制約の説明と孤児ルールへの参照が引き続き含まれていれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
Rust
スター
123k
フォーク
16.6k
平均マージ
2日 17時間
マージ済み PR(30日)
515

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

rust-lang/rust のほかの issue

rust-lang/rust の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。