@@ -11,8 +11,8 @@ use rustc_lint::{LateContext, LateLintPass};
11
11
use rustc_middle:: hir:: nested_filter;
12
12
use rustc_middle:: traits:: Reveal ;
13
13
use rustc_middle:: ty:: {
14
- self , ClauseKind , GenericArgKind , GenericParamDefKind , ImplPolarity , ParamEnv , ToPredicate , TraitPredicate , Ty ,
15
- TyCtxt ,
14
+ self , AdtDef , ClauseKind , GenericArgKind , GenericParamDefKind , ImplPolarity , ParamEnv , ToPredicate , TraitPredicate ,
15
+ Ty , TyCtxt ,
16
16
} ;
17
17
use rustc_session:: declare_lint_pass;
18
18
use rustc_span:: def_id:: LocalDefId ;
@@ -442,13 +442,25 @@ impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> {
442
442
}
443
443
}
444
444
445
+ fn has_non_exhaustive_attr ( cx : & LateContext < ' _ > , adt : AdtDef < ' _ > ) -> bool {
446
+ adt. is_variant_list_non_exhaustive ( )
447
+ || cx. tcx . has_attr ( adt. did ( ) , sym:: non_exhaustive)
448
+ || adt. variants ( ) . iter ( ) . any ( |variant_def| {
449
+ variant_def. is_field_list_non_exhaustive ( ) || cx. tcx . has_attr ( variant_def. def_id , sym:: non_exhaustive)
450
+ } )
451
+ || adt
452
+ . all_fields ( )
453
+ . any ( |field_def| cx. tcx . has_attr ( field_def. did , sym:: non_exhaustive) )
454
+ }
455
+
445
456
/// Implementation of the `DERIVE_PARTIAL_EQ_WITHOUT_EQ` lint.
446
457
fn check_partial_eq_without_eq < ' tcx > ( cx : & LateContext < ' tcx > , span : Span , trait_ref : & hir:: TraitRef < ' _ > , ty : Ty < ' tcx > ) {
447
458
if let ty:: Adt ( adt, args) = ty. kind ( )
448
459
&& cx. tcx . visibility ( adt. did ( ) ) . is_public ( )
449
460
&& let Some ( eq_trait_def_id) = cx. tcx . get_diagnostic_item ( sym:: Eq )
450
461
&& let Some ( def_id) = trait_ref. trait_def_id ( )
451
462
&& cx. tcx . is_diagnostic_item ( sym:: PartialEq , def_id)
463
+ && !has_non_exhaustive_attr ( cx, * adt)
452
464
&& let param_env = param_env_for_derived_eq ( cx. tcx , adt. did ( ) , eq_trait_def_id)
453
465
&& !implements_trait_with_env ( cx. tcx , param_env, ty, eq_trait_def_id, adt. did ( ) , & [ ] )
454
466
// If all of our fields implement `Eq`, we can implement `Eq` too
0 commit comments