From dbe76094142c798138c7065e81ad2c77161767a8 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 30 Jan 2021 23:25:03 +0100 Subject: [PATCH] Only store a LocalDefId in hir::ImplItem. --- clippy_lints/src/doc.rs | 5 ++--- clippy_lints/src/fallible_impl_from.rs | 3 +-- clippy_lints/src/functions.rs | 10 +++++----- clippy_lints/src/inherent_to_string.rs | 7 +++---- clippy_lints/src/len_zero.rs | 9 +++------ clippy_lints/src/lifetimes.rs | 2 +- clippy_lints/src/methods/mod.rs | 9 ++++----- clippy_lints/src/missing_doc.rs | 5 ++--- clippy_lints/src/missing_inline.rs | 7 +++---- clippy_lints/src/mut_key.rs | 4 ++-- clippy_lints/src/new_without_default.rs | 2 +- clippy_lints/src/non_copy_const.rs | 2 +- clippy_lints/src/partialeq_ne_impl.rs | 2 +- clippy_lints/src/ptr.rs | 4 ++-- clippy_lints/src/unused_self.rs | 5 ++--- clippy_lints/src/unwrap_in_result.rs | 7 +++---- 16 files changed, 36 insertions(+), 47 deletions(-) diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 8a82b550b..67b7cf919 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -258,14 +258,13 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown { } if let hir::ImplItemKind::Fn(ref sig, body_id) = item.kind { let body = cx.tcx.hir().body(body_id); - let impl_item_def_id = cx.tcx.hir().local_def_id(item.hir_id); let mut fpu = FindPanicUnwrap { cx, - typeck_results: cx.tcx.typeck(impl_item_def_id), + typeck_results: cx.tcx.typeck(item.def_id), panic_span: None, }; fpu.visit_expr(&body.value); - lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, Some(body_id), fpu.panic_span); + lint_for_missing_headers(cx, item.hir_id(), item.span, sig, headers, Some(body_id), fpu.panic_span); } } } diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index 79828efc2..6d522c7ef 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -116,10 +116,9 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h 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.hir_id); let mut fpu = FindPanicUnwrap { lcx: cx, - typeck_results: cx.tcx.typeck(impl_item_def_id), + typeck_results: cx.tcx.typeck(impl_item.id.def_id), result: Vec::new(), }; fpu.visit_expr(&body.value); diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index eabc745a7..0c6bf8bbd 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -308,24 +308,24 @@ impl<'tcx> LateLintPass<'tcx> for Functions { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) { if let hir::ImplItemKind::Fn(ref sig, ref body_id) = item.kind { - 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 && trait_ref_of_method(cx, item.hir_id).is_none() { + if is_public && trait_ref_of_method(cx, item.hir_id()).is_none() { check_result_unit_err(cx, &sig.decl, item.span, fn_header_span); } 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); } else if is_public && !is_proc_macro(cx.sess(), &item.attrs) - && trait_ref_of_method(cx, item.hir_id).is_none() + && trait_ref_of_method(cx, item.hir_id()).is_none() { check_must_use_candidate( cx, &sig.decl, cx.tcx.hir().body(*body_id), 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/inherent_to_string.rs b/clippy_lints/src/inherent_to_string.rs index b723d06a6..76e7a4992 100644 --- a/clippy_lints/src/inherent_to_string.rs +++ b/clippy_lints/src/inherent_to_string.rs @@ -108,10 +108,10 @@ impl<'tcx> LateLintPass<'tcx> for InherentToString { if decl.inputs.len() == 1; // Check if return type is String - if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id), sym::string_type); + if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::string_type); // Filters instances of to_string which are required by a trait - if trait_ref_of_method(cx, impl_item.hir_id).is_none(); + if trait_ref_of_method(cx, impl_item.hir_id()).is_none(); then { show_lint(cx, impl_item); @@ -124,8 +124,7 @@ fn show_lint(cx: &LateContext<'_>, item: &ImplItem<'_>) { let display_trait_id = get_trait_def_id(cx, &paths::DISPLAY_TRAIT).expect("Failed to get trait ID of `Display`!"); // Get the real type of 'self' - let fn_def_id = cx.tcx.hir().local_def_id(item.hir_id); - let self_type = cx.tcx.fn_sig(fn_def_id).input(0); + let self_type = cx.tcx.fn_sig(item.def_id).input(0); let self_type = self_type.skip_binder().peel_refs(); // Emit either a warning or an error diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index a89941ceb..dab3e0565 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -206,17 +206,14 @@ fn check_impl_items(cx: &LateContext<'_>, item: &Item<'_>, impl_items: &[ImplIte fn is_named_self(cx: &LateContext<'_>, item: &ImplItemRef<'_>, 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 } } 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.hir_id) { + if cx.access_levels.is_exported(is_empty.id.hir_id()) { return; } "a private" @@ -225,7 +222,7 @@ 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.hir_id) { + if cx.access_levels.is_exported(i.id.hir_id()) { let ty = cx.tcx.type_of(item.def_id); span_lint( diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 05c747eee..50e638326 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -87,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for Lifetimes { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) { if let ImplItemKind::Fn(ref sig, id) = item.kind { - let report_extra_lifetimes = trait_ref_of_method(cx, item.hir_id).is_none(); + let report_extra_lifetimes = trait_ref_of_method(cx, item.hir_id()).is_none(); check_fn_inner( cx, &sig.decl, diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index a68775ffb..55660cc95 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1685,7 +1685,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { return; } let name = impl_item.ident.name.as_str(); - let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id); + let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()); let item = cx.tcx.hir().expect_item(parent); let self_ty = cx.tcx.type_of(item.def_id); @@ -1698,8 +1698,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if let hir::ImplItemKind::Fn(ref sig, id) = impl_item.kind; if let Some(first_arg) = iter_input_pats(&sig.decl, cx.tcx.hir().body(id)).next(); - let method_def_id = cx.tcx.hir().local_def_id(impl_item.hir_id); - let method_sig = cx.tcx.fn_sig(method_def_id); + let method_sig = cx.tcx.fn_sig(impl_item.def_id); let method_sig = cx.tcx.erase_late_bound_regions(method_sig); let first_arg_ty = &method_sig.inputs().iter().next(); @@ -1708,7 +1707,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if let Some(first_arg_ty) = first_arg_ty; then { - if cx.access_levels.is_exported(impl_item.hir_id) { + if cx.access_levels.is_exported(impl_item.hir_id()) { // check missing trait implementations for method_config in &TRAIT_METHODS { if name == method_config.method_name && @@ -1750,7 +1749,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { } if let hir::ImplItemKind::Fn(_, _) = impl_item.kind { - let ret_ty = return_ty(cx, impl_item.hir_id); + let ret_ty = return_ty(cx, impl_item.hir_id()); // walk the return type and check for Self (this does not check associated types) if contains_ty(ret_ty, self_ty) { diff --git a/clippy_lints/src/missing_doc.rs b/clippy_lints/src/missing_doc.rs index 5fce32293..761b92617 100644 --- a/clippy_lints/src/missing_doc.rs +++ b/clippy_lints/src/missing_doc.rs @@ -171,8 +171,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { fn check_impl_item(&mut self, cx: &LateContext<'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.hir_id); - match cx.tcx.associated_item(def_id).container { + match cx.tcx.associated_item(impl_item.def_id).container { ty::TraitContainer(_) => return, ty::ImplContainer(cid) => { if cx.tcx.impl_trait_ref(cid).is_some() { @@ -181,7 +180,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { }, } - let (article, desc) = cx.tcx.article_and_description(def_id.to_def_id()); + let (article, desc) = cx.tcx.article_and_description(impl_item.def_id.to_def_id()); self.check_missing_docs_attrs(cx, &impl_item.attrs, impl_item.span, article, desc); } diff --git a/clippy_lints/src/missing_inline.rs b/clippy_lints/src/missing_inline.rs index 5132bed59..47d7c5306 100644 --- a/clippy_lints/src/missing_inline.rs +++ b/clippy_lints/src/missing_inline.rs @@ -138,7 +138,7 @@ impl<'tcx> LateLintPass<'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.hir_id) { + if !cx.access_levels.is_exported(impl_item.hir_id()) { return; } @@ -147,14 +147,13 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { hir::ImplItemKind::Const(..) | hir::ImplItemKind::TyAlias(_) => return, }; - let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id); - let trait_def_id = match cx.tcx.associated_item(def_id).container { + let trait_def_id = match cx.tcx.associated_item(impl_item.def_id).container { TraitContainer(cid) => Some(cid), ImplContainer(cid) => cx.tcx.impl_trait_ref(cid).map(|t| t.def_id), }; if let Some(trait_def_id) = trait_def_id { - if trait_def_id.is_local() && !cx.access_levels.is_exported(impl_item.hir_id) { + if trait_def_id.is_local() && !cx.access_levels.is_exported(impl_item.hir_id()) { // If a trait is being implemented for an item, and the // trait is not exported, we don't need #[inline] return; diff --git a/clippy_lints/src/mut_key.rs b/clippy_lints/src/mut_key.rs index 16981946e..908b7bb7c 100644 --- a/clippy_lints/src/mut_key.rs +++ b/clippy_lints/src/mut_key.rs @@ -63,8 +63,8 @@ impl<'tcx> LateLintPass<'tcx> for MutableKeyType { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'tcx>) { if let hir::ImplItemKind::Fn(ref sig, ..) = item.kind { - if trait_ref_of_method(cx, item.hir_id).is_none() { - check_sig(cx, item.hir_id, &sig.decl); + if trait_ref_of_method(cx, item.hir_id()).is_none() { + check_sig(cx, item.hir_id(), &sig.decl); } } } diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index bd3dac663..de2899c34 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -72,7 +72,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { } if let hir::ImplItemKind::Fn(ref sig, _) = impl_item.kind { let name = impl_item.ident.name; - let id = impl_item.hir_id; + let id = impl_item.hir_id(); if sig.header.constness == hir::Constness::Const { // can't be implemented by default return; diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 0b2262d84..8aebce679 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -271,7 +271,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<'_>) { if let ImplItemKind::Const(hir_ty, body_id) = &impl_item.kind { - let item_hir_id = cx.tcx.hir().get_parent_node(impl_item.hir_id); + let item_hir_id = cx.tcx.hir().get_parent_node(impl_item.hir_id()); let item = cx.tcx.hir().expect_item(item_hir_id); match &item.kind { diff --git a/clippy_lints/src/partialeq_ne_impl.rs b/clippy_lints/src/partialeq_ne_impl.rs index ed314937c..3d6129aa7 100644 --- a/clippy_lints/src/partialeq_ne_impl.rs +++ b/clippy_lints/src/partialeq_ne_impl.rs @@ -44,7 +44,7 @@ impl<'tcx> LateLintPass<'tcx> for PartialEqNeImpl { span_lint_hir( cx, PARTIALEQ_NE_IMPL, - impl_item.id.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 ee4ad086e..de2fb8dec 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -130,13 +130,13 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) { if let ImplItemKind::Fn(ref sig, body_id) = item.kind { - let parent_item = cx.tcx.hir().get_parent_item(item.hir_id); + let parent_item = cx.tcx.hir().get_parent_item(item.hir_id()); if let Some(Node::Item(it)) = cx.tcx.hir().find(parent_item) { if let ItemKind::Impl(Impl { of_trait: Some(_), .. }) = it.kind { return; // ignore trait impls } } - check_fn(cx, &sig.decl, item.hir_id, Some(body_id)); + check_fn(cx, &sig.decl, item.hir_id(), Some(body_id)); } } diff --git a/clippy_lints/src/unused_self.rs b/clippy_lints/src/unused_self.rs index 5349c4f7e..73c64b808 100644 --- a/clippy_lints/src/unused_self.rs +++ b/clippy_lints/src/unused_self.rs @@ -44,10 +44,9 @@ impl<'tcx> LateLintPass<'tcx> for UnusedSelf { if impl_item.span.from_expansion() { return; } - let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id); + let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()); let parent_item = cx.tcx.hir().expect_item(parent); - let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id); - let assoc_item = cx.tcx.associated_item(def_id); + let assoc_item = cx.tcx.associated_item(impl_item.def_id); if_chain! { if let ItemKind::Impl(Impl { of_trait: None, .. }) = parent_item.kind; if assoc_item.fn_has_self_parameter; diff --git a/clippy_lints/src/unwrap_in_result.rs b/clippy_lints/src/unwrap_in_result.rs index fde310293..8cb742984 100644 --- a/clippy_lints/src/unwrap_in_result.rs +++ b/clippy_lints/src/unwrap_in_result.rs @@ -57,8 +57,8 @@ impl<'tcx> LateLintPass<'tcx> for UnwrapInResult { // first check if it's a method or function if let hir::ImplItemKind::Fn(ref _signature, _) = impl_item.kind; // checking if its return type is `result` or `option` - if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id), sym::result_type) - || is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id), sym::option_type); + if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::result_type) + || is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::option_type); then { lint_impl_body(cx, impl_item.span, impl_item); } @@ -114,10 +114,9 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_item: &'tc if let ImplItemKind::Fn(_, body_id) = impl_item.kind; then { let body = cx.tcx.hir().body(body_id); - let impl_item_def_id = cx.tcx.hir().local_def_id(impl_item.hir_id); let mut fpu = FindExpectUnwrap { lcx: cx, - typeck_results: cx.tcx.typeck(impl_item_def_id), + typeck_results: cx.tcx.typeck(impl_item.def_id), result: Vec::new(), }; fpu.visit_expr(&body.value);