Skip to content

Commit 21a97f0

Browse files
committed
Specify an MSRV of 1.63.0 for assigning_clones
1 parent b5dcaae commit 21a97f0

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

clippy_config/src/msrvs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ msrv_aliases! {
2323
1,70,0 { OPTION_RESULT_IS_VARIANT_AND, BINARY_HEAP_RETAIN }
2424
1,68,0 { PATH_MAIN_SEPARATOR_STR }
2525
1,65,0 { LET_ELSE, POINTER_CAST_CONSTNESS }
26+
1,63,0 { ASSIGNING_CLONES }
2627
1,62,0 { BOOL_THEN_SOME, DEFAULT_ENUM_ATTRIBUTE }
2728
1,59,0 { THREAD_LOCAL_INITIALIZER_CAN_BE_MADE_CONST }
2829
1,58,0 { FORMAT_ARGS_CAPTURE, PATTERN_TRAIT_CHAR_ARRAY }

clippy_lints/src/assigning_clones.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use clippy_config::msrvs::{self, Msrv};
12
use clippy_utils::diagnostics::span_lint_and_then;
23
use clippy_utils::macros::HirNode;
34
use clippy_utils::sugg::Sugg;
@@ -6,7 +7,7 @@ use rustc_errors::Applicability;
67
use rustc_hir::{self as hir, Expr, ExprKind, Node};
78
use rustc_lint::{LateContext, LateLintPass};
89
use rustc_middle::ty::{self, Instance, Mutability};
9-
use rustc_session::declare_lint_pass;
10+
use rustc_session::impl_lint_pass;
1011
use rustc_span::def_id::DefId;
1112
use rustc_span::symbol::sym;
1213
use 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

5467
impl<'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`.

clippy_lints/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
11221122
store.register_late_pass(move |_| Box::new(incompatible_msrv::IncompatibleMsrv::new(msrv())));
11231123
store.register_late_pass(|_| Box::new(to_string_trait_impl::ToStringTraitImpl));
11241124
store.register_early_pass(|| Box::new(multiple_bound_locations::MultipleBoundLocations));
1125-
store.register_late_pass(|_| Box::new(assigning_clones::AssigningClones));
1125+
store.register_late_pass(move |_| Box::new(assigning_clones::AssigningClones::new(msrv())));
11261126
store.register_late_pass(|_| Box::new(zero_repeat_side_effects::ZeroRepeatSideEffects));
11271127
store.register_late_pass(|_| Box::new(manual_unwrap_or_default::ManualUnwrapOrDefault));
11281128
store.register_late_pass(|_| Box::new(integer_division_remainder_used::IntegerDivisionRemainderUsed));

0 commit comments

Comments
 (0)