mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 05:33:27 +00:00
Auto merge of #10897 - y21:issue10887, r=Alexendoo
[`missing_fields_in_debug`]: don't ICE when self type is a generic param Fixes #10887 This PR fixes an ICE that happens when the implementor (self type) of a `Debug` impl is a generic parameter. The lint calls `TyCtxt::type_of` with that self type, which ICEs when called with generic parameters, so this just adds a quick check before getting there to ignore them. That can only happen inside of core itself (afaik) because the orphan rules forbid defining an impl such as `impl<T> Debug for T` outside of core, so I'm not sure how to add a test for this. It seems like this impl in particular caused this: https://doc.rust-lang.org/stable/std/fmt/trait.Debug.html#impl-Debug-for-F changelog: [`missing_fields_in_debug`]: don't ICE on blanket `Debug` impl in core
This commit is contained in:
commit
2360f80143
1 changed files with 5 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue