From f3363b9cf245ea4725959454d3940c0a3d04ac2e Mon Sep 17 00:00:00 2001 From: ljedrz Date: Fri, 1 Mar 2019 13:26:06 +0100 Subject: [PATCH] align with rust-lang/rust/#58836 --- clippy_lints/src/copy_iterator.rs | 2 +- clippy_lints/src/derive.rs | 2 +- clippy_lints/src/empty_enum.rs | 2 +- clippy_lints/src/escape.rs | 23 +++++----- clippy_lints/src/fallible_impl_from.rs | 4 +- clippy_lints/src/large_enum_variant.rs | 2 +- clippy_lints/src/len_zero.rs | 16 ++++--- clippy_lints/src/loops.rs | 43 +++++++++---------- .../src/methods/unnecessary_filter_map.rs | 11 +++-- clippy_lints/src/missing_doc.rs | 2 +- clippy_lints/src/missing_inline.rs | 4 +- clippy_lints/src/needless_borrow.rs | 9 ++-- clippy_lints/src/needless_pass_by_value.rs | 15 +++---- clippy_lints/src/partialeq_ne_impl.rs | 3 +- .../src/trivially_copy_pass_by_ref.rs | 4 +- clippy_lints/src/types.rs | 2 +- clippy_lints/src/use_self.rs | 2 +- clippy_lints/src/utils/inspector.rs | 4 +- clippy_lints/src/utils/internal_lints.rs | 3 +- clippy_lints/src/utils/usage.rs | 9 ++-- 20 files changed, 80 insertions(+), 82 deletions(-) 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..6060d3e7b 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,15 @@ 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 +130,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 +144,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 +178,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/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..d66fcee97 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,7 @@ 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 +204,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..c8f557d33 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, @@ -2053,7 +2052,7 @@ 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 + 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/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 e9efac1cd..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; diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 40370506f..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); } }, 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/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/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 9d394a15b..fb7bb1f0d 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -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/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/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) {} }