Skip to content

Do not warn about shadowing in a destructuring assigment #14381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2025

Conversation

samueltardieu
Copy link
Contributor

@samueltardieu samueltardieu commented Mar 9, 2025

When lowering a destructuring assignment from AST to HIR, the compiler will reuse the same identifier name (namely sym::lhs) for all the fields. The desugaring must be checked for to avoid a false positive of the shadow_unrelated lint.

Fix #10279
Fix #14377

changelog: [shadow_unrelated]: prevent false positive in destructuring assignments

@rustbot
Copy link
Collaborator

rustbot commented Mar 9, 2025

r? @y21

rustbot has assigned @y21.
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

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Mar 9, 2025
@profetia
Copy link
Contributor

profetia commented Mar 10, 2025

Related: #10279.

@samueltardieu
Copy link
Contributor Author

Related: #10279.

Yes, this will be fixed as well.

@y21
Copy link
Member

y21 commented Mar 27, 2025

Out of curiosity, does this fix also work for struct literal destructuring? (I'd also be fine with merging this as is even if not, as this already fixes a bunch of FPs)

struct S { a: i32, b: i32 }

let a; let b;
S { a, b } = S { a: 1, b: 2 };

@samueltardieu
Copy link
Contributor Author

Out of curiosity, does this fix also work for struct literal destructuring? (I'd also be fine with merging this as is even if not, as this already fixes a bunch of FPs)

It didn't, because I only checked for Pat nodes and not PatField ones. I have pushed a new version which takes care of this. Good catch, thanks!

Copy link
Member

@y21 y21 left a comment

Choose a reason for hiding this comment

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

Nice, lgtm! r=me after fixing CI

When lowering a destructuring assignment from AST to HIR, the compiler
will reuse the same identifier name (namely `sym::lhs`) for all the
fields. The desugaring must be checked for to avoid a false positive 
of the `shadow_unrelated` lint.
@samueltardieu samueltardieu added this pull request to the merge queue Mar 27, 2025
Merged via the queue into rust-lang:master with commit a895265 Mar 27, 2025
11 checks passed
@samueltardieu samueltardieu deleted the push-vzyluwmvvtys branch March 28, 2025 11:18
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

shadow_unrelated raised when assigning couples shadow_unrelated incorrectly flags a destructuring assignment
4 participants