@@ -11,8 +11,8 @@ use rustc_lint::{LateContext, LateLintPass};
1111use rustc_middle:: hir:: nested_filter;
1212use rustc_middle:: traits:: Reveal ;
1313use 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 ,
1616} ;
1717use rustc_session:: declare_lint_pass;
1818use rustc_span:: def_id:: LocalDefId ;
@@ -442,13 +442,25 @@ impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> {
442442 }
443443}
444444
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+
445456/// Implementation of the `DERIVE_PARTIAL_EQ_WITHOUT_EQ` lint.
446457fn check_partial_eq_without_eq < ' tcx > ( cx : & LateContext < ' tcx > , span : Span , trait_ref : & hir:: TraitRef < ' _ > , ty : Ty < ' tcx > ) {
447458 if let ty:: Adt ( adt, args) = ty. kind ( )
448459 && cx. tcx . visibility ( adt. did ( ) ) . is_public ( )
449460 && let Some ( eq_trait_def_id) = cx. tcx . get_diagnostic_item ( sym:: Eq )
450461 && let Some ( def_id) = trait_ref. trait_def_id ( )
451462 && cx. tcx . is_diagnostic_item ( sym:: PartialEq , def_id)
463+ && !has_non_exhaustive_attr ( cx, * adt)
452464 && let param_env = param_env_for_derived_eq ( cx. tcx , adt. did ( ) , eq_trait_def_id)
453465 && !implements_trait_with_env ( cx. tcx , param_env, ty, eq_trait_def_id, adt. did ( ) , & [ ] )
454466 // If all of our fields implement `Eq`, we can implement `Eq` too
0 commit comments