1
1
use clippy_utils:: diagnostics:: span_lint_and_then;
2
+ use clippy_utils:: msrvs:: { self , Msrv } ;
2
3
use clippy_utils:: source:: indent_of;
3
4
use clippy_utils:: { is_default_equivalent, peel_blocks} ;
4
5
use rustc_errors:: Applicability ;
@@ -8,7 +9,7 @@ use rustc_hir::{
8
9
} ;
9
10
use rustc_lint:: { LateContext , LateLintPass } ;
10
11
use 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 } ;
12
13
use rustc_span:: sym;
13
14
14
15
declare_clippy_lint ! {
@@ -53,7 +54,18 @@ declare_clippy_lint! {
53
54
"manual implementation of the `Default` trait which is equal to a derive"
54
55
}
55
56
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 ] ) ;
57
69
58
70
fn is_path_self ( e : & Expr < ' _ > ) -> bool {
59
71
if let ExprKind :: Path ( QPath :: Resolved ( _, p) ) = e. kind {
@@ -181,10 +193,12 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
181
193
then {
182
194
if adt_def. is_struct( ) {
183
195
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 ) {
185
197
check_enum( cx, item, func_expr, adt_def) ;
186
198
}
187
199
}
188
200
}
189
201
}
202
+
203
+ extract_msrv_attr ! ( LateContext ) ;
190
204
}
0 commit comments