From 9012d8f1975829a1440fde6f6fd6158a239595c4 Mon Sep 17 00:00:00 2001 From: llogiq Date: Tue, 25 Aug 2015 20:11:03 +0200 Subject: [PATCH] fixed false positives on structs/enum variants --- src/shadow.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/shadow.rs b/src/shadow.rs index c4f636ae112..2c16d9d78f4 100644 --- a/src/shadow.rs +++ b/src/shadow.rs @@ -65,13 +65,20 @@ fn check_decl(cx: &Context, decl: &Decl, bindings: &mut Vec) { } } +fn is_binding(cx: &Context, pat: &Pat) -> bool { + match cx.tcx.def_map.borrow().get(&pat.id).map(|d| d.full_def()) { + Some(DefVariant(..)) | Some(DefStruct(..)) => false, + _ => true + } +} + fn check_pat(cx: &Context, pat: &Pat, init: &Option, span: Span, bindings: &mut Vec) where T: Deref { //TODO: match more stuff / destructuring match pat.node { PatIdent(_, ref ident, ref inner) => { let name = ident.node.name; - if pat_is_binding(&cx.tcx.def_map, pat) { + if is_binding(cx, pat) { if bindings.contains(&name) { lint_shadow(cx, name, span, pat.span, init); }