Skip to content

Commit 9f98857

Browse files
committed
Propagate TraitImplHeader to hir
1 parent 7fe9a40 commit 9f98857

29 files changed

+64
-60
lines changed

clippy_lints/src/arbitrary_source_item_ordering.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ fn get_item_name(item: &Item<'_>) -> Option<String> {
534534

535535
if let Some(of_trait) = im.of_trait {
536536
let mut trait_segs: Vec<String> = of_trait
537+
.trait_ref
537538
.path
538539
.segments
539540
.iter()

clippy_lints/src/copy_iterator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ declare_lint_pass!(CopyIterator => [COPY_ITERATOR]);
3737
impl<'tcx> LateLintPass<'tcx> for CopyIterator {
3838
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
3939
if let ItemKind::Impl(Impl {
40-
of_trait: Some(trait_ref),
40+
of_trait: Some(of_trait),
4141
..
4242
}) = item.kind
4343
&& let ty = cx.tcx.type_of(item.owner_id).instantiate_identity()
4444
&& is_copy(cx, ty)
45-
&& let Some(trait_id) = trait_ref.trait_def_id()
45+
&& let Some(trait_id) = of_trait.trait_ref.trait_def_id()
4646
&& cx.tcx.is_diagnostic_item(sym::Iterator, trait_id)
4747
{
4848
span_lint_and_note(

clippy_lints/src/derivable_impls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,14 @@ fn check_enum<'tcx>(cx: &LateContext<'tcx>, item: &'tcx Item<'_>, func_expr: &Ex
183183
impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
184184
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
185185
if let ItemKind::Impl(Impl {
186-
of_trait: Some(trait_ref),
186+
of_trait: Some(of_trait),
187187
items: [child],
188188
self_ty,
189189
..
190190
}) = item.kind
191191
&& !cx.tcx.is_automatically_derived(item.owner_id.to_def_id())
192192
&& !item.span.from_expansion()
193-
&& let Some(def_id) = trait_ref.trait_def_id()
193+
&& let Some(def_id) = of_trait.trait_ref.trait_def_id()
194194
&& cx.tcx.is_diagnostic_item(sym::Default, def_id)
195195
&& let impl_item_hir = child.hir_id()
196196
&& let Node::ImplItem(impl_item) = cx.tcx.hir_node(impl_item_hir)

clippy_lints/src/derive.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,11 @@ declare_lint_pass!(Derive => [
201201
impl<'tcx> LateLintPass<'tcx> for Derive {
202202
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
203203
if let ItemKind::Impl(Impl {
204-
of_trait: Some(trait_ref),
204+
of_trait: Some(of_trait),
205205
..
206206
}) = item.kind
207207
{
208+
let trait_ref = &of_trait.trait_ref;
208209
let ty = cx.tcx.type_of(item.owner_id).instantiate_identity();
209210
let is_automatically_derived = cx.tcx.is_automatically_derived(item.owner_id.to_def_id());
210211

clippy_lints/src/empty_drop.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ declare_lint_pass!(EmptyDrop => [EMPTY_DROP]);
3636
impl LateLintPass<'_> for EmptyDrop {
3737
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
3838
if let ItemKind::Impl(Impl {
39-
of_trait: Some(trait_ref),
39+
of_trait: Some(of_trait),
4040
items: [child],
4141
..
4242
}) = item.kind
43-
&& trait_ref.trait_def_id() == cx.tcx.lang_items().drop_trait()
43+
&& of_trait.trait_ref.trait_def_id() == cx.tcx.lang_items().drop_trait()
4444
&& let impl_item_hir = child.hir_id()
4545
&& let Node::ImplItem(impl_item) = cx.tcx.hir_node(impl_item_hir)
4646
&& let ImplItemKind::Fn(_, b) = &impl_item.kind

clippy_lints/src/error_impl_error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl<'tcx> LateLintPass<'tcx> for ErrorImplError {
5252
);
5353
},
5454
ItemKind::Impl(imp)
55-
if let Some(trait_def_id) = imp.of_trait.and_then(|t| t.trait_def_id())
55+
if let Some(trait_def_id) = imp.of_trait.and_then(|t| t.trait_ref.trait_def_id())
5656
&& let Some(error_def_id) = cx.tcx.get_diagnostic_item(sym::Error)
5757
&& error_def_id == trait_def_id
5858
&& let Some(def_id) = path_res(cx, imp.self_ty).opt_def_id().and_then(DefId::as_local)

clippy_lints/src/format_impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,10 @@ fn is_format_trait_impl(cx: &LateContext<'_>, impl_item: &ImplItem<'_>) -> Optio
254254
if impl_item.ident.name == sym::fmt
255255
&& let ImplItemKind::Fn(_, body_id) = impl_item.kind
256256
&& let Some(Impl {
257-
of_trait: Some(trait_ref),
257+
of_trait: Some(of_trait),
258258
..
259259
}) = get_parent_as_impl(cx.tcx, impl_item.hir_id())
260-
&& let Some(did) = trait_ref.trait_def_id()
260+
&& let Some(did) = of_trait.trait_ref.trait_def_id()
261261
&& let Some(name) = cx.tcx.get_diagnostic_name(did)
262262
&& matches!(name, sym::Debug | sym::Display)
263263
{

clippy_lints/src/from_over_into.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ impl_lint_pass!(FromOverInto => [FROM_OVER_INTO]);
6767
impl<'tcx> LateLintPass<'tcx> for FromOverInto {
6868
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
6969
if let ItemKind::Impl(Impl {
70-
of_trait: Some(hir_trait_ref),
70+
of_trait: Some(of_trait),
7171
self_ty,
7272
items: [impl_item_ref],
7373
..
7474
}) = item.kind
75-
&& let Some(into_trait_seg) = hir_trait_ref.path.segments.last()
75+
&& let Some(into_trait_seg) = of_trait.trait_ref.path.segments.last()
7676
// `impl Into<target_ty> for self_ty`
7777
&& let Some(GenericArgs { args: [GenericArg::Type(target_ty)], .. }) = into_trait_seg.args
7878
&& span_is_local(item.span)

clippy_lints/src/functions/impl_trait_in_params.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ pub(super) fn check_impl_item(cx: &LateContext<'_>, impl_item: &ImplItem<'_>) {
5454
if let ImplItemKind::Fn(_, body_id) = impl_item.kind
5555
&& let hir::Node::Item(item) = cx.tcx.parent_hir_node(impl_item.hir_id())
5656
&& let hir::ItemKind::Impl(impl_) = item.kind
57-
&& let hir::Impl { of_trait, .. } = *impl_
58-
&& of_trait.is_none()
57+
&& let hir::Impl { of_trait: None, .. } = impl_
5958
&& let body = cx.tcx.hir_body(body_id)
6059
&& cx.tcx.visibility(cx.tcx.hir_body_owner_def_id(body.id())).is_public()
6160
&& !is_in_test(cx.tcx, impl_item.hir_id())

clippy_lints/src/functions/renamed_function_params.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ pub(super) fn check_impl_item(cx: &LateContext<'_>, item: &ImplItem<'_>, ignored
1515
&& let parent_node = cx.tcx.parent_hir_node(item.hir_id())
1616
&& let Node::Item(parent_item) = parent_node
1717
&& let ItemKind::Impl(Impl {
18-
of_trait: Some(trait_ref),
18+
of_trait: Some(of_trait),
1919
..
2020
}) = &parent_item.kind
2121
&& let Some(did) = trait_item_def_id_of_impl(cx, item.owner_id)
22-
&& !is_from_ignored_trait(trait_ref, ignored_traits)
22+
&& !is_from_ignored_trait(&of_trait.trait_ref, ignored_traits)
2323
{
2424
let mut param_idents_iter = cx.tcx.hir_body_param_idents(body_id);
2525
let mut default_param_idents_iter = cx.tcx.fn_arg_idents(did).iter().copied();

0 commit comments

Comments
 (0)