@@ -39,7 +39,7 @@ use crate::{
39
39
BuiltinUnstableFeatures , BuiltinUnusedDocComment , BuiltinUnusedDocCommentSub ,
40
40
BuiltinWhileTrue , SuggestChangingAssocTypes ,
41
41
} ,
42
- EarlyContext , EarlyLintPass , LateContext , LateLintPass , LintContext ,
42
+ EarlyContext , EarlyLintPass , LateContext , LateLintPass , Level , LintContext ,
43
43
} ;
44
44
use hir:: IsAsync ;
45
45
use rustc_ast:: attr;
@@ -51,7 +51,7 @@ use rustc_errors::{Applicability, DecorateLint, MultiSpan};
51
51
use rustc_feature:: { deprecated_attributes, AttributeGate , BuiltinAttribute , GateIssue , Stability } ;
52
52
use rustc_hir as hir;
53
53
use 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 } ;
55
55
use rustc_hir:: intravisit:: FnKind as HirFnKind ;
56
56
use rustc_hir:: { Body , FnDecl , GenericParamKind , Node , PatKind , PredicateOrigin } ;
57
57
use rustc_middle:: lint:: in_external_macro;
@@ -774,9 +774,7 @@ declare_lint! {
774
774
}
775
775
776
776
#[ derive( Default ) ]
777
- pub struct MissingDebugImplementations {
778
- impling_types : Option < LocalDefIdSet > ,
779
- }
777
+ pub ( crate ) struct MissingDebugImplementations ;
780
778
781
779
impl_lint_pass ! ( MissingDebugImplementations => [ MISSING_DEBUG_IMPLEMENTATIONS ] ) ;
782
780
@@ -793,21 +791,18 @@ impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
793
791
794
792
let Some ( debug) = cx. tcx . get_diagnostic_item ( sym:: Debug ) else { return } ;
795
793
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 ;
808
798
}
809
799
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 {
811
806
cx. emit_spanned_lint (
812
807
MISSING_DEBUG_IMPLEMENTATIONS ,
813
808
item. span ,
0 commit comments