Skip to content

Fix unused_variables typo suggestions for const patterns#156904

Open
onehr wants to merge 1 commit into
rust-lang:mainfrom
onehr:fix-unused-pattern-typo-147595
Open

Fix unused_variables typo suggestions for const patterns#156904
onehr wants to merge 1 commit into
rust-lang:mainfrom
onehr:fix-unused-pattern-typo-147595

Conversation

@onehr
Copy link
Copy Markdown
Contributor

@onehr onehr commented May 25, 2026

Closes #147595

This fixes unused_variables typo suggestions that could print replacement
patterns which are not valid from the binding site.

The fix keeps the existing def_path_str output when it is already valid, but
adjusts two local-item cases:

  • items outside the binding module are printed with crate::...;
  • items nested inside the current body are printed relative to that body.

It also suppresses const typo suggestions for bare let x = ... bindings,
because replacing the binding with a const path creates a refutable pattern.
Unit ADT typo suggestions are left unchanged.

The regression test covers 2015 and 2021 editions, cross-module consts,
same-module consts, function-local consts, cross-module variants, and bare
let const initializers.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 25, 2026
@onehr onehr marked this pull request as ready for review May 25, 2026 09:59
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 25, 2026

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. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 25, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 25, 2026

r? @mejrs

rustbot has assigned @mejrs.
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 73 candidates
  • Random selection from 18 candidates

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.

Lint unused_variables's "typoed pattern" suggestion still suggests invalid and unrelated paths

3 participants