Skip to content

Commit b3d632e

Browse files
committed
Add MSRV
1 parent ed44449 commit b3d632e

File tree

7 files changed

+51
-5
lines changed

7 files changed

+51
-5
lines changed

clippy_config/src/conf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ define_Conf! {
267267
///
268268
/// Suppress lints whenever the suggested change would cause breakage for other crates.
269269
(avoid_breaking_exported_api: bool = true),
270-
/// Lint: MANUAL_SPLIT_ONCE, MANUAL_STR_REPEAT, CLONED_INSTEAD_OF_COPIED, REDUNDANT_FIELD_NAMES, OPTION_MAP_UNWRAP_OR, REDUNDANT_STATIC_LIFETIMES, FILTER_MAP_NEXT, CHECKED_CONVERSIONS, MANUAL_RANGE_CONTAINS, USE_SELF, MEM_REPLACE_WITH_DEFAULT, MANUAL_NON_EXHAUSTIVE, OPTION_AS_REF_DEREF, MAP_UNWRAP_OR, MATCH_LIKE_MATCHES_MACRO, MANUAL_STRIP, MISSING_CONST_FOR_FN, UNNESTED_OR_PATTERNS, FROM_OVER_INTO, PTR_AS_PTR, IF_THEN_SOME_ELSE_NONE, APPROX_CONSTANT, DEPRECATED_CFG_ATTR, INDEX_REFUTABLE_SLICE, MAP_CLONE, BORROW_AS_PTR, MANUAL_BITS, ERR_EXPECT, CAST_ABS_TO_UNSIGNED, UNINLINED_FORMAT_ARGS, MANUAL_CLAMP, MANUAL_LET_ELSE, UNCHECKED_DURATION_SUBTRACTION, COLLAPSIBLE_STR_REPLACE, SEEK_FROM_CURRENT, SEEK_REWIND, UNNECESSARY_LAZY_EVALUATIONS, TRANSMUTE_PTR_TO_REF, ALMOST_COMPLETE_RANGE, NEEDLESS_BORROW, DERIVABLE_IMPLS, MANUAL_IS_ASCII_CHECK, MANUAL_REM_EUCLID, MANUAL_RETAIN, TYPE_REPETITION_IN_BOUNDS, TUPLE_ARRAY_CONVERSIONS, MANUAL_TRY_FOLD, MANUAL_HASH_ONE, ITER_KV_MAP, MANUAL_C_STR_LITERALS, ASSIGNING_CLONES, LEGACY_NUMERIC_CONSTANTS, MANUAL_PATTERN_CHAR_COMPARISON, ALLOW_ATTRIBUTES, ALLOW_ATTRIBUTES_WITHOUT_REASON.
270+
/// Lint: MANUAL_SPLIT_ONCE, MANUAL_STR_REPEAT, CLONED_INSTEAD_OF_COPIED, REDUNDANT_FIELD_NAMES, OPTION_MAP_UNWRAP_OR, REDUNDANT_STATIC_LIFETIMES, FILTER_MAP_NEXT, CHECKED_CONVERSIONS, MANUAL_RANGE_CONTAINS, USE_SELF, MEM_REPLACE_WITH_DEFAULT, MANUAL_NON_EXHAUSTIVE, OPTION_AS_REF_DEREF, MAP_UNWRAP_OR, MATCH_LIKE_MATCHES_MACRO, MANUAL_STRIP, MISSING_CONST_FOR_FN, UNNESTED_OR_PATTERNS, FROM_OVER_INTO, PTR_AS_PTR, IF_THEN_SOME_ELSE_NONE, APPROX_CONSTANT, DEPRECATED_CFG_ATTR, INDEX_REFUTABLE_SLICE, MAP_CLONE, BORROW_AS_PTR, MANUAL_BITS, ERR_EXPECT, CAST_ABS_TO_UNSIGNED, UNINLINED_FORMAT_ARGS, MANUAL_CLAMP, MANUAL_LET_ELSE, UNCHECKED_DURATION_SUBTRACTION, COLLAPSIBLE_STR_REPLACE, SEEK_FROM_CURRENT, SEEK_REWIND, UNNECESSARY_LAZY_EVALUATIONS, TRANSMUTE_PTR_TO_REF, ALMOST_COMPLETE_RANGE, NEEDLESS_BORROW, DERIVABLE_IMPLS, MANUAL_IS_ASCII_CHECK, MANUAL_REM_EUCLID, MANUAL_RETAIN, TYPE_REPETITION_IN_BOUNDS, TUPLE_ARRAY_CONVERSIONS, MANUAL_TRY_FOLD, MANUAL_HASH_ONE, ITER_KV_MAP, MANUAL_C_STR_LITERALS, ASSIGNING_CLONES, LEGACY_NUMERIC_CONSTANTS, MANUAL_PATTERN_CHAR_COMPARISON, ALLOW_ATTRIBUTES, ALLOW_ATTRIBUTES_WITHOUT_REASON, MAP_WITH_UNUSED_ARGUMENT_OVER_RANGES.
271271
///
272272
/// The minimum rust version that the project supports. Defaults to the `rust-version` field in `Cargo.toml`
273273
#[default_text = ""]

clippy_config/src/msrvs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ msrv_aliases! {
5757
1,17,0 { FIELD_INIT_SHORTHAND, STATIC_IN_CONST, EXPECT_ERR }
5858
1,16,0 { STR_REPEAT }
5959
1,15,0 { MAYBE_BOUND_IN_WHERE }
60+
1,28,0 { REPEAT_WITH }
6061
}
6162

6263
/// Tracks the current MSRV from `clippy.toml`, `Cargo.toml` or set via `#[clippy::msrv]`

clippy_lints/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,9 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
11751175
store.register_late_pass(move |_| Box::new(string_patterns::StringPatterns::new(msrv())));
11761176
store.register_early_pass(|| Box::new(field_scoped_visibility_modifiers::FieldScopedVisibilityModifiers));
11771177
store.register_late_pass(|_| Box::new(set_contains_or_insert::HashsetInsertAfterContains));
1178-
store.register_late_pass(|_| Box::new(map_with_unused_argument_over_ranges::MapWithUnusedArgumentOverRanges));
1178+
store.register_late_pass(move |_| {
1179+
Box::new(map_with_unused_argument_over_ranges::MapWithUnusedArgumentOverRanges::new(msrv()))
1180+
});
11791181
// add lints here, do not remove this comment, it's used in `new_lint`
11801182
}
11811183

clippy_lints/src/map_with_unused_argument_over_ranges.rs

Lines changed: 18 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_sugg;
23
use clippy_utils::higher;
34
use clippy_utils::source::snippet_with_applicability;
@@ -7,7 +8,7 @@ use rustc_data_structures::packed::Pu128;
78
use rustc_errors::Applicability;
89
use rustc_hir::{Body, Closure, Expr, ExprKind, PatKind};
910
use rustc_lint::{LateContext, LateLintPass};
10-
use rustc_session::declare_lint_pass;
11+
use rustc_session::impl_lint_pass;
1112

1213
declare_clippy_lint! {
1314
/// ### What it does
@@ -35,10 +36,24 @@ declare_clippy_lint! {
3536
"map of a trivial closure (not dependent on parameter) over a range"
3637
}
3738

38-
declare_lint_pass!(MapWithUnusedArgumentOverRanges => [MAP_WITH_UNUSED_ARGUMENT_OVER_RANGES]);
39+
pub struct MapWithUnusedArgumentOverRanges {
40+
msrv: Msrv,
41+
}
42+
43+
impl MapWithUnusedArgumentOverRanges {
44+
#[must_use]
45+
pub fn new(msrv: Msrv) -> Self {
46+
Self { msrv }
47+
}
48+
}
49+
50+
impl_lint_pass!(MapWithUnusedArgumentOverRanges => [MAP_WITH_UNUSED_ARGUMENT_OVER_RANGES]);
3951

4052
impl LateLintPass<'_> for MapWithUnusedArgumentOverRanges {
4153
fn check_expr(&mut self, cx: &LateContext<'_>, ex: &Expr<'_>) {
54+
if !self.msrv.meets(msrvs::REPEAT_WITH) {
55+
return;
56+
}
4257
if let ExprKind::MethodCall(path, receiver, [map_arg_expr], _call_span) = ex.kind
4358
&& path.ident.name == rustc_span::sym::map
4459
&& let Some(higher::Range {
@@ -93,4 +108,5 @@ impl LateLintPass<'_> for MapWithUnusedArgumentOverRanges {
93108
}
94109
}
95110
}
111+
extract_msrv_attr!(LateContext);
96112
}

tests/ui/map_with_unused_argument_over_ranges.fixed

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,14 @@ fn main() {
3737
(0..10).map(|x| do_something_interesting(x, 4)); // Actual map over range
3838
"Foobar".chars().map(|_| do_something()); // Not a map over range
3939
}
40+
41+
42+
#[clippy::msrv = "1.27"]
43+
fn msrv_1_27() {
44+
(0..10).map(|_| do_something());
45+
}
46+
47+
#[clippy::msrv = "1.28"]
48+
fn msrv_1_28() {
49+
std::iter::repeat_with(|| do_something()).take(10);
50+
}

tests/ui/map_with_unused_argument_over_ranges.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,13 @@ fn main() {
3737
(0..10).map(|x| do_something_interesting(x, 4)); // Actual map over range
3838
"Foobar".chars().map(|_| do_something()); // Not a map over range
3939
}
40+
41+
#[clippy::msrv = "1.27"]
42+
fn msrv_1_27() {
43+
(0..10).map(|_| do_something());
44+
}
45+
46+
#[clippy::msrv = "1.28"]
47+
fn msrv_1_28() {
48+
(0..10).map(|_| do_something());
49+
}

tests/ui/map_with_unused_argument_over_ranges.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,11 @@ error: map of a trivial closure (not dependent on parameter) over a range
6666
LL | (0..=upper_fn()).map(|_| do_something());
6767
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `std::iter::repeat_with(|| do_something()).take(upper_fn() + 1)`
6868

69-
error: aborting due to 9 previous errors
69+
error: map of a trivial closure (not dependent on parameter) over a range
70+
--> tests/ui/map_with_unused_argument_over_ranges.rs:49:5
71+
|
72+
LL | (0..10).map(|_| do_something());
73+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `std::iter::repeat_with(|| do_something()).take(10)`
74+
75+
error: aborting due to 10 previous errors
7076

0 commit comments

Comments
 (0)