11use clippy_utils:: diagnostics:: span_lint_and_then;
2+ use clippy_utils:: msrvs:: { self , Msrv } ;
23use clippy_utils:: source:: indent_of;
34use clippy_utils:: { is_default_equivalent, peel_blocks} ;
45use rustc_errors:: Applicability ;
@@ -8,7 +9,7 @@ use rustc_hir::{
89} ;
910use rustc_lint:: { LateContext , LateLintPass } ;
1011use rustc_middle:: ty:: { AdtDef , DefIdTree } ;
11- use rustc_session:: { declare_lint_pass , declare_tool_lint } ;
12+ use rustc_session:: { declare_tool_lint , impl_lint_pass } ;
1213use rustc_span:: sym;
1314
1415declare_clippy_lint ! {
@@ -53,7 +54,18 @@ declare_clippy_lint! {
5354 "manual implementation of the `Default` trait which is equal to a derive"
5455}
5556
56- declare_lint_pass ! ( DerivableImpls => [ DERIVABLE_IMPLS ] ) ;
57+ pub struct DerivableImpls {
58+ msrv : Msrv ,
59+ }
60+
61+ impl DerivableImpls {
62+ #[ must_use]
63+ pub fn new ( msrv : Msrv ) -> Self {
64+ DerivableImpls { msrv }
65+ }
66+ }
67+
68+ impl_lint_pass ! ( DerivableImpls => [ DERIVABLE_IMPLS ] ) ;
5769
5870fn is_path_self ( e : & Expr < ' _ > ) -> bool {
5971 if let ExprKind :: Path ( QPath :: Resolved ( _, p) ) = e. kind {
@@ -181,10 +193,12 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
181193 then {
182194 if adt_def. is_struct( ) {
183195 check_struct( cx, item, self_ty, func_expr, adt_def) ;
184- } else if adt_def. is_enum( ) {
196+ } else if adt_def. is_enum( ) && self . msrv . meets ( msrvs :: DEFAULT_ENUM_ATTRIBUTE ) {
185197 check_enum( cx, item, func_expr, adt_def) ;
186198 }
187199 }
188200 }
189201 }
202+
203+ extract_msrv_attr ! ( LateContext ) ;
190204}
0 commit comments