Skip to content

Detect shadowing in pattern field #13797

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
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clippy_lints/src/shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ fn is_self_shadow(cx: &LateContext<'_>, pat: &Pat<'_>, mut expr: &Expr<'_>, hir_
fn find_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<(&'tcx Expr<'tcx>, Option<HirId>)> {
for (hir_id, node) in cx.tcx.hir().parent_iter(hir_id) {
let init = match node {
Node::Arm(_) | Node::Pat(_) | Node::Param(_) => continue,
Node::Arm(_) | Node::Pat(_) | Node::PatField(_) | Node::Param(_) => continue,
Node::Expr(expr) => match expr.kind {
ExprKind::Match(e, _, _) | ExprKind::Let(&LetExpr { init: e, .. }) => Some((e, None)),
// If we're a closure argument, then a parent call is also an associated item.
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,12 @@ fn shadow_closure() {
.collect();
}

struct Issue13795 {
value: i32,
}

fn issue13795(value: Issue13795) {
let Issue13795 { value, .. } = value;
}

fn main() {}
14 changes: 13 additions & 1 deletion tests/ui/shadow.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -304,5 +304,17 @@ note: previous binding is here
LL | .map(|i| i.map(|i| i - 10))
| ^

error: aborting due to 25 previous errors
error: `value` is shadowed by itself in `value`
--> tests/ui/shadow.rs:141:22
|
LL | let Issue13795 { value, .. } = value;
| ^^^^^
|
note: previous binding is here
--> tests/ui/shadow.rs:140:15
|
LL | fn issue13795(value: Issue13795) {
| ^^^^^

error: aborting due to 26 previous errors

Loading