diff options
| author | bors <bors@rust-lang.org> | 2023-07-07 19:12:54 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-07-07 19:12:54 +0000 |
| commit | 2eff2f2046749e0e6f33af0de330bd68e64c2b12 (patch) | |
| tree | b3e34ddda6c838eb3b645717cdfa5f955fd8364a | |
| parent | 26edd5a2ab5ae719019f4ca17f93d0bd092f1334 (diff) | |
| parent | 5df1f6681dca1a2028a4e6b60d3ab789c00b4cf8 (diff) | |
| download | rust-2eff2f2046749e0e6f33af0de330bd68e64c2b12.tar.gz rust-2eff2f2046749e0e6f33af0de330bd68e64c2b12.zip | |
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
| -rw-r--r-- | clippy_lints/src/incorrect_impls.rs | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/clippy_lints/src/incorrect_impls.rs b/clippy_lints/src/incorrect_impls.rs index 13cc0b23ba3..ed21df4ff88 100644 --- a/clippy_lints/src/incorrect_impls.rs +++ b/clippy_lints/src/incorrect_impls.rs @@ -1,7 +1,6 @@ use clippy_utils::{diagnostics::span_lint_and_sugg, get_parent_node, last_path_segment, ty::implements_trait}; use rustc_errors::Applicability; -use rustc_hir::{ExprKind, ImplItem, ImplItemKind, ItemKind, Node, UnOp}; -use rustc_hir_analysis::hir_ty_to_ty; +use rustc_hir::{ExprKind, ImplItem, ImplItemKind, Node, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::EarlyBinder; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -55,9 +54,6 @@ impl LateLintPass<'_> for IncorrectImpls { let Some(Node::Item(item)) = node else { return; }; - let ItemKind::Impl(imp) = item.kind else { - return; - }; let Some(trait_impl) = cx.tcx.impl_trait_ref(item.owner_id).map(EarlyBinder::skip_binder) else { return; }; @@ -80,9 +76,9 @@ impl LateLintPass<'_> for IncorrectImpls { && let Some(copy_def_id) = cx.tcx.get_diagnostic_item(sym::Copy) && implements_trait( cx, - hir_ty_to_ty(cx.tcx, imp.self_ty), + trait_impl.self_ty(), copy_def_id, - trait_impl.substs, + &[], ) { if impl_item.ident.name == sym::clone { |
