about summary refs log tree commit diff
diff options
context:
space:
mode:
authory21 <30553356+y21@users.noreply.github.com>2023-06-06 01:23:42 +0200
committery21 <30553356+y21@users.noreply.github.com>2023-06-06 01:23:42 +0200
commit1cf95a9d50b0ca8be1687e03db4202cf033d4a74 (patch)
treec435fb9f970f44af1f56a2814df353bcacba6638
parentb033883e2be39f0bc4ff0f5d9902f87d6f92fc85 (diff)
downloadrust-1cf95a9d50b0ca8be1687e03db4202cf033d4a74.tar.gz
rust-1cf95a9d50b0ca8be1687e03db4202cf033d4a74.zip
don't call `type_of` on generic params
-rw-r--r--clippy_lints/src/missing_fields_in_debug.rs5
1 files changed, 5 insertions, 0 deletions
diff --git a/clippy_lints/src/missing_fields_in_debug.rs b/clippy_lints/src/missing_fields_in_debug.rs
index b6f0de7e504..1138d1163a4 100644
--- a/clippy_lints/src/missing_fields_in_debug.rs
+++ b/clippy_lints/src/missing_fields_in_debug.rs
@@ -207,6 +207,11 @@ impl<'tcx> LateLintPass<'tcx> for MissingFieldsInDebug {
         if let ItemKind::Impl(Impl { of_trait: Some(trait_ref), self_ty, items, .. }) = item.kind
             && let Res::Def(DefKind::Trait, trait_def_id) = trait_ref.path.res
             && let TyKind::Path(QPath::Resolved(_, self_path)) = &self_ty.kind
+            // don't trigger if self is a generic parameter, e.g. `impl<T> Debug for T`
+            // this can only happen in core itself, where the trait is defined,
+            // but it caused ICEs in the past:
+            // https://github.com/rust-lang/rust-clippy/issues/10887
+            && !matches!(self_path.res, Res::Def(DefKind::TyParam, _))
             && cx.match_def_path(trait_def_id, &[sym::core, sym::fmt, sym::Debug])
             // don't trigger if this impl was derived
             && !cx.tcx.has_attr(item.owner_id, sym::automatically_derived)