From fc9bc33bbaa595cdfe3e5e5cd37cd96186fc52eb Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 30 Jan 2021 20:46:50 +0100 Subject: [PATCH] Only store a LocalDefId in hir::TraitItem. --- clippy_lints/src/doc.rs | 2 +- clippy_lints/src/escape.rs | 4 ++-- clippy_lints/src/functions.rs | 8 ++++---- clippy_lints/src/len_zero.rs | 5 +---- clippy_lints/src/methods/mod.rs | 6 +++--- clippy_lints/src/missing_doc.rs | 3 +-- clippy_lints/src/mut_key.rs | 2 +- clippy_lints/src/pass_by_ref_or_value.rs | 2 +- clippy_lints/src/ptr.rs | 2 +- 9 files changed, 15 insertions(+), 19 deletions(-) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index c12448588..8a82b550b 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -246,7 +246,7 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown { let headers = check_attrs(cx, &self.valid_idents, &item.attrs); if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind { if !in_external_macro(cx.tcx.sess, item.span) { - lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, None, None); + lint_for_missing_headers(cx, item.hir_id(), item.span, sig, headers, None, None); } } } diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 40e93da8d..f8ef2a464 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -87,11 +87,11 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { // find `self` ty for this trait if relevant if let ItemKind::Trait(_, _, _, _, items) = item.kind { for trait_item in items { - if trait_item.id.hir_id == hir_id { + if trait_item.id.hir_id() == hir_id { // be sure we have `self` parameter in this function if let AssocItemKind::Fn { has_self: true } = trait_item.kind { trait_self_ty = - Some(TraitRef::identity(cx.tcx, trait_item.id.hir_id.owner.to_def_id()).self_ty()); + Some(TraitRef::identity(cx.tcx, trait_item.id.def_id.to_def_id()).self_ty()); } } } diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index 28d025315..eabc745a7 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -339,7 +339,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions { if sig.header.abi == Abi::Rust { self.check_arg_number(cx, &sig.decl, item.span.with_hi(sig.decl.output.span().hi())); } - let is_public = cx.access_levels.is_exported(item.hir_id); + let is_public = cx.access_levels.is_exported(item.hir_id()); let fn_header_span = item.span.with_hi(sig.decl.output.span().hi()); if is_public { check_result_unit_err(cx, &sig.decl, item.span, fn_header_span); @@ -347,11 +347,11 @@ impl<'tcx> LateLintPass<'tcx> for Functions { let attr = must_use_attr(&item.attrs); if let Some(attr) = attr { - check_needless_must_use(cx, &sig.decl, item.hir_id, item.span, fn_header_span, attr); + check_needless_must_use(cx, &sig.decl, item.hir_id(), item.span, fn_header_span, attr); } if let hir::TraitFn::Provided(eid) = *eid { let body = cx.tcx.hir().body(eid); - Self::check_raw_ptr(cx, sig.header.unsafety, &sig.decl, body, item.hir_id); + Self::check_raw_ptr(cx, sig.header.unsafety, &sig.decl, body, item.hir_id()); if attr.is_none() && is_public && !is_proc_macro(cx.sess(), &item.attrs) { check_must_use_candidate( @@ -359,7 +359,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions { &sig.decl, body, item.span, - item.hir_id, + item.hir_id(), item.span.with_hi(sig.decl.output.span().hi()), "this method could have a `#[must_use]` attribute", ); diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 8706cf7f0..a89941ceb 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -159,10 +159,7 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items fn is_named_self(cx: &LateContext<'_>, item: &TraitItemRef, name: &str) -> bool { item.ident.name.as_str() == name && if let AssocItemKind::Fn { has_self } = item.kind { - has_self && { - let did = cx.tcx.hir().local_def_id(item.id.hir_id); - cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1 - } + has_self && { cx.tcx.fn_sig(item.id.def_id).inputs().skip_binder().len() == 1 } } else { false } diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index a2104b48b..a68775ffb 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1791,7 +1791,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if let Some(first_arg_ty) = sig.decl.inputs.iter().next(); let first_arg_span = first_arg_ty.span; let first_arg_ty = hir_ty_to_ty(cx.tcx, first_arg_ty); - let self_ty = TraitRef::identity(cx.tcx, item.hir_id.owner.to_def_id()).self_ty(); + let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id()).self_ty(); then { lint_wrong_self_convention(cx, &item.ident.name.as_str(), false, self_ty, first_arg_ty, first_arg_span); @@ -1801,8 +1801,8 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if_chain! { if item.ident.name == sym::new; if let TraitItemKind::Fn(_, _) = item.kind; - let ret_ty = return_ty(cx, item.hir_id); - let self_ty = TraitRef::identity(cx.tcx, item.hir_id.owner.to_def_id()).self_ty(); + let ret_ty = return_ty(cx, item.hir_id()); + let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id()).self_ty(); if !contains_ty(ret_ty, self_ty); then { diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 21b59fba9..5fce32293 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -164,8 +164,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { } fn check_trait_item(&mut self, cx: &LateContext<'tcx>, trait_item: &'tcx hir::TraitItem<'_>) { - let def_id = cx.tcx.hir().local_def_id(trait_item.hir_id); - let (article, desc) = cx.tcx.article_and_description(def_id.to_def_id()); + let (article, desc) = cx.tcx.article_and_description(trait_item.def_id.to_def_id()); self.check_missing_docs_attrs(cx, &trait_item.attrs, trait_item.span, article, desc); } diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 7b9205a99..16981946e 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -71,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for MutableKeyType { fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'tcx>) { if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind { - check_sig(cx, item.hir_id, &sig.decl); + check_sig(cx, item.hir_id(), &sig.decl); } } diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index d96a9b025..b9ba32001 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -206,7 +206,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue { } if let hir::TraitItemKind::Fn(method_sig, _) = &item.kind { - self.check_poly_fn(cx, item.hir_id, &*method_sig.decl, None); + self.check_poly_fn(cx, item.hir_id(), &*method_sig.decl, None); } } diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 9efeac3d8..ee4ad086e 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -147,7 +147,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { } else { None }; - check_fn(cx, &sig.decl, item.hir_id, body_id); + check_fn(cx, &sig.decl, item.hir_id(), body_id); } }