Skip to content

Commit 3c6eee2

Browse files
committed
Auto merge of #144377 - camsteffen:simplify-impl-of-method, r=fee1-dead
Rename impl_of_method and trait_of_item This PR used to tweak the implementation of impl_of_method, but that introduced a perf regression. Rename impl_of_method and trait_of_item to impl_of_assoc and trait_of_assoc respectively. This reflects how the two functions are closely related. And it reflects the behavior more accurately as the functions check whether the input is an associated item.
2 parents 466408e + 5cd0ed9 commit 3c6eee2

36 files changed

+51
-51
lines changed

clippy_lints/src/assigning_clones.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for AssigningClones {
9898
// That is overly conservative - the lint should fire even if there was no initializer,
9999
// but the variable has been initialized before `lhs` was evaluated.
100100
&& path_to_local(lhs).is_none_or(|lhs| local_is_initialized(cx, lhs))
101-
&& let Some(resolved_impl) = cx.tcx.impl_of_method(resolved_fn.def_id())
101+
&& let Some(resolved_impl) = cx.tcx.impl_of_assoc(resolved_fn.def_id())
102102
// Derived forms don't implement `clone_from`/`clone_into`.
103103
// See https://github.com/rust-lang/rust/pull/98445#issuecomment-1190681305
104104
&& !cx.tcx.is_builtin_derived(resolved_impl)

clippy_lints/src/casts/cast_ptr_alignment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn is_used_as_unaligned(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
6363
ExprKind::MethodCall(name, self_arg, ..) if self_arg.hir_id == e.hir_id => {
6464
if matches!(name.ident.name, sym::read_unaligned | sym::write_unaligned)
6565
&& let Some(def_id) = cx.typeck_results().type_dependent_def_id(parent.hir_id)
66-
&& let Some(def_id) = cx.tcx.impl_of_method(def_id)
66+
&& let Some(def_id) = cx.tcx.impl_of_assoc(def_id)
6767
&& cx.tcx.type_of(def_id).instantiate_identity().is_raw_ptr()
6868
{
6969
true

clippy_lints/src/casts/confusing_method_to_numeric_cast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn get_const_name_and_ty_name(
3737
} else {
3838
return None;
3939
}
40-
} else if let Some(impl_id) = cx.tcx.impl_of_method(method_def_id)
40+
} else if let Some(impl_id) = cx.tcx.impl_of_assoc(method_def_id)
4141
&& let Some(ty_name) = get_primitive_ty_name(cx.tcx.type_of(impl_id).instantiate_identity())
4242
&& matches!(
4343
method_name,

clippy_lints/src/dereference.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
364364
// * `&self` methods on `&T` can have auto-borrow, but `&self` methods on `T` will take
365365
// priority.
366366
if let Some(fn_id) = typeck.type_dependent_def_id(hir_id)
367-
&& let Some(trait_id) = cx.tcx.trait_of_item(fn_id)
367+
&& let Some(trait_id) = cx.tcx.trait_of_assoc(fn_id)
368368
&& let arg_ty = cx.tcx.erase_regions(adjusted_ty)
369369
&& let ty::Ref(_, sub_ty, _) = *arg_ty.kind()
370370
&& let args =

clippy_lints/src/implicit_saturating_sub.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ fn check_with_condition<'tcx>(
339339
ExprKind::Path(QPath::TypeRelative(_, name)) => {
340340
if name.ident.name == sym::MIN
341341
&& let Some(const_id) = cx.typeck_results().type_dependent_def_id(cond_num_val.hir_id)
342-
&& let Some(impl_id) = cx.tcx.impl_of_method(const_id)
342+
&& let Some(impl_id) = cx.tcx.impl_of_assoc(const_id)
343343
&& let None = cx.tcx.impl_trait_ref(impl_id) // An inherent impl
344344
&& cx.tcx.type_of(impl_id).instantiate_identity().is_integral()
345345
{
@@ -350,7 +350,7 @@ fn check_with_condition<'tcx>(
350350
if let ExprKind::Path(QPath::TypeRelative(_, name)) = func.kind
351351
&& name.ident.name == sym::min_value
352352
&& let Some(func_id) = cx.typeck_results().type_dependent_def_id(func.hir_id)
353-
&& let Some(impl_id) = cx.tcx.impl_of_method(func_id)
353+
&& let Some(impl_id) = cx.tcx.impl_of_assoc(func_id)
354354
&& let None = cx.tcx.impl_trait_ref(impl_id) // An inherent impl
355355
&& cx.tcx.type_of(impl_id).instantiate_identity().is_integral()
356356
{

clippy_lints/src/loops/needless_range_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ impl<'tcx> Visitor<'tcx> for VarVisitor<'_, 'tcx> {
317317
.cx
318318
.typeck_results()
319319
.type_dependent_def_id(expr.hir_id)
320-
.and_then(|def_id| self.cx.tcx.trait_of_item(def_id))
320+
.and_then(|def_id| self.cx.tcx.trait_of_assoc(def_id))
321321
&& ((meth.ident.name == sym::index && self.cx.tcx.lang_items().index_trait() == Some(trait_id))
322322
|| (meth.ident.name == sym::index_mut && self.cx.tcx.lang_items().index_mut_trait() == Some(trait_id)))
323323
&& !self.check(args_1, args_0, expr)

clippy_lints/src/methods/bytes_count_to_len.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub(super) fn check<'tcx>(
1414
bytes_recv: &'tcx hir::Expr<'_>,
1515
) {
1616
if let Some(bytes_id) = cx.typeck_results().type_dependent_def_id(count_recv.hir_id)
17-
&& let Some(impl_id) = cx.tcx.impl_of_method(bytes_id)
17+
&& let Some(impl_id) = cx.tcx.impl_of_assoc(bytes_id)
1818
&& cx.tcx.type_of(impl_id).instantiate_identity().is_str()
1919
&& let ty = cx.typeck_results().expr_ty(bytes_recv).peel_refs()
2020
&& (ty.is_str() || is_type_lang_item(cx, ty, hir::LangItem::String))

clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub(super) fn check<'tcx>(
3030
}
3131

3232
if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
33-
&& let Some(impl_id) = cx.tcx.impl_of_method(method_id)
33+
&& let Some(impl_id) = cx.tcx.impl_of_assoc(method_id)
3434
&& cx.tcx.type_of(impl_id).instantiate_identity().is_str()
3535
&& let ExprKind::Lit(Spanned {
3636
node: LitKind::Str(ext_literal, ..),

clippy_lints/src/methods/clone_on_copy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub(super) fn check(
2828
if cx
2929
.typeck_results()
3030
.type_dependent_def_id(expr.hir_id)
31-
.and_then(|id| cx.tcx.trait_of_item(id))
31+
.and_then(|id| cx.tcx.trait_of_assoc(id))
3232
.zip(cx.tcx.lang_items().clone_trait())
3333
.is_none_or(|(x, y)| x != y)
3434
{

clippy_lints/src/methods/get_first.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub(super) fn check<'tcx>(
1818
arg: &'tcx hir::Expr<'_>,
1919
) {
2020
if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
21-
&& let Some(impl_id) = cx.tcx.impl_of_method(method_id)
21+
&& let Some(impl_id) = cx.tcx.impl_of_assoc(method_id)
2222
&& let identity = cx.tcx.type_of(impl_id).instantiate_identity()
2323
&& let hir::ExprKind::Lit(Spanned {
2424
node: LitKind::Int(Pu128(0), _),

0 commit comments

Comments
 (0)