Misleading warning when a variable is "unused" (used only in unreachable code)

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

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

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
rust
領域
compilers

調査の方向性

Start with the supplied Rust playground example and compare its diagnostics on Rust 1.100.0 with the earlier behavior referenced in issues #99076 and #115394. The report identifies no compiler files or tests, so first trace how unreachable code and unused-variable warnings are emitted for this example. Done means the final join is reported as unreachable, with the unused-variable warning handled consistently.

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

説明

A-diagnostics A-lints A-never-type D-confusing L-false-negative L-unreachable_code L-unused_variables S-has-mcve T-compiler
Code

https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=b73b5e4465ed2e20db9a89d75f267fca

  let infinite_thread = thread::spawn(|| loop {});
  let finite_thread = thread::spawn(|| {});
  
  infinite_thread.join().unwrap();
  finite_thread.join().unwrap();
Current output
> warning: unused variable: `finite_thread`

But more importantly, there is not a warning that the last line is unreachable code. I found a few similar issues (#99076, #115394) but in those it sounds like the compiler emitted both warnings, for the unused variable and the unreachable code. In this case I am seeing the unused variable warning only.

Desired output
> warning: unreachable code

either in addition to or instead of the unused variable warning.

Rationale and extra context

I got this warning when upgrading from 1.99 to 1.100 and was confused at first because it seemed quite clear that finite_thread was used.

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

環境構築

はじめの一歩

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

rust-lang/rust のほかの issue

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

似ている issue

Rust の issue をもっと見る

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

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