From 90fcc67d32afd73d28aaf965e152dbe478ea9024 Mon Sep 17 00:00:00 2001 From: mojave2 Date: Fri, 25 Aug 2023 19:15:44 +0800 Subject: [PATCH] fix "derivable_impls: attributes are ignored" --- clippy_lints/src/derivable_impls.rs | 3 +-- tests/ui/derivable_impls.fixed | 13 +++++++++++++ tests/ui/derivable_impls.rs | 13 +++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/derivable_impls.rs b/clippy_lints/src/derivable_impls.rs index 9a85cc4ce2d..d2bfc4f8e27 100644 --- a/clippy_lints/src/derivable_impls.rs +++ b/clippy_lints/src/derivable_impls.rs @@ -217,8 +217,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { if let &Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind(); if let attrs = cx.tcx.hir().attrs(item.hir_id()); if !attrs.iter().any(|attr| attr.doc_str().is_some()); - if let child_attrs = cx.tcx.hir().attrs(impl_item_hir); - if !child_attrs.iter().any(|attr| attr.doc_str().is_some()); + if cx.tcx.hir().attrs(impl_item_hir).is_empty(); then { if adt_def.is_struct() { diff --git a/tests/ui/derivable_impls.fixed b/tests/ui/derivable_impls.fixed index 6cc202414f5..68c5a5c5ca4 100644 --- a/tests/ui/derivable_impls.fixed +++ b/tests/ui/derivable_impls.fixed @@ -287,4 +287,17 @@ mod issue10158 { } } +mod issue11368 { + pub struct A { + a: u32, + } + + impl Default for A { + #[track_caller] + fn default() -> Self { + Self { a: 0 } + } + } +} + fn main() {} diff --git a/tests/ui/derivable_impls.rs b/tests/ui/derivable_impls.rs index 0aa9acd752d..21d73ba8b77 100644 --- a/tests/ui/derivable_impls.rs +++ b/tests/ui/derivable_impls.rs @@ -323,4 +323,17 @@ fn default() -> Self { } } +mod issue11368 { + pub struct A { + a: u32, + } + + impl Default for A { + #[track_caller] + fn default() -> Self { + Self { a: 0 } + } + } +} + fn main() {}