Skip to content

Commit 1cf95a9

Browse files
committed
don't call type_of on generic params
1 parent b033883 commit 1cf95a9

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

clippy_lints/src/missing_fields_in_debug.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ impl<'tcx> LateLintPass<'tcx> for MissingFieldsInDebug {
207207
if let ItemKind::Impl(Impl { of_trait: Some(trait_ref), self_ty, items, .. }) = item.kind
208208
&& let Res::Def(DefKind::Trait, trait_def_id) = trait_ref.path.res
209209
&& let TyKind::Path(QPath::Resolved(_, self_path)) = &self_ty.kind
210+
// don't trigger if self is a generic parameter, e.g. `impl<T> Debug for T`
211+
// this can only happen in core itself, where the trait is defined,
212+
// but it caused ICEs in the past:
213+
// https://github.com/rust-lang/rust-clippy/issues/10887
214+
&& !matches!(self_path.res, Res::Def(DefKind::TyParam, _))
210215
&& cx.match_def_path(trait_def_id, &[sym::core, sym::fmt, sym::Debug])
211216
// don't trigger if this impl was derived
212217
&& !cx.tcx.has_attr(item.owner_id, sym::automatically_derived)

0 commit comments

Comments
 (0)