1+ use clippy_config:: msrvs:: { self , Msrv } ;
12use clippy_utils:: diagnostics:: span_lint_and_then;
23use clippy_utils:: macros:: HirNode ;
34use clippy_utils:: sugg:: Sugg ;
@@ -6,7 +7,7 @@ use rustc_errors::Applicability;
67use rustc_hir:: { self as hir, Expr , ExprKind , Node } ;
78use rustc_lint:: { LateContext , LateLintPass } ;
89use rustc_middle:: ty:: { self , Instance , Mutability } ;
9- use rustc_session:: declare_lint_pass ;
10+ use rustc_session:: impl_lint_pass ;
1011use rustc_span:: def_id:: DefId ;
1112use rustc_span:: symbol:: sym;
1213use rustc_span:: ExpnKind ;
@@ -49,10 +50,26 @@ declare_clippy_lint! {
4950 perf,
5051 "assigning the result of cloning may be inefficient"
5152}
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 ] ) ;
5366
5467impl < ' tcx > LateLintPass < ' tcx > for AssigningClones {
5568 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+
5673 // Do not fire the lint in macros
5774 let expn_data = assign_expr. span ( ) . ctxt ( ) . outer_expn_data ( ) ;
5875 match expn_data. kind {
@@ -72,6 +89,8 @@ impl<'tcx> LateLintPass<'tcx> for AssigningClones {
7289 suggest ( cx, assign_expr, lhs, & call) ;
7390 }
7491 }
92+
93+ extract_msrv_attr ! ( LateContext ) ;
7594}
7695
7796// Try to resolve the call to `Clone::clone` or `ToOwned::to_owned`.
0 commit comments