Skip to content

Commit dfb41f4

Browse files
committed
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.
1 parent 9e45a23 commit dfb41f4

24 files changed

+61
-69
lines changed

clippy_lints/src/copy_iterator.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::utils::{is_copy, match_path, paths, span_lint_and_note};
2-
use rustc_hir::{Item, ItemKind};
2+
use rustc_hir::{Item, ItemKind, Impl};
33
use rustc_lint::{LateContext, LateLintPass};
44
use rustc_session::{declare_lint_pass, declare_tool_lint};
55

@@ -33,10 +33,10 @@ declare_lint_pass!(CopyIterator => [COPY_ITERATOR]);
3333

3434
impl<'tcx> LateLintPass<'tcx> for CopyIterator {
3535
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
36-
if let ItemKind::Impl {
36+
if let ItemKind::Impl(Impl {
3737
of_trait: Some(ref trait_ref),
3838
..
39-
} = item.kind
39+
}) = item.kind
4040
{
4141
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.hir_id));
4242

clippy_lints/src/derive.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use if_chain::if_chain;
77
use rustc_hir::def_id::DefId;
88
use rustc_hir::intravisit::{walk_expr, walk_fn, walk_item, FnKind, NestedVisitorMap, Visitor};
99
use rustc_hir::{
10-
BlockCheckMode, BodyId, Expr, ExprKind, FnDecl, HirId, Item, ItemKind, TraitRef, UnsafeSource, Unsafety,
10+
BlockCheckMode, BodyId, Expr, ExprKind, FnDecl, HirId, Item, ItemKind, Impl, TraitRef, UnsafeSource, Unsafety,
1111
};
1212
use rustc_lint::{LateContext, LateLintPass};
1313
use rustc_middle::hir::map::Map;
@@ -164,10 +164,10 @@ declare_lint_pass!(Derive => [
164164

165165
impl<'tcx> LateLintPass<'tcx> for Derive {
166166
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
167-
if let ItemKind::Impl {
167+
if let ItemKind::Impl(Impl {
168168
of_trait: Some(ref trait_ref),
169169
..
170-
} = item.kind
170+
}) = item.kind
171171
{
172172
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.hir_id));
173173
let is_automatically_derived = is_automatically_derived(&*item.attrs);

clippy_lints/src/doc.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,8 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
182182
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, Some(body_id));
183183
}
184184
},
185-
hir::ItemKind::Impl {
186-
of_trait: ref trait_ref,
187-
..
188-
} => {
189-
self.in_trait_impl = trait_ref.is_some();
185+
hir::ItemKind::Impl(ref impl_) => {
186+
self.in_trait_impl = impl_.of_trait.is_some();
190187
},
191188
_ => {},
192189
}

clippy_lints/src/escape.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc_hir::intravisit;
2-
use rustc_hir::{self, Body, FnDecl, HirId, HirIdSet, ItemKind, Node};
2+
use rustc_hir::{self, Body, FnDecl, HirId, HirIdSet, ItemKind, Impl, Node};
33
use rustc_infer::infer::TyCtxtInferExt;
44
use rustc_lint::{LateContext, LateLintPass};
55
use rustc_middle::ty::{self, Ty};
@@ -77,7 +77,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
7777
let parent_node = cx.tcx.hir().find(parent_id);
7878

7979
if let Some(Node::Item(item)) = parent_node {
80-
if let ItemKind::Impl { of_trait: Some(_), .. } = item.kind {
80+
if let ItemKind::Impl(Impl { of_trait: Some(_), .. }) = item.kind {
8181
return;
8282
}
8383
}

clippy_lints/src/fallible_impl_from.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom {
5757
// check for `impl From<???> for ..`
5858
let impl_def_id = cx.tcx.hir().local_def_id(item.hir_id);
5959
if_chain! {
60-
if let hir::ItemKind::Impl{ items: impl_items, .. } = item.kind;
60+
if let hir::ItemKind::Impl(impl_) = &item.kind;
6161
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_def_id);
6262
if match_def_path(cx, impl_trait_ref.def_id, &FROM_TRAIT);
6363
then {
64-
lint_impl_body(cx, item.span, impl_items);
64+
lint_impl_body(cx, item.span, impl_.items);
6565
}
6666
}
6767
}

clippy_lints/src/inherent_impl.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::utils::{in_macro, span_lint_and_then};
44
use rustc_data_structures::fx::FxHashMap;
5-
use rustc_hir::{def_id, Crate, Item, ItemKind};
5+
use rustc_hir::{def_id, Crate, Item, ItemKind, Impl};
66
use rustc_lint::{LateContext, LateLintPass};
77
use rustc_session::{declare_tool_lint, impl_lint_pass};
88
use rustc_span::Span;
@@ -49,11 +49,11 @@ impl_lint_pass!(MultipleInherentImpl => [MULTIPLE_INHERENT_IMPL]);
4949

5050
impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl {
5151
fn check_item(&mut self, _: &LateContext<'tcx>, item: &'tcx Item<'_>) {
52-
if let ItemKind::Impl {
52+
if let ItemKind::Impl(Impl {
5353
ref generics,
5454
of_trait: None,
5555
..
56-
} = item.kind
56+
}) = item.kind
5757
{
5858
// Remember for each inherent implementation encountered its span and generics
5959
// but filter out implementations that have generic params (type or lifetime)

clippy_lints/src/len_zero.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_ast::ast::LitKind;
33
use rustc_data_structures::fx::FxHashSet;
44
use rustc_errors::Applicability;
55
use rustc_hir::def_id::DefId;
6-
use rustc_hir::{AssocItemKind, BinOpKind, Expr, ExprKind, ImplItemRef, Item, ItemKind, TraitItemRef};
6+
use rustc_hir::{AssocItemKind, BinOpKind, Expr, ExprKind, ImplItemRef, Item, ItemKind, Impl, TraitItemRef};
77
use rustc_lint::{LateContext, LateLintPass};
88
use rustc_middle::ty;
99
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -115,11 +115,11 @@ impl<'tcx> LateLintPass<'tcx> for LenZero {
115115

116116
match item.kind {
117117
ItemKind::Trait(_, _, _, _, ref trait_items) => check_trait_items(cx, item, trait_items),
118-
ItemKind::Impl {
118+
ItemKind::Impl(Impl {
119119
of_trait: None,
120120
items: ref impl_items,
121121
..
122-
} => check_impl_items(cx, item, impl_items),
122+
}) => check_impl_items(cx, item, impl_items),
123123
_ => (),
124124
}
125125
}

clippy_lints/src/methods/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1626,7 +1626,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
16261626
let self_ty = cx.tcx.type_of(def_id);
16271627

16281628
// if this impl block implements a trait, lint in trait definition instead
1629-
if let hir::ItemKind::Impl { of_trait: Some(_), .. } = item.kind {
1629+
if let hir::ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) = item.kind {
16301630
return;
16311631
}
16321632

clippy_lints/src/needless_pass_by_value.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_ast::ast::Attribute;
88
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
99
use rustc_errors::{Applicability, DiagnosticBuilder};
1010
use rustc_hir::intravisit::FnKind;
11-
use rustc_hir::{BindingAnnotation, Body, FnDecl, GenericArg, HirId, ItemKind, Node, PatKind, QPath, TyKind};
11+
use rustc_hir::{BindingAnnotation, Body, FnDecl, GenericArg, HirId, ItemKind, Impl, Node, PatKind, QPath, TyKind};
1212
use rustc_infer::infer::TyCtxtInferExt;
1313
use rustc_lint::{LateContext, LateLintPass};
1414
use rustc_middle::ty::{self, TypeFoldable};
@@ -92,7 +92,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
9292
if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) {
9393
if matches!(
9494
item.kind,
95-
ItemKind::Impl { of_trait: Some(_), .. } | ItemKind::Trait(..)
95+
ItemKind::Impl(Impl { of_trait: Some(_), .. }) | ItemKind::Trait(..)
9696
) {
9797
return;
9898
}

clippy_lints/src/new_without_default.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ impl_lint_pass!(NewWithoutDefault => [NEW_WITHOUT_DEFAULT]);
6060
impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
6161
#[allow(clippy::too_many_lines)]
6262
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
63-
if let hir::ItemKind::Impl {
63+
if let hir::ItemKind::Impl(hir::Impl {
6464
of_trait: None, items, ..
65-
} = item.kind
65+
}) = item.kind
6666
{
6767
for assoc_item in items {
6868
if let hir::AssocItemKind::Fn { has_self: false } = assoc_item.kind {

0 commit comments

Comments
 (0)