Skip to content

Commit 2eff2f2

Browse files
committed
Auto merge of #11122 - Nilstrieb:SUBSTITUTION-INITIATED, r=flip1995
Pass correct substs to `implements_trait` in `incorrect_impls` `Copy<T>` does in fact not exist. The substs on the trait_ref contain the `Self` type of the impl as the first parameter, so passing that to `implements_trait`, which then nicely prepends the `Self` type for us does not end will. fixes #11121 The assertions requires debug assertions inside rustc, which is probably why it didn't fire here. I tested the change locally in rust-lang/rust and it did not ICE anymore. cc `@xFrednet` `@Centri3` changelog: [`incorrect_impls`]: fix confusion about generic parameters
2 parents 26edd5a + 5df1f66 commit 2eff2f2

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

clippy_lints/src/incorrect_impls.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use clippy_utils::{diagnostics::span_lint_and_sugg, get_parent_node, last_path_segment, ty::implements_trait};
22
use rustc_errors::Applicability;
3-
use rustc_hir::{ExprKind, ImplItem, ImplItemKind, ItemKind, Node, UnOp};
4-
use rustc_hir_analysis::hir_ty_to_ty;
3+
use rustc_hir::{ExprKind, ImplItem, ImplItemKind, Node, UnOp};
54
use rustc_lint::{LateContext, LateLintPass};
65
use rustc_middle::ty::EarlyBinder;
76
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -55,9 +54,6 @@ impl LateLintPass<'_> for IncorrectImpls {
5554
let Some(Node::Item(item)) = node else {
5655
return;
5756
};
58-
let ItemKind::Impl(imp) = item.kind else {
59-
return;
60-
};
6157
let Some(trait_impl) = cx.tcx.impl_trait_ref(item.owner_id).map(EarlyBinder::skip_binder) else {
6258
return;
6359
};
@@ -80,9 +76,9 @@ impl LateLintPass<'_> for IncorrectImpls {
8076
&& let Some(copy_def_id) = cx.tcx.get_diagnostic_item(sym::Copy)
8177
&& implements_trait(
8278
cx,
83-
hir_ty_to_ty(cx.tcx, imp.self_ty),
79+
trait_impl.self_ty(),
8480
copy_def_id,
85-
trait_impl.substs,
81+
&[],
8682
)
8783
{
8884
if impl_item.ident.name == sym::clone {

0 commit comments

Comments
 (0)