11use clippy_utils:: diagnostics:: { span_lint_and_help, span_lint_and_note, span_lint_and_sugg, span_lint_and_then} ;
22use clippy_utils:: ty:: { implements_trait, implements_trait_with_env, is_copy} ;
3- use clippy_utils:: { is_lint_allowed, match_def_path, paths} ;
3+ use clippy_utils:: { has_non_exhaustive_attr , is_lint_allowed, match_def_path, paths} ;
44use rustc_errors:: Applicability ;
55use rustc_hir:: def_id:: DefId ;
66use rustc_hir:: intravisit:: { walk_expr, walk_fn, walk_item, FnKind , Visitor } ;
@@ -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 , AdtDef , ClauseKind , GenericArgKind , GenericParamDefKind , ImplPolarity , ParamEnv , ToPredicate , TraitPredicate ,
15- Ty , TyCtxt ,
14+ self , ClauseKind , GenericArgKind , GenericParamDefKind , ImplPolarity , ParamEnv , ToPredicate , TraitPredicate , Ty ,
15+ TyCtxt ,
1616} ;
1717use rustc_session:: declare_lint_pass;
1818use rustc_span:: def_id:: LocalDefId ;
@@ -442,25 +442,14 @@ 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-
456445/// Implementation of the `DERIVE_PARTIAL_EQ_WITHOUT_EQ` lint.
457446fn check_partial_eq_without_eq < ' tcx > ( cx : & LateContext < ' tcx > , span : Span , trait_ref : & hir:: TraitRef < ' _ > , ty : Ty < ' tcx > ) {
458447 if let ty:: Adt ( adt, args) = ty. kind ( )
459448 && cx. tcx . visibility ( adt. did ( ) ) . is_public ( )
460449 && let Some ( eq_trait_def_id) = cx. tcx . get_diagnostic_item ( sym:: Eq )
461450 && let Some ( def_id) = trait_ref. trait_def_id ( )
462451 && cx. tcx . is_diagnostic_item ( sym:: PartialEq , def_id)
463- && !has_non_exhaustive_attr ( cx, * adt)
452+ && !has_non_exhaustive_attr ( cx. tcx , * adt)
464453 && let param_env = param_env_for_derived_eq ( cx. tcx , adt. did ( ) , eq_trait_def_id)
465454 && !implements_trait_with_env ( cx. tcx , param_env, ty, eq_trait_def_id, adt. did ( ) , & [ ] )
466455 // If all of our fields implement `Eq`, we can implement `Eq` too
0 commit comments