@@ -39,7 +39,7 @@ use crate::{
3939 BuiltinUnstableFeatures , BuiltinUnusedDocComment , BuiltinUnusedDocCommentSub ,
4040 BuiltinWhileTrue , SuggestChangingAssocTypes ,
4141 } ,
42- EarlyContext , EarlyLintPass , LateContext , LateLintPass , LintContext ,
42+ EarlyContext , EarlyLintPass , LateContext , LateLintPass , Level , LintContext ,
4343} ;
4444use hir:: IsAsync ;
4545use rustc_ast:: attr;
@@ -51,7 +51,7 @@ use rustc_errors::{Applicability, DecorateLint, MultiSpan};
5151use rustc_feature:: { deprecated_attributes, AttributeGate , BuiltinAttribute , GateIssue , Stability } ;
5252use rustc_hir as hir;
5353use rustc_hir:: def:: { DefKind , Res } ;
54- use rustc_hir:: def_id:: { DefId , LocalDefId , LocalDefIdSet , CRATE_DEF_ID } ;
54+ use rustc_hir:: def_id:: { DefId , LocalDefId , CRATE_DEF_ID } ;
5555use rustc_hir:: intravisit:: FnKind as HirFnKind ;
5656use rustc_hir:: { Body , FnDecl , GenericParamKind , Node , PatKind , PredicateOrigin } ;
5757use rustc_middle:: lint:: in_external_macro;
@@ -774,9 +774,7 @@ declare_lint! {
774774}
775775
776776#[ derive( Default ) ]
777- pub struct MissingDebugImplementations {
778- impling_types : Option < LocalDefIdSet > ,
779- }
777+ pub ( crate ) struct MissingDebugImplementations ;
780778
781779impl_lint_pass ! ( MissingDebugImplementations => [ MISSING_DEBUG_IMPLEMENTATIONS ] ) ;
782780
@@ -793,21 +791,18 @@ impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
793791
794792 let Some ( debug) = cx. tcx . get_diagnostic_item ( sym:: Debug ) else { return } ;
795793
796- if self . impling_types . is_none ( ) {
797- let mut impls = LocalDefIdSet :: default ( ) ;
798- cx. tcx . for_each_impl ( debug, |d| {
799- if let Some ( ty_def) = cx. tcx . type_of ( d) . instantiate_identity ( ) . ty_adt_def ( ) {
800- if let Some ( def_id) = ty_def. did ( ) . as_local ( ) {
801- impls. insert ( def_id) ;
802- }
803- }
804- } ) ;
805-
806- self . impling_types = Some ( impls) ;
807- debug ! ( "{:?}" , self . impling_types) ;
794+ // Avoid listing trait impls if the trait is allowed.
795+ let ( level, _) = cx. tcx . lint_level_at_node ( MISSING_DEBUG_IMPLEMENTATIONS , item. hir_id ( ) ) ;
796+ if level == Level :: Allow {
797+ return ;
808798 }
809799
810- if !self . impling_types . as_ref ( ) . unwrap ( ) . contains ( & item. owner_id . def_id ) {
800+ let has_impl = cx
801+ . tcx
802+ . non_blanket_impls_for_ty ( debug, cx. tcx . type_of ( item. owner_id ) . instantiate_identity ( ) )
803+ . next ( )
804+ . is_some ( ) ;
805+ if !has_impl {
811806 cx. emit_spanned_lint (
812807 MISSING_DEBUG_IMPLEMENTATIONS ,
813808 item. span ,
0 commit comments