From 2fe968774abcaa806fc7227f70bd2416d2a4a71f Mon Sep 17 00:00:00 2001 From: Laura Peskin Date: Mon, 25 Sep 2017 01:44:47 -0400 Subject: [PATCH] replace defids with nodeids for local variables --- Cargo.lock | 6 +++--- clippy_lints/src/loops.rs | 27 +++++++++++---------------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 88f1a8a7f3a..21f2b4332c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ [root] name = "clippy_lints" -version = "0.0.162" +version = "0.0.163" dependencies = [ "itertools 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -73,11 +73,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "clippy" -version = "0.0.162" +version = "0.0.163" dependencies = [ "cargo_metadata 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "clippy-mini-macro-test 0.1.0", - "clippy_lints 0.0.162", + "clippy_lints 0.0.163", "compiletest_rs 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "duct 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index f8c3e7b4cbd..518b6e21347 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -1374,20 +1374,15 @@ fn check_for_mutability(cx: &LateContext, bound: &Expr) -> Option { let QPath::Resolved(None, _) = *qpath, ], { let def = cx.tables.qpath_def(qpath, bound.hir_id); - match def { - Def::Local(..) | Def::Upvar(..) => { - let def_id = def.def_id(); - let node_id = cx.tcx.hir.as_local_node_id(def_id).expect("local/upvar are local nodes"); - let node_str = cx.tcx.hir.get(node_id); - if_let_chain! {[ - let map::Node::NodeBinding(pat) = node_str, - let PatKind::Binding(bind_ann, _, _, _) = pat.node, - let BindingAnnotation::Mutable = bind_ann, - ], { - return Some(node_id); - }} - } - _ => () + if let Def::Local(node_id) = def { + let node_str = cx.tcx.hir.get(node_id); + if_let_chain! {[ + let map::Node::NodeBinding(pat) = node_str, + let PatKind::Binding(bind_ann, _, _, _) = pat.node, + let BindingAnnotation::Mutable = bind_ann, + ], { + return Some(node_id); + }} } }} return None; @@ -1395,8 +1390,8 @@ fn check_for_mutability(cx: &LateContext, bound: &Expr) -> Option { fn check_for_mutation(cx: &LateContext, body: &Expr, bound_ids: Vec>) -> (Option, Option) { let mut delegate = MutateDelegate { node_id_low: bound_ids[0], node_id_high: bound_ids[1], span_low: None, span_high: None }; - let def_id = def_id::DefId::local(body.hir_id.owner); - let region_scope_tree = &cx.tcx.region_scope_tree(def_id); + let d = def_id::DefId::local(body.hir_id.owner); + let region_scope_tree = &cx.tcx.region_scope_tree(d); ExprUseVisitor::new(&mut delegate, cx.tcx, cx.param_env, region_scope_tree, cx.tables).walk_expr(body); return delegate.mutation_span(); } -- 2.44.0