Fix unused_variables typo suggestions for const patterns#156904
Conversation
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
|
r? @mejrs rustbot has assigned @mejrs. Use Why was this reviewer chosen?The reviewer was selected based on:
|
There was a problem hiding this comment.
Thanks!
- Please add a regression test for not suggesting
path::_, like reported in the issue. - Please add explicit
HELPannotations in the new tests.
It looks good otherwise but I'm not familiar enough here to tell whether or not corner cases are being missed, so
|
Reminder, once the PR becomes ready for a review, use |
b6a1b9e to
518355f
Compare
|
Thanks @mejrs for your comments, resolved. |
|
@rustbot ready |
2de8a14 to
537deff
Compare
537deff to
189de55
Compare
This comment has been minimized.
This comment has been minimized.
When `unused_variables` finds a similarly named const or enum variant, it suggests replacing the unused binding with a pattern matching that item. The item was printed with a trimmed path, which is not necessarily resolvable from the binding site, so the `MachineApplicable` suggestion could fail to compile. Print the item with `with_crate_prefix!`: a `crate::`-rooted, re-export-aware path that resolves from any binding site in the crate. A const declared inside the current body has no such path, so it is printed by its bare in-scope name. Also suppress const typo suggestions for bare `let x = ...` bindings, where a const pattern would be refutable.
189de55 to
5632423
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
☔ The latest upstream changes (presumably #157894) made this pull request unmergeable. Please resolve the merge conflicts. |
Closes #147595
This fixes
unused_variablestypo suggestions that could print replacementpatterns which are not valid from the binding site.
The fix keeps the existing
def_path_stroutput when it is already valid, butadjusts two local-item cases:
crate::...;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
letconst initializers.