Skip to content

Commit eee7c58

Browse files
authored
use is_automatically_derived() instead of has_attr() (rust-lang#14506)
`has_attr(def_id, sym::automatically_derived)` is as same as `is_automatically_derived(def_id)`. changelog: none
2 parents 4f58673 + 2eee361 commit eee7c58

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

clippy_lints/src/derivable_impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
188188
self_ty,
189189
..
190190
}) = item.kind
191-
&& !cx.tcx.has_attr(item.owner_id, sym::automatically_derived)
191+
&& !cx.tcx.is_automatically_derived(item.owner_id.to_def_id())
192192
&& !item.span.from_expansion()
193193
&& let Some(def_id) = trait_ref.trait_def_id()
194194
&& cx.tcx.is_diagnostic_item(sym::Default, def_id)

clippy_lints/src/derive.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl<'tcx> LateLintPass<'tcx> for Derive {
206206
}) = item.kind
207207
{
208208
let ty = cx.tcx.type_of(item.owner_id).instantiate_identity();
209-
let is_automatically_derived = cx.tcx.has_attr(item.owner_id, sym::automatically_derived);
209+
let is_automatically_derived = cx.tcx.is_automatically_derived(item.owner_id.to_def_id());
210210

211211
check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived);
212212
check_ord_partial_ord(cx, item.span, trait_ref, ty, is_automatically_derived);
@@ -235,7 +235,7 @@ fn check_hash_peq<'tcx>(
235235
{
236236
// Look for the PartialEq implementations for `ty`
237237
cx.tcx.for_each_relevant_impl(peq_trait_def_id, ty, |impl_id| {
238-
let peq_is_automatically_derived = cx.tcx.has_attr(impl_id, sym::automatically_derived);
238+
let peq_is_automatically_derived = cx.tcx.is_automatically_derived(impl_id);
239239

240240
if !hash_is_automatically_derived || peq_is_automatically_derived {
241241
return;
@@ -278,7 +278,7 @@ fn check_ord_partial_ord<'tcx>(
278278
{
279279
// Look for the PartialOrd implementations for `ty`
280280
cx.tcx.for_each_relevant_impl(partial_ord_trait_def_id, ty, |impl_id| {
281-
let partial_ord_is_automatically_derived = cx.tcx.has_attr(impl_id, sym::automatically_derived);
281+
let partial_ord_is_automatically_derived = cx.tcx.is_automatically_derived(impl_id);
282282

283283
if partial_ord_is_automatically_derived == ord_is_automatically_derived {
284284
return;

clippy_lints/src/missing_fields_in_debug.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingFieldsInDebug {
209209
&& let Res::Def(DefKind::Struct | DefKind::Enum | DefKind::Union, self_path_did) = self_path.res
210210
&& cx.tcx.is_diagnostic_item(sym::Debug, trait_def_id)
211211
// don't trigger if this impl was derived
212-
&& !cx.tcx.has_attr(item.owner_id, sym::automatically_derived)
212+
&& !cx.tcx.is_automatically_derived(item.owner_id.to_def_id())
213213
&& !item.span.from_expansion()
214214
// find `Debug::fmt` function
215215
&& let Some(fmt_item) = items.iter().find(|i| i.ident.name == sym::fmt)

clippy_lints/src/partialeq_ne_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl<'tcx> LateLintPass<'tcx> for PartialEqNeImpl {
3838
items: impl_items,
3939
..
4040
}) = item.kind
41-
&& !cx.tcx.has_attr(item.owner_id, sym::automatically_derived)
41+
&& !cx.tcx.is_automatically_derived(item.owner_id.to_def_id())
4242
&& let Some(eq_trait) = cx.tcx.lang_items().eq_trait()
4343
&& trait_ref.path.res.def_id() == eq_trait
4444
{

clippy_lints/src/unconditional_recursion.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ fn get_impl_trait_def_id(cx: &LateContext<'_>, method_def_id: LocalDefId) -> Opt
135135
}),
136136
)) = cx.tcx.hir_parent_iter(hir_id).next()
137137
// We exclude `impl` blocks generated from rustc's proc macros.
138-
&& !cx.tcx.has_attr(*owner_id, sym::automatically_derived)
138+
&& !cx.tcx.is_automatically_derived(owner_id.to_def_id())
139139
// It is a implementation of a trait.
140140
&& let Some(trait_) = impl_.of_trait
141141
{
@@ -240,7 +240,7 @@ fn check_to_string(cx: &LateContext<'_>, method_span: Span, method_def_id: Local
240240
}),
241241
)) = cx.tcx.hir_parent_iter(hir_id).next()
242242
// We exclude `impl` blocks generated from rustc's proc macros.
243-
&& !cx.tcx.has_attr(*owner_id, sym::automatically_derived)
243+
&& !cx.tcx.is_automatically_derived(owner_id.to_def_id())
244244
// It is a implementation of a trait.
245245
&& let Some(trait_) = impl_.of_trait
246246
&& let Some(trait_def_id) = trait_.trait_def_id()
@@ -337,7 +337,7 @@ impl UnconditionalRecursion {
337337
for (ty, impl_def_ids) in impls.non_blanket_impls() {
338338
let Some(self_def_id) = ty.def() else { continue };
339339
for impl_def_id in impl_def_ids {
340-
if !cx.tcx.has_attr(*impl_def_id, sym::automatically_derived) &&
340+
if !cx.tcx.is_automatically_derived(*impl_def_id) &&
341341
let Some(assoc_item) = cx
342342
.tcx
343343
.associated_items(impl_def_id)

0 commit comments

Comments
 (0)