diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 3571540c6c9..29ee6ae1fed 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -182,7 +182,7 @@ fn get_type_name(cx: &LateContext<'_, '_>, kind: &ty::TyKind<'_>) -> String { fn compare_inputs(closure_inputs: &mut dyn Iterator, call_args: &mut dyn Iterator) -> bool { for (closure_input, function_arg) in closure_inputs.zip(call_args) { - if let PatKind::Binding(_, _, _, ident, _) = closure_input.pat.node { + if let PatKind::Binding(_, _, ident, _) = closure_input.pat.node { // XXXManishearth Should I be checking the binding mode here? if let ExprKind::Path(QPath::Resolved(None, ref p)) = function_arg.node { if p.segments.len() != 1 { diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index ef3debe17a7..5378f7d455f 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -8,7 +8,6 @@ use rustc::ty; use rustc::{declare_tool_lint, lint_array}; use rustc_data_structures::fx::FxHashSet; use rustc_target::spec::abi::Abi; -use syntax::ast; use syntax::source_map::Span; declare_clippy_lint! { @@ -278,8 +277,8 @@ impl<'a, 'tcx> Functions { } } -fn raw_ptr_arg(arg: &hir::Arg, ty: &hir::Ty) -> Option { - if let (&hir::PatKind::Binding(_, id, _, _, _), &hir::TyKind::Ptr(_)) = (&arg.pat.node, &ty.node) { +fn raw_ptr_arg(arg: &hir::Arg, ty: &hir::Ty) -> Option { + if let (&hir::PatKind::Binding(_, id, _, _), &hir::TyKind::Ptr(_)) = (&arg.pat.node, &ty.node) { Some(id) } else { None @@ -288,7 +287,7 @@ fn raw_ptr_arg(arg: &hir::Arg, ty: &hir::Ty) -> Option { struct DerefVisitor<'a, 'tcx: 'a> { cx: &'a LateContext<'a, 'tcx>, - ptrs: FxHashSet, + ptrs: FxHashSet, tables: &'a ty::TypeckTables<'tcx>, } @@ -329,7 +328,7 @@ impl<'a, 'tcx: 'a> DerefVisitor<'a, 'tcx> { fn check_arg(&self, ptr: &hir::Expr) { if let hir::ExprKind::Path(ref qpath) = ptr.node { if let Def::Local(id) = self.cx.tables.qpath_def(qpath, ptr.hir_id) { - if self.ptrs.contains(&id) { + if self.ptrs.contains(&self.cx.tcx.hir().node_to_hir_id(id)) { span_lint( self.cx, NOT_UNSAFE_PTR_ARG_DEREF, diff --git a/clippy_lints/src/let_if_seq.rs b/clippy_lints/src/let_if_seq.rs index e3533ed6d02..5ef3d8dd4ab 100644 --- a/clippy_lints/src/let_if_seq.rs +++ b/clippy_lints/src/let_if_seq.rs @@ -6,7 +6,6 @@ use rustc::hir::BindingAnnotation; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::{declare_tool_lint, lint_array}; use rustc_errors::Applicability; -use syntax::ast; declare_clippy_lint! { /// **What it does:** Checks for variable declarations immediately followed by a @@ -73,7 +72,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq { if_chain! { if let Some(expr) = it.peek(); if let hir::StmtKind::Local(ref local) = stmt.node; - if let hir::PatKind::Binding(mode, canonical_id, _, ident, None) = local.pat.node; + if let hir::PatKind::Binding(mode, canonical_id, ident, None) = local.pat.node; if let hir::StmtKind::Expr(ref if_) = expr.node; if let hir::ExprKind::If(ref cond, ref then, ref else_) = if_.node; if !used_in_expr(cx, canonical_id, cond); @@ -142,7 +141,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq { struct UsedVisitor<'a, 'tcx: 'a> { cx: &'a LateContext<'a, 'tcx>, - id: ast::NodeId, + id: hir::HirId, used: bool, } @@ -151,7 +150,7 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for UsedVisitor<'a, 'tcx> { if_chain! { if let hir::ExprKind::Path(ref qpath) = expr.node; if let Def::Local(local_id) = self.cx.tables.qpath_def(qpath, expr.hir_id); - if self.id == local_id; + if self.id == self.cx.tcx.hir().node_to_hir_id(local_id); then { self.used = true; return; @@ -166,7 +165,7 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for UsedVisitor<'a, 'tcx> { fn check_assign<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, - decl: ast::NodeId, + decl: hir::HirId, block: &'tcx hir::Block, ) -> Option<&'tcx hir::Expr> { if_chain! { @@ -176,7 +175,7 @@ fn check_assign<'a, 'tcx>( if let hir::ExprKind::Assign(ref var, ref value) = expr.node; if let hir::ExprKind::Path(ref qpath) = var.node; if let Def::Local(local_id) = cx.tables.qpath_def(qpath, var.hir_id); - if decl == local_id; + if decl == cx.tcx.hir().node_to_hir_id(local_id); then { let mut v = UsedVisitor { cx, @@ -199,7 +198,7 @@ fn check_assign<'a, 'tcx>( None } -fn used_in_expr<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, id: ast::NodeId, expr: &'tcx hir::Expr) -> bool { +fn used_in_expr<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, id: hir::HirId, expr: &'tcx hir::Expr) -> bool { let mut v = UsedVisitor { cx, id, used: false }; hir::intravisit::walk_expr(&mut v, expr); v.used diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 06d6a508701..bd795031805 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -272,7 +272,7 @@ pub mod zero_div_zero; pub use crate::utils::conf::Conf; mod reexport { - crate use syntax::ast::{Name, NodeId}; + crate use syntax::ast::Name; } /// Register all pre expansion lints diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 2cde33372a7..9fe6504bd42 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -486,8 +486,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { // check for never_loop match expr.node { ExprKind::While(_, ref block, _) | ExprKind::Loop(ref block, _, _) => { - let node_id = cx.tcx.hir().hir_to_node_id(expr.hir_id); - match never_loop_block(block, node_id) { + match never_loop_block(block, expr.hir_id) { NeverLoopResult::AlwaysBreak => { span_lint(cx, NEVER_LOOP, expr.span, "this loop never actually loops") }, @@ -664,7 +663,7 @@ fn combine_branches(b1: NeverLoopResult, b2: NeverLoopResult) -> NeverLoopResult } } -fn never_loop_block(block: &Block, main_loop_id: NodeId) -> NeverLoopResult { +fn never_loop_block(block: &Block, main_loop_id: HirId) -> NeverLoopResult { let stmts = block.stmts.iter().map(stmt_to_expr); let expr = once(block.expr.as_ref().map(|p| &**p)); let mut iter = stmts.chain(expr).filter_map(|e| e); @@ -679,7 +678,7 @@ fn stmt_to_expr(stmt: &Stmt) -> Option<&Expr> { } } -fn never_loop_expr(expr: &Expr, main_loop_id: NodeId) -> NeverLoopResult { +fn never_loop_expr(expr: &Expr, main_loop_id: HirId) -> NeverLoopResult { match expr.node { ExprKind::Box(ref e) | ExprKind::Unary(_, ref e) @@ -753,17 +752,17 @@ fn never_loop_expr(expr: &Expr, main_loop_id: NodeId) -> NeverLoopResult { } } -fn never_loop_expr_seq<'a, T: Iterator>(es: &mut T, main_loop_id: NodeId) -> NeverLoopResult { +fn never_loop_expr_seq<'a, T: Iterator>(es: &mut T, main_loop_id: HirId) -> NeverLoopResult { es.map(|e| never_loop_expr(e, main_loop_id)) .fold(NeverLoopResult::Otherwise, combine_seq) } -fn never_loop_expr_all<'a, T: Iterator>(es: &mut T, main_loop_id: NodeId) -> NeverLoopResult { +fn never_loop_expr_all<'a, T: Iterator>(es: &mut T, main_loop_id: HirId) -> NeverLoopResult { es.map(|e| never_loop_expr(e, main_loop_id)) .fold(NeverLoopResult::Otherwise, combine_both) } -fn never_loop_expr_branch<'a, T: Iterator>(e: &mut T, main_loop_id: NodeId) -> NeverLoopResult { +fn never_loop_expr_branch<'a, T: Iterator>(e: &mut T, main_loop_id: HirId) -> NeverLoopResult { e.map(|e| never_loop_expr(e, main_loop_id)) .fold(NeverLoopResult::AlwaysBreak, combine_branches) } @@ -784,14 +783,14 @@ fn check_for_loop<'a, 'tcx>( detect_manual_memcpy(cx, pat, arg, body, expr); } -fn same_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var: ast::NodeId) -> bool { +fn same_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var: HirId) -> bool { if_chain! { if let ExprKind::Path(ref qpath) = expr.node; if let QPath::Resolved(None, ref path) = *qpath; if path.segments.len() == 1; if let Def::Local(local_id) = cx.tables.qpath_def(qpath, expr.hir_id); // our variable! - if local_id == var; + if cx.tcx.hir().node_to_hir_id(local_id) == var; then { return true; } @@ -833,8 +832,8 @@ fn is_slice_like<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'_>) -> bool { is_slice || match_type(cx, ty, &paths::VEC) || match_type(cx, ty, &paths::VEC_DEQUE) } -fn get_fixed_offset_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var: ast::NodeId) -> Option { - fn extract_offset<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, e: &Expr, var: ast::NodeId) -> Option { +fn get_fixed_offset_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var: HirId) -> Option { + fn extract_offset<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, e: &Expr, var: HirId) -> Option { match e.node { ExprKind::Lit(ref l) => match l.node { ast::LitKind::Int(x, _ty) => Some(x.to_string()), @@ -889,7 +888,7 @@ fn get_fixed_offset_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var: fn fetch_cloned_fixed_offset_var<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, expr: &Expr, - var: ast::NodeId, + var: HirId, ) -> Option { if_chain! { if let ExprKind::MethodCall(ref method, _, ref args) = expr.node; @@ -907,12 +906,12 @@ fn fetch_cloned_fixed_offset_var<'a, 'tcx>( fn get_indexed_assignments<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, body: &Expr, - var: ast::NodeId, + var: HirId, ) -> Vec<(FixedOffsetVar, FixedOffsetVar)> { fn get_assignment<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, e: &Expr, - var: ast::NodeId, + var: HirId, ) -> Option<(FixedOffsetVar, FixedOffsetVar)> { if let ExprKind::Assign(ref lhs, ref rhs) = e.node { match ( @@ -970,7 +969,7 @@ fn detect_manual_memcpy<'a, 'tcx>( }) = higher::range(cx, arg) { // the var must be a single name - if let PatKind::Binding(_, canonical_id, _, _, _) = pat.node { + if let PatKind::Binding(_, canonical_id, _, _) = pat.node { let print_sum = |arg1: &Offset, arg2: &Offset| -> String { match (&arg1.value[..], arg1.negate, &arg2.value[..], arg2.negate) { ("0", _, "0", _) => "".into(), @@ -1087,7 +1086,7 @@ fn check_for_loop_range<'a, 'tcx>( }) = higher::range(cx, arg) { // the var must be a single name - if let PatKind::Binding(_, canonical_id, _, ident, _) = pat.node { + if let PatKind::Binding(_, canonical_id, ident, _) = pat.node { let mut visitor = VarVisitor { cx, var: canonical_id, @@ -1711,7 +1710,7 @@ impl<'tcx> Visitor<'tcx> for UsedVisitor { struct LocalUsedVisitor<'a, 'tcx: 'a> { cx: &'a LateContext<'a, 'tcx>, - local: ast::NodeId, + local: HirId, used: bool, } @@ -1733,7 +1732,7 @@ struct VarVisitor<'a, 'tcx: 'a> { /// context reference cx: &'a LateContext<'a, 'tcx>, /// var name to look for as index - var: ast::NodeId, + var: HirId, /// indexed variables that are used mutably indexed_mut: FxHashSet, /// indirectly indexed variables (`v[(i + 4) % N]`), the extend is `None` for global @@ -1841,7 +1840,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { then { match self.cx.tables.qpath_def(qpath, expr.hir_id) { Def::Upvar(local_id, ..) => { - if local_id == self.var { + if self.cx.tcx.hir().node_to_hir_id(local_id) == self.var { // we are not indexing anything, record that self.nonindex = true; } @@ -1849,7 +1848,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { Def::Local(local_id) => { - if local_id == self.var { + if self.cx.tcx.hir().node_to_hir_id(local_id) == self.var { self.nonindex = true; } else { // not the correct variable, but still a variable diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index 2fc3a4fd5c1..580d22845b0 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -482,7 +482,7 @@ fn check_wild_enum_match(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm]) { for pat in &arm.pats { if let PatKind::Wild = pat.node { wildcard_span = Some(pat.span); - } else if let PatKind::Binding(_, _, _, ident, None) = pat.node { + } else if let PatKind::Binding(_, _, ident, None) = pat.node { wildcard_span = Some(pat.span); wildcard_ident = Some(ident); } diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 82c5b62145b..87bf3b5485f 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -115,7 +115,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline { // trait method with default body needs inline in case // an impl is not provided let desc = "a default trait method"; - let item = cx.tcx.hir().expect_trait_item_by_hir_id(tit.id.hir_id); + let item = cx.tcx.hir().expect_trait_item(tit.id.hir_id); check_missing_inline_attrs(cx, &item.attrs, item.span, desc); } }, diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 5dfc36d3e0e..a3748d87a83 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -209,7 +209,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { if !implements_borrow_trait; if !all_borrowable_trait; - if let PatKind::Binding(mode, _, canonical_id, ..) = arg.pat.node; + if let PatKind::Binding(mode, canonical_id, ..) = arg.pat.node; if !moved_vars.contains(&canonical_id); then { if mode == BindingAnnotation::Mutable || mode == BindingAnnotation::RefMut { diff --git a/clippy_lints/src/unused_io_amount.rs b/clippy_lints/src/unused_io_amount.rs index 89f6873565a..bf31b774bba 100644 --- a/clippy_lints/src/unused_io_amount.rs +++ b/clippy_lints/src/unused_io_amount.rs @@ -50,7 +50,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedIoAmount { }; match expr.node { - hir::ExprKind::Match(ref res, _, _) if is_try(expr).is_some() => { + hir::ExprKind::Match(ref res, _, _) if is_try(cx, expr).is_some() => { if let hir::ExprKind::Call(ref func, ref args) = res.node { if let hir::ExprKind::Path(ref path) = func.node { if match_qpath(path, &paths::TRY_INTO_RESULT) && args.len() == 1 { diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index 877f431e641..343098ceeee 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -164,8 +164,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass { output: &mut self.registered_lints, cx, }; - let node_id = cx.tcx.hir().hir_to_node_id(impl_item_refs[0].id.hir_id); - let body_id = cx.tcx.hir().body_owned_by(node_id); + let body_id = cx.tcx.hir().body_owned_by(impl_item_refs[0].id.hir_id); collector.visit_expr(&cx.tcx.hir().body(body_id).value); } } diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 70ba0592caa..f6b9a77a573 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -829,15 +829,15 @@ pub fn iter_input_pats<'tcx>(decl: &FnDecl, body: &'tcx Body) -> impl Iterator Option<&Expr> { - fn is_ok(arm: &Arm) -> bool { +pub fn is_try<'a>(cx: &'_ LateContext<'_, '_>, expr: &'a Expr) -> Option<&'a Expr> { + fn is_ok(cx: &'_ LateContext<'_, '_>, arm: &Arm) -> bool { if_chain! { if let PatKind::TupleStruct(ref path, ref pat, None) = arm.pats[0].node; if match_qpath(path, &paths::RESULT_OK[1..]); - if let PatKind::Binding(_, defid, _, _, None) = pat[0].node; + if let PatKind::Binding(_, hir_id, _, None) = pat[0].node; if let ExprKind::Path(QPath::Resolved(None, ref path)) = arm.body.node; if let Def::Local(lid) = path.def; - if lid == defid; + if cx.tcx.hir().node_to_hir_id(lid) == hir_id; then { return true; } @@ -863,8 +863,8 @@ pub fn is_try(expr: &Expr) -> Option<&Expr> { if arms.len() == 2; if arms[0].pats.len() == 1 && arms[0].guard.is_none(); if arms[1].pats.len() == 1 && arms[1].guard.is_none(); - if (is_ok(&arms[0]) && is_err(&arms[1])) || - (is_ok(&arms[1]) && is_err(&arms[0])); + if (is_ok(cx, &arms[0]) && is_err(&arms[1])) || + (is_ok(cx, &arms[1]) && is_err(&arms[0])); then { return Some(expr); }