Skip to content

Commit c2d23ad

Browse files
authored
Detect shadowing in pattern field (#13797)
Fix #13795 changelog: [`shadow_same`]: detect shadowing as a pattern field
2 parents 59740a8 + f51f72b commit c2d23ad

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

clippy_lints/src/shadow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ fn is_self_shadow(cx: &LateContext<'_>, pat: &Pat<'_>, mut expr: &Expr<'_>, hir_
263263
fn find_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<(&'tcx Expr<'tcx>, Option<HirId>)> {
264264
for (hir_id, node) in cx.tcx.hir().parent_iter(hir_id) {
265265
let init = match node {
266-
Node::Arm(_) | Node::Pat(_) | Node::Param(_) => continue,
266+
Node::Arm(_) | Node::Pat(_) | Node::PatField(_) | Node::Param(_) => continue,
267267
Node::Expr(expr) => match expr.kind {
268268
ExprKind::Match(e, _, _) | ExprKind::Let(&LetExpr { init: e, .. }) => Some((e, None)),
269269
// If we're a closure argument, then a parent call is also an associated item.

tests/ui/shadow.rs

+8
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,12 @@ fn shadow_closure() {
133133
.collect();
134134
}
135135

136+
struct Issue13795 {
137+
value: i32,
138+
}
139+
140+
fn issue13795(value: Issue13795) {
141+
let Issue13795 { value, .. } = value;
142+
}
143+
136144
fn main() {}

tests/ui/shadow.stderr

+13-1
Original file line numberDiff line numberDiff line change
@@ -304,5 +304,17 @@ note: previous binding is here
304304
LL | .map(|i| i.map(|i| i - 10))
305305
| ^
306306

307-
error: aborting due to 25 previous errors
307+
error: `value` is shadowed by itself in `value`
308+
--> tests/ui/shadow.rs:141:22
309+
|
310+
LL | let Issue13795 { value, .. } = value;
311+
| ^^^^^
312+
|
313+
note: previous binding is here
314+
--> tests/ui/shadow.rs:140:15
315+
|
316+
LL | fn issue13795(value: Issue13795) {
317+
| ^^^^^
318+
319+
error: aborting due to 26 previous errors
308320

0 commit comments

Comments
 (0)