Skip to content

Fix unused variable warnings for diverging expressions#158846

Open
chenyukang wants to merge 2 commits into
rust-lang:mainfrom
chenyukang:yukang-fix-158783-unused-never-binding
Open

Fix unused variable warnings for diverging expressions#158846
chenyukang wants to merge 2 commits into
rust-lang:mainfrom
chenyukang:yukang-fix-158783-unused-never-binding

Conversation

@chenyukang

@chenyukang chenyukang commented Jul 6, 2026

Copy link
Copy Markdown
Member

Fixes #158783

@rustbot

rustbot commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 6, 2026
@rustbot

rustbot commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

r? @TaKO8Ki

rustbot has assigned @TaKO8Ki.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 75 candidates
  • Random selection from 20 candidates

@rust-log-analyzer

This comment has been minimized.

@chenyukang chenyukang force-pushed the yukang-fix-158783-unused-never-binding branch from d838658 to 4216015 Compare July 6, 2026 13:05
Comment on lines -2591 to 2596
/// #[expect(unused_variables)]
/// fn example() -> i32 {
/// let x = {
/// return 5;
/// };
/// }

@tiif tiif Jul 9, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the case of

 fn example() -> i32 {
     let x = {
         return 5;
     };
 }

x is actually unused so i think perhaps we should still emit error for it? 🤔

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree it's better to keep it.
but I haven't came out with a perfect fix for it, the following commit 8a2d4db is an attempt which seems ugly but workable way.

is_local_used_in_source should be enough for fixing the original issue, but I think we should still keep:

self.body.local_kind(local) == LocalKind::Temp
&& matches!(binding.opt_match_place, Some((None, _)))

for a cheap checking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

match on a ! variable reports unused variable warning

5 participants