wrong suggestion when deriving clone for struct containing `dyn Fn`

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

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

まだ誰も着手していません。

評価

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

調査の方向性

まず、Fn trait オブジェクトに関する E0277 の提案を扱う derive-macro の診断コードとテストを読みます。issue には最小限の再現例と誤った提案が記載されています。ここに示された struct フィールドの回帰テストを追加し、該当する診断テストを実行します。このケースで提案が表示されず、診断が引き続き Clone の実装がないことを報告すれば完了です。

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

説明

A-diagnostics A-dyn-trait A-macros A-suggestion-diagnostics D-invalid-suggestion T-compiler
Code
#[derive(Clone)]
struct S {
    f: Box<dyn Fn()>,
}
Current output
error[E0277]: the trait bound `dyn Fn(): Clone` is not satisfied
 --> src/lib.rs:3:5
  |
1 | #[derive(Clone)]
  |          ----- in this derive macro expansion
2 | struct S {
3 |     f: Box<dyn Fn()>,
  |     ^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `dyn Fn()`
  |
  = note: required for `Box<dyn Fn()>` to implement `Clone`
help: use parentheses to call this trait object
  |
3 |     f: Box<dyn Fn()>(),
  |                     ++
Desired output
error[E0277]: the trait bound `dyn Fn(): Clone` is not satisfied
 --> src/lib.rs:3:5
  |
1 | #[derive(Clone)]
  |          ----- in this derive macro expansion
2 | struct S {
3 |     f: Box<dyn Fn()>,
  |     ^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `dyn Fn()`
  |
  = note: required for `Box<dyn Fn()>` to implement `Clone`
Rationale and extra context

Applying the suggestion results in a syntax error:

error: expected `,`, or `}`, found `(`
 --> src/lib.rs:3:21
  |
2 | struct S {
  |        - while parsing this struct
3 |     f: Box<dyn Fn()>(),
  |                     ^
Other cases

Rust Version
rustc 1.100.0 (0ef1bc386 2026-11-09)
binary: rustc
commit-hash: 0ef1bc386059596dada8fb65b50425aab2ea637a
commit-date: 2026-11-09
host: x86_64-unknown-linux-gnu
release: 1.100.0
LLVM version: 23.1.5
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 を短くまとめたダイジェスト。