1
1
use clippy_utils:: diagnostics:: { span_lint_and_help, span_lint_and_note, span_lint_and_sugg, span_lint_and_then} ;
2
2
use 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} ;
4
4
use rustc_errors:: Applicability ;
5
5
use rustc_hir:: def_id:: DefId ;
6
6
use rustc_hir:: intravisit:: { walk_expr, walk_fn, walk_item, FnKind , Visitor } ;
@@ -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 , AdtDef , ClauseKind , GenericArgKind , GenericParamDefKind , ImplPolarity , ParamEnv , ToPredicate , TraitPredicate ,
15
- Ty , TyCtxt ,
14
+ self , ClauseKind , GenericArgKind , GenericParamDefKind , ImplPolarity , ParamEnv , ToPredicate , TraitPredicate , Ty ,
15
+ TyCtxt ,
16
16
} ;
17
17
use rustc_session:: declare_lint_pass;
18
18
use rustc_span:: def_id:: LocalDefId ;
@@ -442,25 +442,14 @@ 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
-
456
445
/// Implementation of the `DERIVE_PARTIAL_EQ_WITHOUT_EQ` lint.
457
446
fn check_partial_eq_without_eq < ' tcx > ( cx : & LateContext < ' tcx > , span : Span , trait_ref : & hir:: TraitRef < ' _ > , ty : Ty < ' tcx > ) {
458
447
if let ty:: Adt ( adt, args) = ty. kind ( )
459
448
&& cx. tcx . visibility ( adt. did ( ) ) . is_public ( )
460
449
&& let Some ( eq_trait_def_id) = cx. tcx . get_diagnostic_item ( sym:: Eq )
461
450
&& let Some ( def_id) = trait_ref. trait_def_id ( )
462
451
&& cx. tcx . is_diagnostic_item ( sym:: PartialEq , def_id)
463
- && !has_non_exhaustive_attr ( cx, * adt)
452
+ && !has_non_exhaustive_attr ( cx. tcx , * adt)
464
453
&& let param_env = param_env_for_derived_eq ( cx. tcx , adt. did ( ) , eq_trait_def_id)
465
454
&& !implements_trait_with_env ( cx. tcx , param_env, ty, eq_trait_def_id, adt. did ( ) , & [ ] )
466
455
// If all of our fields implement `Eq`, we can implement `Eq` too
0 commit comments