diff --git a/clippy_lints/src/copy_iterator.rs b/clippy_lints/src/copy_iterator.rs index 59eef9e39..3fac6e78a 100644 --- a/clippy_lints/src/copy_iterator.rs +++ b/clippy_lints/src/copy_iterator.rs @@ -44,7 +44,7 @@ impl LintPass for CopyIterator { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyIterator { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) { if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) = item.node { - let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.id)); + let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id_from_hir_id(item.hir_id)); if is_copy(cx, ty) && match_path(&trait_ref.path, &paths::ITERATOR) { span_note_and_lint( diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 9580fbbe4..2460a2746 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -77,7 +77,7 @@ impl LintPass for Derive { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Derive { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) { if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) = item.node { - let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.id)); + let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id_from_hir_id(item.hir_id)); let is_automatically_derived = is_automatically_derived(&*item.attrs); check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived); diff --git a/clippy_lints/src/empty_enum.rs b/clippy_lints/src/empty_enum.rs index ab80625f6..60d83a98d 100644 --- a/clippy_lints/src/empty_enum.rs +++ b/clippy_lints/src/empty_enum.rs @@ -38,7 +38,7 @@ impl LintPass for EmptyEnum { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EmptyEnum { fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item) { - let did = cx.tcx.hir().local_def_id(item.id); + let did = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id); if let ItemKind::Enum(..) = item.node { let ty = cx.tcx.type_of(did); let adt = ty.ty_adt_def().expect("already checked whether this is an enum"); diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 3f49cbdc0..45ecdc3d3 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -6,9 +6,8 @@ use rustc::middle::expr_use_visitor::*; use rustc::middle::mem_categorization::{cmt_, Categorization}; use rustc::ty::layout::LayoutOf; use rustc::ty::{self, Ty}; -use rustc::util::nodemap::NodeSet; +use rustc::util::nodemap::HirIdSet; use rustc::{declare_tool_lint, lint_array}; -use syntax::ast::NodeId; use syntax::source_map::Span; pub struct Pass { @@ -44,7 +43,7 @@ fn is_non_trait_box(ty: Ty<'_>) -> bool { struct EscapeDelegate<'a, 'tcx: 'a> { cx: &'a LateContext<'a, 'tcx>, - set: NodeSet, + set: HirIdSet, too_large_for_stack: u64, } @@ -80,7 +79,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { let mut v = EscapeDelegate { cx, - set: NodeSet::default(), + set: HirIdSet::default(), too_large_for_stack: self.too_large_for_stack, }; @@ -92,7 +91,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { span_lint( cx, BOXED_LOCAL, - cx.tcx.hir().span(node), + cx.tcx.hir().span_by_hir_id(node), "local variable doesn't need to be boxed here", ); } @@ -111,13 +110,13 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { fn matched_pat(&mut self, _: &Pat, _: &cmt_<'tcx>, _: MatchMode) {} fn consume_pat(&mut self, consume_pat: &Pat, cmt: &cmt_<'tcx>, _: ConsumeMode) { let map = &self.cx.tcx.hir(); - if map.is_argument(consume_pat.id) { + if map.is_argument(map.hir_to_node_id(consume_pat.hir_id)) { // Skip closure arguments - if let Some(Node::Expr(..)) = map.find(map.get_parent_node(consume_pat.id)) { + if let Some(Node::Expr(..)) = map.find_by_hir_id(map.get_parent_node_by_hir_id(consume_pat.hir_id)) { return; } if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) { - self.set.insert(consume_pat.id); + self.set.insert(consume_pat.hir_id); } return; } @@ -129,7 +128,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { if let ExprKind::Box(..) = ex.node { if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) { // let x = box (...) - self.set.insert(consume_pat.id); + self.set.insert(consume_pat.hir_id); } // TODO Box::new // TODO vec![] @@ -143,7 +142,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { if self.set.contains(&lid) { // let y = x where x is known // remove x, insert y - self.set.insert(consume_pat.id); + self.set.insert(consume_pat.hir_id); self.set.remove(&lid); } } @@ -177,7 +176,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { } } } - fn decl_without_init(&mut self, _: NodeId, _: Span) {} + fn decl_without_init(&mut self, _: HirId, _: Span) {} fn mutate(&mut self, _: HirId, _: Span, _: &cmt_<'tcx>, _: MutateMode) {} } diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index 3669e8998..48d4db53d 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -43,7 +43,7 @@ impl LintPass for FallibleImplFrom { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FallibleImplFrom { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) { // check for `impl From for ..` - let impl_def_id = cx.tcx.hir().local_def_id(item.id); + let impl_def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id); if_chain! { if let hir::ItemKind::Impl(.., ref impl_items) = item.node; if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_def_id); @@ -105,7 +105,7 @@ fn lint_impl_body<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, impl_span: Span, impl_it then { // check the body for `begin_panic` or `unwrap` let body = cx.tcx.hir().body(body_id); - let impl_item_def_id = cx.tcx.hir().local_def_id(impl_item.id.node_id); + let impl_item_def_id = cx.tcx.hir().local_def_id_from_hir_id(impl_item.id.hir_id); let mut fpu = FindPanicUnwrap { tcx: cx.tcx, tables: cx.tcx.typeck_tables_of(impl_item_def_id), diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index 3b15f2760..1a9089b55 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -150,8 +150,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions { } } - let nodeid = cx.tcx.hir().hir_to_node_id(hir_id); - self.check_raw_ptr(cx, unsafety, decl, body, nodeid); + self.check_raw_ptr(cx, unsafety, decl, body, hir_id); self.check_line_number(cx, span, body); } @@ -164,7 +163,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions { if let hir::TraitMethod::Provided(eid) = *eid { let body = cx.tcx.hir().body(eid); - self.check_raw_ptr(cx, sig.header.unsafety, &sig.decl, body, item.id); + self.check_raw_ptr(cx, sig.header.unsafety, &sig.decl, body, item.hir_id); } } } @@ -255,10 +254,11 @@ impl<'a, 'tcx> Functions { unsafety: hir::Unsafety, decl: &'tcx hir::FnDecl, body: &'tcx hir::Body, - nodeid: ast::NodeId, + hir_id: hir::HirId, ) { let expr = &body.value; - if unsafety == hir::Unsafety::Normal && cx.access_levels.is_exported(nodeid) { + let node_id = cx.tcx.hir().hir_to_node_id(hir_id); + if unsafety == hir::Unsafety::Normal && cx.access_levels.is_exported(node_id) { let raw_ptrs = iter_input_pats(decl, body) .zip(decl.inputs.iter()) .filter_map(|(arg, ty)| raw_ptr_arg(arg, ty)) diff --git a/clippy_lints/src/large_enum_variant.rs b/clippy_lints/src/large_enum_variant.rs index a6d34f2c7..7a1a0e599 100644 --- a/clippy_lints/src/large_enum_variant.rs +++ b/clippy_lints/src/large_enum_variant.rs @@ -54,7 +54,7 @@ impl LintPass for LargeEnumVariant { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeEnumVariant { fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item) { - let did = cx.tcx.hir().local_def_id(item.id); + let did = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id); if let ItemKind::Enum(ref def, _) = item.node { let ty = cx.tcx.type_of(did); let adt = ty.ty_adt_def().expect("already checked whether this is an enum"); diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 2764cd6ff..094cfcf1b 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -132,7 +132,7 @@ fn check_trait_items(cx: &LateContext<'_, '_>, visited_trait: &Item, trait_items item.ident.name == name && if let AssociatedItemKind::Method { has_self } = item.kind { has_self && { - let did = cx.tcx.hir().local_def_id(item.id.node_id); + let did = cx.tcx.hir().local_def_id_from_hir_id(item.id.hir_id); cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1 } } else { @@ -149,9 +149,11 @@ fn check_trait_items(cx: &LateContext<'_, '_>, visited_trait: &Item, trait_items } } - if cx.access_levels.is_exported(visited_trait.id) && trait_items.iter().any(|i| is_named_self(cx, i, "len")) { + let trait_node_id = cx.tcx.hir().hir_to_node_id(visited_trait.hir_id); + + if cx.access_levels.is_exported(trait_node_id) && trait_items.iter().any(|i| is_named_self(cx, i, "len")) { let mut current_and_super_traits = FxHashSet::default(); - let visited_trait_def_id = cx.tcx.hir().local_def_id(visited_trait.id); + let visited_trait_def_id = cx.tcx.hir().local_def_id_from_hir_id(visited_trait.hir_id); fill_trait_set(visited_trait_def_id, &mut current_and_super_traits, cx); let is_empty_method_found = current_and_super_traits @@ -183,7 +185,7 @@ fn check_impl_items(cx: &LateContext<'_, '_>, item: &Item, impl_items: &[ImplIte item.ident.name == name && if let AssociatedItemKind::Method { has_self } = item.kind { has_self && { - let did = cx.tcx.hir().local_def_id(item.id.node_id); + let did = cx.tcx.hir().local_def_id_from_hir_id(item.id.hir_id); cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1 } } else { @@ -192,7 +194,10 @@ fn check_impl_items(cx: &LateContext<'_, '_>, item: &Item, impl_items: &[ImplIte } let is_empty = if let Some(is_empty) = impl_items.iter().find(|i| is_named_self(cx, i, "is_empty")) { - if cx.access_levels.is_exported(is_empty.id.node_id) { + if cx + .access_levels + .is_exported(cx.tcx.hir().hir_to_node_id(is_empty.id.hir_id)) + { return; } else { "a private" @@ -202,8 +207,8 @@ fn check_impl_items(cx: &LateContext<'_, '_>, item: &Item, impl_items: &[ImplIte }; if let Some(i) = impl_items.iter().find(|i| is_named_self(cx, i, "len")) { - if cx.access_levels.is_exported(i.id.node_id) { - let def_id = cx.tcx.hir().local_def_id(item.id); + if cx.access_levels.is_exported(cx.tcx.hir().hir_to_node_id(i.id.hir_id)) { + let def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id); let ty = cx.tcx.type_of(def_id); span_lint( diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 73da2467f..811e7fc6c 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -1562,8 +1562,8 @@ fn check_for_loop_over_map_kv<'a, 'tcx>( } struct MutatePairDelegate { - node_id_low: Option, - node_id_high: Option, + hir_id_low: Option, + hir_id_high: Option, span_low: Option, span_high: Option, } @@ -1578,10 +1578,10 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate { fn borrow(&mut self, _: HirId, sp: Span, cmt: &cmt_<'tcx>, _: ty::Region<'_>, bk: ty::BorrowKind, _: LoanCause) { if let ty::BorrowKind::MutBorrow = bk { if let Categorization::Local(id) = cmt.cat { - if Some(id) == self.node_id_low { + if Some(id) == self.hir_id_low { self.span_low = Some(sp) } - if Some(id) == self.node_id_high { + if Some(id) == self.hir_id_high { self.span_high = Some(sp) } } @@ -1590,16 +1590,16 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate { fn mutate(&mut self, _: HirId, sp: Span, cmt: &cmt_<'tcx>, _: MutateMode) { if let Categorization::Local(id) = cmt.cat { - if Some(id) == self.node_id_low { + if Some(id) == self.hir_id_low { self.span_low = Some(sp) } - if Some(id) == self.node_id_high { + if Some(id) == self.hir_id_high { self.span_high = Some(sp) } } } - fn decl_without_init(&mut self, _: NodeId, _: Span) {} + fn decl_without_init(&mut self, _: HirId, _: Span) {} } impl<'tcx> MutatePairDelegate { @@ -1635,7 +1635,7 @@ fn mut_warn_with_span(cx: &LateContext<'_, '_>, span: Option) { } } -fn check_for_mutability(cx: &LateContext<'_, '_>, bound: &Expr) -> Option { +fn check_for_mutability(cx: &LateContext<'_, '_>, bound: &Expr) -> Option { if_chain! { if let ExprKind::Path(ref qpath) = bound.node; if let QPath::Resolved(None, _) = *qpath; @@ -1648,7 +1648,7 @@ fn check_for_mutability(cx: &LateContext<'_, '_>, bound: &Expr) -> Option, bound: &Expr) -> Option, body: &Expr, - bound_ids: &[Option], + bound_ids: &[Option], ) -> (Option, Option) { let mut delegate = MutatePairDelegate { - node_id_low: bound_ids[0], - node_id_high: bound_ids[1], + hir_id_low: bound_ids[0], + hir_id_high: bound_ids[1], span_low: None, span_high: None, }; @@ -1938,8 +1938,7 @@ fn is_iterator_used_after_while_let<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, it past_while_let: false, var_used_after_while_let: false, }; - let def_hir_id = cx.tcx.hir().node_to_hir_id(def_id); - if let Some(enclosing_block) = get_enclosing_block(cx, def_hir_id) { + if let Some(enclosing_block) = get_enclosing_block(cx, def_id) { walk_block(&mut visitor, enclosing_block); } visitor.var_used_after_while_let @@ -1947,7 +1946,7 @@ fn is_iterator_used_after_while_let<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, it struct VarUsedAfterLoopVisitor<'a, 'tcx: 'a> { cx: &'a LateContext<'a, 'tcx>, - def_id: NodeId, + def_id: HirId, iter_expr_id: HirId, past_while_let: bool, var_used_after_while_let: bool, @@ -2052,9 +2051,9 @@ enum VarState { /// Scan a for loop for variables that are incremented exactly once. struct IncrementVisitor<'a, 'tcx: 'a> { - cx: &'a LateContext<'a, 'tcx>, // context reference - states: FxHashMap, // incremented variables - depth: u32, // depth of conditional expressions + cx: &'a LateContext<'a, 'tcx>, // context reference + states: FxHashMap, // incremented variables + depth: u32, // depth of conditional expressions done: bool, } @@ -2108,7 +2107,7 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> { struct InitializeVisitor<'a, 'tcx: 'a> { cx: &'a LateContext<'a, 'tcx>, // context reference end_expr: &'tcx Expr, // the for loop. Stop scanning here. - var_id: NodeId, + var_id: HirId, state: VarState, name: Option, depth: u32, // depth of conditional expressions @@ -2119,7 +2118,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> { fn visit_stmt(&mut self, stmt: &'tcx Stmt) { // Look for declarations of the variable if let StmtKind::Local(ref local) = stmt.node { - if local.pat.id == self.var_id { + if local.pat.hir_id == self.var_id { if let PatKind::Binding(.., ident, _) = local.pat.node { self.name = Some(ident.name); @@ -2191,11 +2190,11 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> { } } -fn var_def_id(cx: &LateContext<'_, '_>, expr: &Expr) -> Option { +fn var_def_id(cx: &LateContext<'_, '_>, expr: &Expr) -> Option { if let ExprKind::Path(ref qpath) = expr.node { let path_res = cx.tables.qpath_def(qpath, expr.hir_id); if let Def::Local(node_id) = path_res { - return Some(node_id); + return Some(cx.tcx.hir().node_to_hir_id(node_id)); } } None @@ -2376,7 +2375,7 @@ fn check_infinite_loop<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, cond: &'tcx Expr, e /// All variables definition IDs are collected struct VarCollectorVisitor<'a, 'tcx: 'a> { cx: &'a LateContext<'a, 'tcx>, - ids: FxHashSet, + ids: FxHashSet, def_ids: FxHashMap, skip: bool, } @@ -2390,7 +2389,7 @@ impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> { then { match def { Def::Local(node_id) | Def::Upvar(node_id, ..) => { - self.ids.insert(node_id); + self.ids.insert(self.cx.tcx.hir().node_to_hir_id(node_id)); }, Def::Static(def_id, mutable) => { self.def_ids.insert(def_id, mutable); diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 8d4bb06e5..deaf054ae 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -907,9 +907,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { return; } let name = implitem.ident.name; - let parent = cx.tcx.hir().get_parent(implitem.id); - let item = cx.tcx.hir().expect_item(parent); - let def_id = cx.tcx.hir().local_def_id(item.id); + let parent = cx.tcx.hir().get_parent_item(implitem.hir_id); + let item = cx.tcx.hir().expect_item_by_hir_id(parent); + let def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id); let ty = cx.tcx.type_of(def_id); if_chain! { if let hir::ImplItemKind::Method(ref sig, id) = implitem.node; @@ -917,7 +917,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { if let Some(first_arg) = iter_input_pats(&sig.decl, cx.tcx.hir().body(id)).next(); if let hir::ItemKind::Impl(_, _, _, _, None, ref self_ty, _) = item.node; then { - if cx.access_levels.is_exported(implitem.id) { + let node_id = cx.tcx.hir().hir_to_node_id(implitem.hir_id); + if cx.access_levels.is_exported(node_id) { // check missing trait implementations for &(method_name, n_args, self_kind, out_type, trait_name) in &TRAIT_METHODS { if name == method_name && @@ -964,7 +965,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { } if let hir::ImplItemKind::Method(_, _) = implitem.node { - let ret_ty = return_ty(cx, implitem.id); + let ret_ty = return_ty(cx, implitem.hir_id); // walk the return type and check for Self (this does not check associated types) for inner_type in ret_ty.walk() { diff --git a/clippy_lints/src/methods/unnecessary_filter_map.rs b/clippy_lints/src/methods/unnecessary_filter_map.rs index 8d90a4388..c081384db 100644 --- a/clippy_lints/src/methods/unnecessary_filter_map.rs +++ b/clippy_lints/src/methods/unnecessary_filter_map.rs @@ -5,7 +5,6 @@ use rustc::hir; use rustc::hir::def::Def; use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc::lint::LateContext; -use syntax::ast; use if_chain::if_chain; @@ -18,7 +17,7 @@ pub(super) fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &[hir::Expr if let hir::ExprKind::Closure(_, _, body_id, ..) = args[1].node { let body = cx.tcx.hir().body(body_id); - let arg_id = body.arguments[0].pat.id; + let arg_id = body.arguments[0].pat.hir_id; let mutates_arg = match mutated_variables(&body.value, cx) { Some(used_mutably) => used_mutably.contains(&arg_id), None => true, @@ -56,7 +55,7 @@ pub(super) fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &[hir::Expr // returns (found_mapping, found_filtering) fn check_expression<'a, 'tcx: 'a>( cx: &'a LateContext<'a, 'tcx>, - arg_id: ast::NodeId, + arg_id: hir::HirId, expr: &'tcx hir::Expr, ) -> (bool, bool) { match &expr.node { @@ -69,7 +68,7 @@ fn check_expression<'a, 'tcx: 'a>( if let hir::ExprKind::Path(path) = &args[0].node; if let Def::Local(ref local) = cx.tables.qpath_def(path, args[0].hir_id); then { - if arg_id == *local { + if arg_id == cx.tcx.hir().node_to_hir_id(*local) { return (false, false) } } @@ -113,7 +112,7 @@ fn check_expression<'a, 'tcx: 'a>( struct ReturnVisitor<'a, 'tcx: 'a> { cx: &'a LateContext<'a, 'tcx>, - arg_id: ast::NodeId, + arg_id: hir::HirId, // Found a non-None return that isn't Some(input) found_mapping: bool, // Found a return that isn't Some @@ -121,7 +120,7 @@ struct ReturnVisitor<'a, 'tcx: 'a> { } impl<'a, 'tcx: 'a> ReturnVisitor<'a, 'tcx> { - fn new(cx: &'a LateContext<'a, 'tcx>, arg_id: ast::NodeId) -> ReturnVisitor<'a, 'tcx> { + fn new(cx: &'a LateContext<'a, 'tcx>, arg_id: hir::HirId) -> ReturnVisitor<'a, 'tcx> { ReturnVisitor { cx, arg_id, diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 9fd67e2fc..8c5c1f652 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -124,7 +124,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { hir::ItemKind::Fn(..) => { // ignore main() if it.ident.name == "main" { - let def_id = cx.tcx.hir().local_def_id(it.id); + let def_id = cx.tcx.hir().local_def_id_from_hir_id(it.hir_id); let def_key = cx.tcx.hir().def_key(def_id); if def_key.parent == Some(hir::def_id::CRATE_DEF_INDEX) { return; @@ -162,7 +162,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, impl_item: &'tcx hir::ImplItem) { // If the method is an impl for a trait, don't doc. - let def_id = cx.tcx.hir().local_def_id(impl_item.id); + let def_id = cx.tcx.hir().local_def_id_from_hir_id(impl_item.hir_id); match cx.tcx.associated_item(def_id).container { ty::TraitContainer(_) => return, ty::ImplContainer(cid) => { diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 754215799..2a7a211f2 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -95,7 +95,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline { return; } - if !cx.access_levels.is_exported(it.id) { + if !cx.access_levels.is_exported(cx.tcx.hir().hir_to_node_id(it.hir_id)) { return; } match it.node { @@ -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(tit.id.node_id); + let item = cx.tcx.hir().expect_trait_item_by_hir_id(tit.id.hir_id); check_missing_inline_attrs(cx, &item.attrs, item.span, desc); } }, @@ -146,7 +146,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline { } // If the item being implemented is not exported, then we don't need #[inline] - if !cx.access_levels.is_exported(impl_item.id) { + let node_id = cx.tcx.hir().hir_to_node_id(impl_item.hir_id); + if !cx.access_levels.is_exported(node_id) { return; } @@ -155,7 +156,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline { hir::ImplItemKind::Const(..) | hir::ImplItemKind::Type(_) | hir::ImplItemKind::Existential(_) => return, }; - let def_id = cx.tcx.hir().local_def_id(impl_item.id); + let def_id = cx.tcx.hir().local_def_id_from_hir_id(impl_item.hir_id); let trait_def_id = match cx.tcx.associated_item(def_id).container { TraitContainer(cid) => Some(cid), ImplContainer(cid) => cx.tcx.impl_trait_ref(cid).map(|t| t.def_id), diff --git a/clippy_lints/src/needless_borrow.rs b/clippy_lints/src/needless_borrow.rs index 777d2f683..91e391873 100644 --- a/clippy_lints/src/needless_borrow.rs +++ b/clippy_lints/src/needless_borrow.rs @@ -4,13 +4,12 @@ use crate::utils::{in_macro, snippet_opt, span_lint_and_then}; use if_chain::if_chain; -use rustc::hir::{BindingAnnotation, Expr, ExprKind, Item, MutImmutable, Pat, PatKind}; +use rustc::hir::{BindingAnnotation, Expr, ExprKind, HirId, Item, MutImmutable, Pat, PatKind}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::ty; use rustc::ty::adjustment::{Adjust, Adjustment}; use rustc::{declare_tool_lint, lint_array}; use rustc_errors::Applicability; -use syntax::ast::NodeId; /// **What it does:** Checks for address of operations (`&`) that are going to /// be dereferenced immediately by the compiler. @@ -32,7 +31,7 @@ declare_clippy_lint! { #[derive(Default)] pub struct NeedlessBorrow { - derived_item: Option, + derived_item: Option, } impl LintPass for NeedlessBorrow { @@ -119,13 +118,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow { fn check_item(&mut self, _: &LateContext<'a, 'tcx>, item: &'tcx Item) { if item.attrs.iter().any(|a| a.check_name("automatically_derived")) { debug_assert!(self.derived_item.is_none()); - self.derived_item = Some(item.id); + self.derived_item = Some(item.hir_id); } } fn check_item_post(&mut self, _: &LateContext<'a, 'tcx>, item: &'tcx Item) { if let Some(id) = self.derived_item { - if item.id == id { + if item.hir_id == id { self.derived_item = None; } } diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 69d04ff74..43343bcfa 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -17,7 +17,6 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::Applicability; use rustc_target::spec::abi::Abi; use std::borrow::Cow; -use syntax::ast::NodeId; use syntax::errors::DiagnosticBuilder; use syntax_pos::Span; @@ -210,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 { @@ -326,10 +325,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { struct MovedVariablesCtxt<'a, 'tcx: 'a> { cx: &'a LateContext<'a, 'tcx>, - moved_vars: FxHashSet, + moved_vars: FxHashSet, /// Spans which need to be prefixed with `*` for dereferencing the /// suggested additional reference. - spans_need_deref: FxHashMap>, + spans_need_deref: FxHashMap>, } impl<'a, 'tcx> MovedVariablesCtxt<'a, 'tcx> { @@ -353,16 +352,16 @@ impl<'a, 'tcx> MovedVariablesCtxt<'a, 'tcx> { let cmt = unwrap_downcast_or_interior(cmt); if let mc::Categorization::Local(vid) = cmt.cat { - let mut id = matched_pat.id; + let mut id = matched_pat.hir_id; loop { - let parent = self.cx.tcx.hir().get_parent_node(id); + let parent = self.cx.tcx.hir().get_parent_node_by_hir_id(id); if id == parent { // no parent return; } id = parent; - if let Some(node) = self.cx.tcx.hir().find(id) { + if let Some(node) = self.cx.tcx.hir().find_by_hir_id(id) { match node { Node::Expr(e) => { // `match` and `if let` @@ -432,7 +431,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt<'a, 'tcx> { fn mutate(&mut self, _: HirId, _: Span, _: &mc::cmt_<'tcx>, _: euv::MutateMode) {} - fn decl_without_init(&mut self, _: NodeId, _: Span) {} + fn decl_without_init(&mut self, _: HirId, _: Span) {} } fn unwrap_downcast_or_interior<'a, 'tcx>(mut cmt: &'a mc::cmt_<'tcx>) -> mc::cmt_<'tcx> { diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index ce8b1db50..fe992d3cf 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -133,7 +133,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault { let self_did = cx.tcx.hir().local_def_id_from_hir_id(cx.tcx.hir().get_parent_item(id)); let self_ty = cx.tcx.type_of(self_did); if_chain! { - if same_tys(cx, self_ty, return_ty(cx, node_id)); + if same_tys(cx, self_ty, return_ty(cx, id)); if let Some(default_trait_id) = get_trait_def_id(cx, &paths::DEFAULT_TRAIT); then { if self.impling_types.is_none() { diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 3bc46f533..34a4a7eb2 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -177,8 +177,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst { fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, impl_item: &'tcx ImplItem) { if let ImplItemKind::Const(hir_ty, ..) = &impl_item.node { - let item_node_id = cx.tcx.hir().get_parent_node(impl_item.id); - let item = cx.tcx.hir().expect_item(item_node_id); + let item_hir_id = cx.tcx.hir().get_parent_node_by_hir_id(impl_item.hir_id); + let item = cx.tcx.hir().expect_item_by_hir_id(item_hir_id); // ensure the impl is an inherent impl. if let ItemKind::Impl(_, _, _, _, None, _, _) = item.node { let ty = hir_ty_to_ty(cx.tcx, hir_ty); diff --git a/clippy_lints/src/partialeq_ne_impl.rs b/clippy_lints/src/partialeq_ne_impl.rs index f57fd22c0..5c532516b 100644 --- a/clippy_lints/src/partialeq_ne_impl.rs +++ b/clippy_lints/src/partialeq_ne_impl.rs @@ -51,11 +51,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { then { for impl_item in impl_items { if impl_item.ident.name == "ne" { - let hir_id = cx.tcx.hir().node_to_hir_id(impl_item.id.node_id); span_lint_node( cx, PARTIALEQ_NE_IMPL, - hir_id, + impl_item.id.hir_id, impl_item.span, "re-implementing `PartialEq::ne` is unnecessary", ); diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index cddb1c710..e930aae10 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -10,7 +10,6 @@ use rustc::ty; use rustc::{declare_tool_lint, lint_array}; use rustc_errors::Applicability; use std::borrow::Cow; -use syntax::ast::NodeId; use syntax::source_map::Span; use syntax_pos::MultiSpan; @@ -111,18 +110,19 @@ impl LintPass for PointerPass { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PointerPass { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) { if let ItemKind::Fn(ref decl, _, _, body_id) = item.node { - check_fn(cx, decl, item.id, Some(body_id)); + check_fn(cx, decl, item.hir_id, Some(body_id)); } } fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx ImplItem) { if let ImplItemKind::Method(ref sig, body_id) = item.node { - if let Some(Node::Item(it)) = cx.tcx.hir().find(cx.tcx.hir().get_parent(item.id)) { + let parent_item = cx.tcx.hir().get_parent_item(item.hir_id); + if let Some(Node::Item(it)) = cx.tcx.hir().find_by_hir_id(parent_item) { if let ItemKind::Impl(_, _, _, _, Some(_), _, _) = it.node { return; // ignore trait impls } } - check_fn(cx, &sig.decl, item.id, Some(body_id)); + check_fn(cx, &sig.decl, item.hir_id, Some(body_id)); } } @@ -133,7 +133,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PointerPass { } else { None }; - check_fn(cx, &sig.decl, item.id, body_id); + check_fn(cx, &sig.decl, item.hir_id, body_id); } } @@ -152,8 +152,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PointerPass { } #[allow(clippy::too_many_lines)] -fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: NodeId, opt_body_id: Option) { - let fn_def_id = cx.tcx.hir().local_def_id(fn_id); +fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: HirId, opt_body_id: Option) { + let fn_def_id = cx.tcx.hir().local_def_id_from_hir_id(fn_id); let sig = cx.tcx.fn_sig(fn_def_id); let fn_ty = sig.skip_binder(); diff --git a/clippy_lints/src/trivially_copy_pass_by_ref.rs b/clippy_lints/src/trivially_copy_pass_by_ref.rs index 59e6bcedb..5c1d63787 100644 --- a/clippy_lints/src/trivially_copy_pass_by_ref.rs +++ b/clippy_lints/src/trivially_copy_pass_by_ref.rs @@ -72,11 +72,11 @@ impl<'a, 'tcx> TriviallyCopyPassByRef { } fn check_trait_method(&mut self, cx: &LateContext<'_, 'tcx>, item: &TraitItemRef) { - let method_def_id = cx.tcx.hir().local_def_id(item.id.node_id); + let method_def_id = cx.tcx.hir().local_def_id_from_hir_id(item.id.hir_id); let method_sig = cx.tcx.fn_sig(method_def_id); let method_sig = cx.tcx.erase_late_bound_regions(&method_sig); - let decl = match cx.tcx.hir().fn_decl(item.id.node_id) { + let decl = match cx.tcx.hir().fn_decl_by_hir_id(item.id.hir_id) { Some(b) => b, None => return, }; diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 7356f957d..09f596a10 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -2034,7 +2034,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitHasher { } } - if !cx.access_levels.is_exported(item.id) { + if !cx.access_levels.is_exported(cx.tcx.hir().hir_to_node_id(item.hir_id)) { return; } diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 94f98a17e..fb7bb1f0d 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -137,7 +137,7 @@ fn check_trait_method_impl_decl<'a, 'tcx: 'a>( let trait_method_sig = cx.tcx.fn_sig(trait_method.def_id); let trait_method_sig = cx.tcx.erase_late_bound_regions(&trait_method_sig); - let impl_method_def_id = cx.tcx.hir().local_def_id(impl_item.id); + let impl_method_def_id = cx.tcx.hir().local_def_id_from_hir_id(impl_item.hir_id); let impl_method_sig = cx.tcx.fn_sig(impl_method_def_id); let impl_method_sig = cx.tcx.erase_late_bound_regions(&impl_method_sig); @@ -192,7 +192,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UseSelf { item_path, cx, }; - let impl_def_id = cx.tcx.hir().local_def_id(item.id); + let impl_def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id); let impl_trait_ref = cx.tcx.impl_trait_ref(impl_def_id); if let Some(impl_trait_ref) = impl_trait_ref { diff --git a/clippy_lints/src/utils/diagnostics.rs b/clippy_lints/src/utils/diagnostics.rs index 5aaf2f9f7..6d04ce70b 100644 --- a/clippy_lints/src/utils/diagnostics.rs +++ b/clippy_lints/src/utils/diagnostics.rs @@ -135,8 +135,7 @@ pub fn span_lint_and_then<'a, 'tcx: 'a, T: LintContext<'tcx>, F>( } pub fn span_lint_node(cx: &LateContext<'_, '_>, lint: &'static Lint, node: HirId, sp: Span, msg: &str) { - let node_id = cx.tcx.hir().hir_to_node_id(node); - DiagnosticWrapper(cx.tcx.struct_span_lint_node(lint, node_id, sp, msg)).docs_link(lint); + DiagnosticWrapper(cx.tcx.struct_span_lint_hir(lint, node, sp, msg)).docs_link(lint); } pub fn span_lint_node_and_then( @@ -147,8 +146,7 @@ pub fn span_lint_node_and_then( msg: &str, f: impl FnOnce(&mut DiagnosticBuilder<'_>), ) { - let node_id = cx.tcx.hir().hir_to_node_id(node); - let mut db = DiagnosticWrapper(cx.tcx.struct_span_lint_node(lint, node_id, sp, msg)); + let mut db = DiagnosticWrapper(cx.tcx.struct_span_lint_hir(lint, node, sp, msg)); f(&mut db.0); db.docs_link(lint); } diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index c83e1c396..4d43c374b 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -344,7 +344,7 @@ fn print_expr(cx: &LateContext<'_, '_>, expr: &hir::Expr, indent: usize) { } fn print_item(cx: &LateContext<'_, '_>, item: &hir::Item) { - let did = cx.tcx.hir().local_def_id(item.id); + let did = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id); println!("item `{}`", item.ident.name); match item.vis.node { hir::VisibilityKind::Public => println!("public"), @@ -357,7 +357,7 @@ fn print_item(cx: &LateContext<'_, '_>, item: &hir::Item) { } match item.node { hir::ItemKind::ExternCrate(ref _renamed_from) => { - let def_id = cx.tcx.hir().local_def_id(item.id); + let def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id); if let Some(crate_id) = cx.tcx.extern_mod_stmt_cnum(def_id) { let source = cx.tcx.used_crate_source(crate_id); if let Some(ref src) = source.dylib { diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index 789504936..0821ab036 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -164,7 +164,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass { output: &mut self.registered_lints, cx, }; - let body_id = cx.tcx.hir().body_owned_by(impl_item_refs[0].id.node_id); + 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); 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 d7ed3191d..70ba0592c 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -702,8 +702,8 @@ pub fn is_direct_expn_of(span: Span, name: &str) -> Option { } /// Convenience function to get the return type of a function -pub fn return_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, fn_item: NodeId) -> Ty<'tcx> { - let fn_def_id = cx.tcx.hir().local_def_id(fn_item); +pub fn return_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, fn_item: hir::HirId) -> Ty<'tcx> { + let fn_def_id = cx.tcx.hir().local_def_id_from_hir_id(fn_item); let ret_ty = cx.tcx.fn_sig(fn_def_id).output(); cx.tcx.erase_late_bound_regions(&ret_ty) } @@ -878,8 +878,7 @@ pub fn is_try(expr: &Expr) -> Option<&Expr> { /// /// Useful for skipping long running code when it's unnecessary pub fn is_allowed(cx: &LateContext<'_, '_>, lint: &'static Lint, id: HirId) -> bool { - let node_id = cx.tcx.hir().hir_to_node_id(id); - cx.tcx.lint_level_at_node(lint, node_id).0 == Level::Allow + cx.tcx.lint_level_at_node(lint, id).0 == Level::Allow } pub fn get_arg_name(pat: &Pat) -> Option { diff --git a/clippy_lints/src/utils/usage.rs b/clippy_lints/src/utils/usage.rs index 1f649829f..f4c89a8ca 100644 --- a/clippy_lints/src/utils/usage.rs +++ b/clippy_lints/src/utils/usage.rs @@ -7,11 +7,10 @@ use rustc::middle::mem_categorization::cmt_; use rustc::middle::mem_categorization::Categorization; use rustc::ty; use rustc_data_structures::fx::FxHashSet; -use syntax::ast::NodeId; use syntax::source_map::Span; /// Returns a set of mutated local variable ids or None if mutations could not be determined. -pub fn mutated_variables<'a, 'tcx: 'a>(expr: &'tcx Expr, cx: &'a LateContext<'a, 'tcx>) -> Option> { +pub fn mutated_variables<'a, 'tcx: 'a>(expr: &'tcx Expr, cx: &'a LateContext<'a, 'tcx>) -> Option> { let mut delegate = MutVarsDelegate { used_mutably: FxHashSet::default(), skip: false, @@ -35,11 +34,11 @@ pub fn is_potentially_mutated<'a, 'tcx: 'a>( Def::Local(id) | Def::Upvar(id, ..) => id, _ => return true, }; - mutated_variables(expr, cx).map_or(true, |mutated| mutated.contains(&id)) + mutated_variables(expr, cx).map_or(true, |mutated| mutated.contains(&cx.tcx.hir().node_to_hir_id(id))) } struct MutVarsDelegate { - used_mutably: FxHashSet, + used_mutably: FxHashSet, skip: bool, } @@ -79,5 +78,5 @@ impl<'tcx> Delegate<'tcx> for MutVarsDelegate { self.update(&cmt.cat) } - fn decl_without_init(&mut self, _: NodeId, _: Span) {} + fn decl_without_init(&mut self, _: HirId, _: Span) {} }