From dfb41f47979cbda90100de67f2318b2a54243ed9 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 22 Nov 2020 17:46:21 -0500 Subject: [PATCH] Separate out a `hir::Impl` struct This makes it possible to pass the `Impl` directly to functions, instead of having to pass each of the many fields one at a time. It also simplifies matches in many cases. --- clippy_lints/src/copy_iterator.rs | 6 +++--- clippy_lints/src/derive.rs | 6 +++--- clippy_lints/src/doc.rs | 7 ++----- clippy_lints/src/escape.rs | 4 ++-- clippy_lints/src/fallible_impl_from.rs | 4 ++-- clippy_lints/src/inherent_impl.rs | 6 +++--- clippy_lints/src/len_zero.rs | 6 +++--- clippy_lints/src/methods/mod.rs | 2 +- clippy_lints/src/needless_pass_by_value.rs | 4 ++-- clippy_lints/src/new_without_default.rs | 4 ++-- clippy_lints/src/non_copy_const.rs | 8 ++++---- clippy_lints/src/partialeq_ne_impl.rs | 4 ++-- clippy_lints/src/pass_by_ref_or_value.rs | 4 ++-- clippy_lints/src/ptr.rs | 4 ++-- clippy_lints/src/serde_api.rs | 6 +++--- clippy_lints/src/to_string_in_display.rs | 4 ++-- clippy_lints/src/types.rs | 17 ++++++----------- clippy_lints/src/unnecessary_wraps.rs | 4 ++-- clippy_lints/src/unused_self.rs | 4 ++-- clippy_lints/src/use_self.rs | 8 ++++---- clippy_lints/src/utils/inspector.rs | 6 +++--- clippy_lints/src/utils/internal_lints.rs | 4 ++-- clippy_lints/src/utils/mod.rs | 6 +++--- clippy_lints/src/zero_sized_map_values.rs | 2 +- 24 files changed, 61 insertions(+), 69 deletions(-) diff --git a/clippy_lints/src/copy_iterator.rs b/clippy_lints/src/copy_iterator.rs index 349402453226..a7aa2cb35c1c 100644 --- a/clippy_lints/src/copy_iterator.rs +++ b/clippy_lints/src/copy_iterator.rs @@ -1,5 +1,5 @@ use crate::utils::{is_copy, match_path, paths, span_lint_and_note}; -use rustc_hir::{Item, ItemKind}; +use rustc_hir::{Item, ItemKind, Impl}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -33,10 +33,10 @@ declare_lint_pass!(CopyIterator => [COPY_ITERATOR]); impl<'tcx> LateLintPass<'tcx> for CopyIterator { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if let ItemKind::Impl { + if let ItemKind::Impl(Impl { of_trait: Some(ref trait_ref), .. - } = item.kind + }) = item.kind { let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.hir_id)); diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index c75efc6e99f8..b55f59f021df 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -7,7 +7,7 @@ use if_chain::if_chain; use rustc_hir::def_id::DefId; use rustc_hir::intravisit::{walk_expr, walk_fn, walk_item, FnKind, NestedVisitorMap, Visitor}; use rustc_hir::{ - BlockCheckMode, BodyId, Expr, ExprKind, FnDecl, HirId, Item, ItemKind, TraitRef, UnsafeSource, Unsafety, + BlockCheckMode, BodyId, Expr, ExprKind, FnDecl, HirId, Item, ItemKind, Impl, TraitRef, UnsafeSource, Unsafety, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::map::Map; @@ -164,10 +164,10 @@ declare_lint_pass!(Derive => [ impl<'tcx> LateLintPass<'tcx> for Derive { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if let ItemKind::Impl { + if let ItemKind::Impl(Impl { of_trait: Some(ref trait_ref), .. - } = item.kind + }) = item.kind { let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.hir_id)); let is_automatically_derived = is_automatically_derived(&*item.attrs); diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index aba655327959..f518da55cd76 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -182,11 +182,8 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown { lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, Some(body_id)); } }, - hir::ItemKind::Impl { - of_trait: ref trait_ref, - .. - } => { - self.in_trait_impl = trait_ref.is_some(); + hir::ItemKind::Impl(ref impl_) => { + self.in_trait_impl = impl_.of_trait.is_some(); }, _ => {}, } diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index d2dcb3e5c464..550876978129 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -1,5 +1,5 @@ use rustc_hir::intravisit; -use rustc_hir::{self, Body, FnDecl, HirId, HirIdSet, ItemKind, Node}; +use rustc_hir::{self, Body, FnDecl, HirId, HirIdSet, ItemKind, Impl, Node}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{self, Ty}; @@ -77,7 +77,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { let parent_node = cx.tcx.hir().find(parent_id); if let Some(Node::Item(item)) = parent_node { - if let ItemKind::Impl { of_trait: Some(_), .. } = item.kind { + if let ItemKind::Impl(Impl { of_trait: Some(_), .. }) = item.kind { return; } } diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index 509a4a4e15f6..9f389c8d2f9e 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -57,11 +57,11 @@ impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom { // check for `impl From for ..` let impl_def_id = cx.tcx.hir().local_def_id(item.hir_id); if_chain! { - if let hir::ItemKind::Impl{ items: impl_items, .. } = item.kind; + if let hir::ItemKind::Impl(impl_) = &item.kind; if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_def_id); if match_def_path(cx, impl_trait_ref.def_id, &FROM_TRAIT); then { - lint_impl_body(cx, item.span, impl_items); + lint_impl_body(cx, item.span, impl_.items); } } } diff --git a/clippy_lints/src/inherent_impl.rs b/clippy_lints/src/inherent_impl.rs index 4e6bb6047854..e287aecb044f 100644 --- a/clippy_lints/src/inherent_impl.rs +++ b/clippy_lints/src/inherent_impl.rs @@ -2,7 +2,7 @@ use crate::utils::{in_macro, span_lint_and_then}; use rustc_data_structures::fx::FxHashMap; -use rustc_hir::{def_id, Crate, Item, ItemKind}; +use rustc_hir::{def_id, Crate, Item, ItemKind, Impl}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::Span; @@ -49,11 +49,11 @@ impl_lint_pass!(MultipleInherentImpl => [MULTIPLE_INHERENT_IMPL]); impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl { fn check_item(&mut self, _: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if let ItemKind::Impl { + if let ItemKind::Impl(Impl { ref generics, of_trait: None, .. - } = item.kind + }) = item.kind { // Remember for each inherent implementation encountered its span and generics // but filter out implementations that have generic params (type or lifetime) diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index 6fe533510904..5474b30bdec8 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -3,7 +3,7 @@ use rustc_ast::ast::LitKind; use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use rustc_hir::def_id::DefId; -use rustc_hir::{AssocItemKind, BinOpKind, Expr, ExprKind, ImplItemRef, Item, ItemKind, TraitItemRef}; +use rustc_hir::{AssocItemKind, BinOpKind, Expr, ExprKind, ImplItemRef, Item, ItemKind, Impl, TraitItemRef}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -115,11 +115,11 @@ impl<'tcx> LateLintPass<'tcx> for LenZero { match item.kind { ItemKind::Trait(_, _, _, _, ref trait_items) => check_trait_items(cx, item, trait_items), - ItemKind::Impl { + ItemKind::Impl(Impl { of_trait: None, items: ref impl_items, .. - } => check_impl_items(cx, item, impl_items), + }) => check_impl_items(cx, item, impl_items), _ => (), } } diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index e99fe1b97ff6..2658c365e135 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1626,7 +1626,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { let self_ty = cx.tcx.type_of(def_id); // if this impl block implements a trait, lint in trait definition instead - if let hir::ItemKind::Impl { of_trait: Some(_), .. } = item.kind { + if let hir::ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) = item.kind { return; } diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 5043b7b1fc3c..a435f86bfd8d 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -8,7 +8,7 @@ use rustc_ast::ast::Attribute; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_hir::intravisit::FnKind; -use rustc_hir::{BindingAnnotation, Body, FnDecl, GenericArg, HirId, ItemKind, Node, PatKind, QPath, TyKind}; +use rustc_hir::{BindingAnnotation, Body, FnDecl, GenericArg, HirId, ItemKind, Impl, Node, PatKind, QPath, TyKind}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{self, TypeFoldable}; @@ -92,7 +92,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) { if matches!( item.kind, - ItemKind::Impl { of_trait: Some(_), .. } | ItemKind::Trait(..) + ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..) ) { return; } diff --git a/clippy_lints/src/new_without_default.rs b/clippy_lints/src/new_without_default.rs index 68fdd0eb269e..bd3dac663fe2 100644 --- a/clippy_lints/src/new_without_default.rs +++ b/clippy_lints/src/new_without_default.rs @@ -60,9 +60,9 @@ impl_lint_pass!(NewWithoutDefault => [NEW_WITHOUT_DEFAULT]); impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault { #[allow(clippy::too_many_lines)] fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) { - if let hir::ItemKind::Impl { + if let hir::ItemKind::Impl(hir::Impl { of_trait: None, items, .. - } = item.kind + }) = item.kind { for assoc_item in items { if let hir::AssocItemKind::Fn { has_self: false } = assoc_item.kind { diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 6b0d198edcff..3a9aa6ced03b 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -7,7 +7,7 @@ use std::ptr; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::{ - BodyId, Expr, ExprKind, HirId, ImplItem, ImplItemKind, Item, ItemKind, Node, TraitItem, TraitItemKind, UnOp, + BodyId, Expr, ExprKind, HirId, Impl, ImplItem, ImplItemKind, Item, ItemKind, Node, TraitItem, TraitItemKind, UnOp, }; use rustc_infer::traits::specialization_graph; use rustc_lint::{LateContext, LateLintPass, Lint}; @@ -275,10 +275,10 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst { let item = cx.tcx.hir().expect_item(item_hir_id); match &item.kind { - ItemKind::Impl { + ItemKind::Impl(Impl { of_trait: Some(of_trait_ref), .. - } => { + }) => { if_chain! { // Lint a trait impl item only when the definition is a generic type, // assuming a assoc const is not meant to be a interior mutable type. @@ -317,7 +317,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst { } } }, - ItemKind::Impl { of_trait: None, .. } => { + ItemKind::Impl(Impl { of_trait: None, .. }) => { let ty = hir_ty_to_ty(cx.tcx, hir_ty); // Normalize assoc types originated from generic params. let normalized = cx.tcx.normalize_erasing_regions(cx.param_env, ty); diff --git a/clippy_lints/src/partialeq_ne_impl.rs b/clippy_lints/src/partialeq_ne_impl.rs index ceecc8dbc06f..04b6e5d58478 100644 --- a/clippy_lints/src/partialeq_ne_impl.rs +++ b/clippy_lints/src/partialeq_ne_impl.rs @@ -1,6 +1,6 @@ use crate::utils::{is_automatically_derived, span_lint_hir}; use if_chain::if_chain; -use rustc_hir::{Item, ItemKind}; +use rustc_hir::{Item, ItemKind, Impl}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; @@ -34,7 +34,7 @@ declare_lint_pass!(PartialEqNeImpl => [PARTIALEQ_NE_IMPL]); impl<'tcx> LateLintPass<'tcx> for PartialEqNeImpl { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { if_chain! { - if let ItemKind::Impl{ of_trait: Some(ref trait_ref), items: impl_items, .. } = item.kind; + if let ItemKind::Impl(Impl { of_trait: Some(ref trait_ref), items: impl_items, .. }) = item.kind; if !is_automatically_derived(&*item.attrs); if let Some(eq_trait) = cx.tcx.lang_items().eq_trait(); if trait_ref.path.res.def_id() == eq_trait; diff --git a/clippy_lints/src/pass_by_ref_or_value.rs b/clippy_lints/src/pass_by_ref_or_value.rs index 6a17d654ac94..7814065e31a1 100644 --- a/clippy_lints/src/pass_by_ref_or_value.rs +++ b/clippy_lints/src/pass_by_ref_or_value.rs @@ -6,7 +6,7 @@ use rustc_ast::attr; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::intravisit::FnKind; -use rustc_hir::{BindingAnnotation, Body, FnDecl, HirId, ItemKind, MutTy, Mutability, Node, PatKind}; +use rustc_hir::{BindingAnnotation, Body, FnDecl, HirId, ItemKind, MutTy, Mutability, Node, PatKind, Impl}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; use rustc_session::{declare_tool_lint, impl_lint_pass}; @@ -246,7 +246,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue { if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) { if matches!( item.kind, - ItemKind::Impl { of_trait: Some(_), .. } | ItemKind::Trait(..) + ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..) ) { return; } diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index c494a7136313..b832add009f8 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -8,7 +8,7 @@ use crate::utils::{ use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{ - BinOpKind, BodyId, Expr, ExprKind, FnDecl, FnRetTy, GenericArg, HirId, ImplItem, ImplItemKind, Item, ItemKind, + BinOpKind, BodyId, Expr, ExprKind, FnDecl, FnRetTy, GenericArg, HirId, ImplItem, ImplItemKind, Item, ItemKind, Impl, Lifetime, MutTy, Mutability, Node, PathSegment, QPath, TraitFn, TraitItem, TraitItemKind, Ty, TyKind, }; use rustc_lint::{LateContext, LateLintPass}; @@ -132,7 +132,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { if let ImplItemKind::Fn(ref sig, body_id) = item.kind { 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 { of_trait: Some(_), .. } = it.kind { + if let ItemKind::Impl(Impl { of_trait: Some(_), .. }) = it.kind { return; // ignore trait impls } } diff --git a/clippy_lints/src/serde_api.rs b/clippy_lints/src/serde_api.rs index 339a7cf3bf5d..ca4fd9f35597 100644 --- a/clippy_lints/src/serde_api.rs +++ b/clippy_lints/src/serde_api.rs @@ -1,5 +1,5 @@ use crate::utils::{get_trait_def_id, paths, span_lint}; -use rustc_hir::{Item, ItemKind}; +use rustc_hir::{Item, ItemKind, Impl}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -22,11 +22,11 @@ declare_lint_pass!(SerdeAPI => [SERDE_API_MISUSE]); impl<'tcx> LateLintPass<'tcx> for SerdeAPI { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if let ItemKind::Impl { + if let ItemKind::Impl(Impl { of_trait: Some(ref trait_ref), items, .. - } = item.kind + }) = item.kind { let did = trait_ref.path.res.def_id(); if let Some(visit_did) = get_trait_def_id(cx, &paths::SERDE_DE_VISITOR) { diff --git a/clippy_lints/src/to_string_in_display.rs b/clippy_lints/src/to_string_in_display.rs index 006d7a3a12d9..675eaf4277a4 100644 --- a/clippy_lints/src/to_string_in_display.rs +++ b/clippy_lints/src/to_string_in_display.rs @@ -1,7 +1,7 @@ use crate::utils::{match_def_path, match_trait_method, paths, qpath_res, span_lint}; use if_chain::if_chain; use rustc_hir::def::Res; -use rustc_hir::{Expr, ExprKind, HirId, ImplItem, ImplItemKind, Item, ItemKind}; +use rustc_hir::{Expr, ExprKind, HirId, ImplItem, ImplItemKind, Item, ItemKind, Impl}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; @@ -111,7 +111,7 @@ impl LateLintPass<'_> for ToStringInDisplay { fn is_display_impl(cx: &LateContext<'_>, item: &Item<'_>) -> bool { if_chain! { - if let ItemKind::Impl { of_trait: Some(trait_ref), .. } = &item.kind; + if let ItemKind::Impl(Impl { of_trait: Some(trait_ref), .. }) = &item.kind; if let Some(did) = trait_ref.trait_def_id(); then { match_def_path(cx, did, &paths::DISPLAY_TRAIT) diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index fd74783335d5..2696c5e781ab 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -258,7 +258,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { fn check_fn(&mut self, cx: &LateContext<'_>, _: FnKind<'_>, decl: &FnDecl<'_>, _: &Body<'_>, _: Span, id: HirId) { // Skip trait implementations; see issue #605. if let Some(hir::Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_item(id)) { - if let ItemKind::Impl { of_trait: Some(_), .. } = item.kind { + if let ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) = item.kind { return; } } @@ -2558,21 +2558,16 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher { } match item.kind { - ItemKind::Impl { - ref generics, - self_ty: ref ty, - ref items, - .. - } => { + ItemKind::Impl(ref impl_) => { let mut vis = ImplicitHasherTypeVisitor::new(cx); - vis.visit_ty(ty); + vis.visit_ty(impl_.self_ty); for target in &vis.found { if differing_macro_contexts(item.span, target.span()) { return; } - let generics_suggestion_span = generics.span.substitute_dummy({ + let generics_suggestion_span = impl_.generics.span.substitute_dummy({ let pos = snippet_opt(cx, item.span.until(target.span())) .and_then(|snip| Some(item.span.lo() + BytePos(snip.find("impl")? as u32 + 4))); if let Some(pos) = pos { @@ -2583,7 +2578,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher { }); let mut ctr_vis = ImplicitHasherConstructorVisitor::new(cx, target); - for item in items.iter().map(|item| cx.tcx.hir().impl_item(item.id)) { + for item in impl_.items.iter().map(|item| cx.tcx.hir().impl_item(item.id)) { ctr_vis.visit_impl_item(item); } @@ -2596,7 +2591,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher { target.type_name() ), move |diag| { - suggestion(cx, diag, generics.span, generics_suggestion_span, target, ctr_vis); + suggestion(cx, diag, impl_.generics.span, generics_suggestion_span, target, ctr_vis); }, ); } diff --git a/clippy_lints/src/unnecessary_wraps.rs b/clippy_lints/src/unnecessary_wraps.rs index 5b9a80f92db6..07cd752184bb 100644 --- a/clippy_lints/src/unnecessary_wraps.rs +++ b/clippy_lints/src/unnecessary_wraps.rs @@ -5,7 +5,7 @@ use crate::utils::{ use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::intravisit::FnKind; -use rustc_hir::{Body, ExprKind, FnDecl, HirId, ItemKind, Node}; +use rustc_hir::{Body, ExprKind, FnDecl, HirId, ItemKind, Impl, Node}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::subst::GenericArgKind; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -77,7 +77,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps { if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) { if matches!( item.kind, - ItemKind::Impl { of_trait: Some(_), .. } | ItemKind::Trait(..) + ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..) ) { return; } diff --git a/clippy_lints/src/unused_self.rs b/clippy_lints/src/unused_self.rs index da7517125c13..a61717943110 100644 --- a/clippy_lints/src/unused_self.rs +++ b/clippy_lints/src/unused_self.rs @@ -1,7 +1,7 @@ use if_chain::if_chain; use rustc_hir::def::Res; use rustc_hir::intravisit::{walk_path, NestedVisitorMap, Visitor}; -use rustc_hir::{HirId, ImplItem, ImplItemKind, ItemKind, Path}; +use rustc_hir::{HirId, ImplItem, ImplItemKind, ItemKind, Impl, Path}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::map::Map; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -49,7 +49,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedSelf { let def_id = cx.tcx.hir().local_def_id(impl_item.hir_id); let assoc_item = cx.tcx.associated_item(def_id); if_chain! { - if let ItemKind::Impl { of_trait: None, .. } = parent_item.kind; + if let ItemKind::Impl(Impl { of_trait: None, .. }) = parent_item.kind; if assoc_item.fn_has_self_parameter; if let ImplItemKind::Fn(.., body_id) = &impl_item.kind; let body = cx.tcx.hir().body(*body_id); diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 3b23f885e08d..b82ea66190fc 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -181,8 +181,8 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { return; } if_chain! { - if let ItemKind::Impl{ self_ty: ref item_type, items: refs, .. } = item.kind; - if let TyKind::Path(QPath::Resolved(_, ref item_path)) = item_type.kind; + if let ItemKind::Impl(impl_) = &item.kind; + if let TyKind::Path(QPath::Resolved(_, ref item_path)) = impl_.self_ty.kind; then { let parameters = &item_path.segments.last().expect(SEGMENTS_MSG).args; let should_check = parameters.as_ref().map_or( @@ -200,7 +200,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { let impl_trait_ref = cx.tcx.impl_trait_ref(impl_def_id); if let Some(impl_trait_ref) = impl_trait_ref { - for impl_item_ref in refs { + for impl_item_ref in impl_.items { let impl_item = cx.tcx.hir().impl_item(impl_item_ref.id); if let ImplItemKind::Fn(FnSig{ decl: impl_decl, .. }, impl_body_id) = &impl_item.kind { @@ -213,7 +213,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { } } } else { - for impl_item_ref in refs { + for impl_item_ref in impl_.items { let impl_item = cx.tcx.hir().impl_item(impl_item_ref.id); visitor.visit_impl_item(impl_item); } diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index 5d946e4bd495..a02c0a3f44d7 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -423,13 +423,13 @@ fn print_item(cx: &LateContext<'_>, item: &hir::Item<'_>) { hir::ItemKind::TraitAlias(..) => { println!("trait alias"); }, - hir::ItemKind::Impl { + hir::ItemKind::Impl(hir::Impl { of_trait: Some(ref _trait_ref), .. - } => { + }) => { println!("trait impl"); }, - hir::ItemKind::Impl { of_trait: None, .. } => { + hir::ItemKind::Impl(hir::Impl { of_trait: None, .. }) => { println!("impl"); }, } diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index 9ba39f73ee88..407f06f48942 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -352,11 +352,11 @@ impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass { } else if is_expn_of(item.span, "impl_lint_pass").is_some() || is_expn_of(item.span, "declare_lint_pass").is_some() { - if let hir::ItemKind::Impl { + if let hir::ItemKind::Impl(hir::Impl { of_trait: None, items: ref impl_item_refs, .. - } = item.kind + }) = item.kind { let mut collector = LintCollector { output: &mut self.registered_lints, diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 1c68e837c4ab..87f99019d72d 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -439,8 +439,8 @@ pub fn trait_ref_of_method<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Optio if_chain! { if parent_impl != hir::CRATE_HIR_ID; if let hir::Node::Item(item) = cx.tcx.hir().get(parent_impl); - if let hir::ItemKind::Impl{ of_trait: trait_ref, .. } = &item.kind; - then { return trait_ref.as_ref(); } + if let hir::ItemKind::Impl(impl_) = &item.kind; + then { return impl_.of_trait.as_ref(); } } None } @@ -1530,7 +1530,7 @@ pub fn is_no_std_crate(krate: &Crate<'_>) -> bool { /// ``` pub fn is_trait_impl_item(cx: &LateContext<'_>, hir_id: HirId) -> bool { if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) { - matches!(item.kind, ItemKind::Impl { of_trait: Some(_), .. }) + matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. })) } else { false } diff --git a/clippy_lints/src/zero_sized_map_values.rs b/clippy_lints/src/zero_sized_map_values.rs index 1d5fa8d06a99..9761e822a7a0 100644 --- a/clippy_lints/src/zero_sized_map_values.rs +++ b/clippy_lints/src/zero_sized_map_values.rs @@ -62,7 +62,7 @@ impl LateLintPass<'_> for ZeroSizedMapValues { fn in_trait_impl(cx: &LateContext<'_>, hir_id: HirId) -> bool { let parent_id = cx.tcx.hir().get_parent_item(hir_id); if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_item(parent_id)) { - if let ItemKind::Impl { of_trait: Some(_), .. } = item.kind { + if let ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) = item.kind { return true; } }