1
+ use clippy_config:: msrvs:: { self , Msrv } ;
1
2
use clippy_utils:: diagnostics:: span_lint_and_then;
2
3
use clippy_utils:: macros:: HirNode ;
3
4
use clippy_utils:: sugg:: Sugg ;
@@ -6,7 +7,7 @@ use rustc_errors::Applicability;
6
7
use rustc_hir:: { self as hir, Expr , ExprKind , Node } ;
7
8
use rustc_lint:: { LateContext , LateLintPass } ;
8
9
use rustc_middle:: ty:: { self , Instance , Mutability } ;
9
- use rustc_session:: declare_lint_pass ;
10
+ use rustc_session:: impl_lint_pass ;
10
11
use rustc_span:: def_id:: DefId ;
11
12
use rustc_span:: symbol:: sym;
12
13
use rustc_span:: ExpnKind ;
@@ -49,10 +50,26 @@ declare_clippy_lint! {
49
50
perf,
50
51
"assigning the result of cloning may be inefficient"
51
52
}
52
- declare_lint_pass ! ( AssigningClones => [ ASSIGNING_CLONES ] ) ;
53
+
54
+ pub struct AssigningClones {
55
+ msrv : Msrv ,
56
+ }
57
+
58
+ impl AssigningClones {
59
+ #[ must_use]
60
+ pub fn new ( msrv : Msrv ) -> Self {
61
+ Self { msrv }
62
+ }
63
+ }
64
+
65
+ impl_lint_pass ! ( AssigningClones => [ ASSIGNING_CLONES ] ) ;
53
66
54
67
impl < ' tcx > LateLintPass < ' tcx > for AssigningClones {
55
68
fn check_expr ( & mut self , cx : & LateContext < ' tcx > , assign_expr : & ' tcx hir:: Expr < ' _ > ) {
69
+ if !self . msrv . meets ( msrvs:: ASSIGNING_CLONES ) {
70
+ return ;
71
+ }
72
+
56
73
// Do not fire the lint in macros
57
74
let expn_data = assign_expr. span ( ) . ctxt ( ) . outer_expn_data ( ) ;
58
75
match expn_data. kind {
@@ -72,6 +89,8 @@ impl<'tcx> LateLintPass<'tcx> for AssigningClones {
72
89
suggest ( cx, assign_expr, lhs, & call) ;
73
90
}
74
91
}
92
+
93
+ extract_msrv_attr ! ( LateContext ) ;
75
94
}
76
95
77
96
// Try to resolve the call to `Clone::clone` or `ToOwned::to_owned`.
0 commit comments