Skip to content

Commit d19cd65

Browse files
committed
Rename trivial_map_over_range to map_with_unused_argument_over_ranges
This is plural and more accurately describes the lint.
1 parent 3c0aaa0 commit d19cd65

9 files changed

+24
-23
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5559,6 +5559,7 @@ Released 2018-09-13
55595559
[`map_flatten`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_flatten
55605560
[`map_identity`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_identity
55615561
[`map_unwrap_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_unwrap_or
5562+
[`map_with_unused_argument_over_ranges`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_with_unused_argument_over_ranges
55625563
[`match_as_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_as_ref
55635564
[`match_bool`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_bool
55645565
[`match_like_matches_macro`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro
@@ -5885,7 +5886,6 @@ Released 2018-09-13
58855886
[`transmutes_expressible_as_ptr_casts`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmutes_expressible_as_ptr_casts
58865887
[`transmuting_null`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmuting_null
58875888
[`trim_split_whitespace`]: https://rust-lang.github.io/rust-clippy/master/index.html#trim_split_whitespace
5888-
[`trivial_map_over_range`]: https://rust-lang.github.io/rust-clippy/master/index.html#trivial_map_over_range
58895889
[`trivial_regex`]: https://rust-lang.github.io/rust-clippy/master/index.html#trivial_regex
58905890
[`trivially_copy_pass_by_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref
58915891
[`try_err`]: https://rust-lang.github.io/rust-clippy/master/index.html#try_err

clippy_lints/src/declared_lints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
320320
crate::manual_unwrap_or_default::MANUAL_UNWRAP_OR_DEFAULT_INFO,
321321
crate::map_unit_fn::OPTION_MAP_UNIT_FN_INFO,
322322
crate::map_unit_fn::RESULT_MAP_UNIT_FN_INFO,
323+
crate::map_with_unused_argument_over_ranges::MAP_WITH_UNUSED_ARGUMENT_OVER_RANGES_INFO,
323324
crate::match_result_ok::MATCH_RESULT_OK_INFO,
324325
crate::matches::COLLAPSIBLE_MATCH_INFO,
325326
crate::matches::INFALLIBLE_DESTRUCTURING_MATCH_INFO,
@@ -706,7 +707,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
706707
crate::transmute::UNSOUND_COLLECTION_TRANSMUTE_INFO,
707708
crate::transmute::USELESS_TRANSMUTE_INFO,
708709
crate::transmute::WRONG_TRANSMUTE_INFO,
709-
crate::trivial_map_over_range::TRIVIAL_MAP_OVER_RANGE_INFO,
710710
crate::tuple_array_conversions::TUPLE_ARRAY_CONVERSIONS_INFO,
711711
crate::types::BORROWED_BOX_INFO,
712712
crate::types::BOX_COLLECTION_INFO,

clippy_lints/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ mod manual_string_new;
217217
mod manual_strip;
218218
mod manual_unwrap_or_default;
219219
mod map_unit_fn;
220+
mod map_with_unused_argument_over_ranges;
220221
mod match_result_ok;
221222
mod matches;
222223
mod mem_replace;
@@ -346,7 +347,6 @@ mod to_string_trait_impl;
346347
mod trailing_empty_array;
347348
mod trait_bounds;
348349
mod transmute;
349-
mod trivial_map_over_range;
350350
mod tuple_array_conversions;
351351
mod types;
352352
mod unconditional_recursion;
@@ -1175,7 +1175,7 @@ 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(trivial_map_over_range::TrivialMapOverRange));
1178+
store.register_late_pass(|_| Box::new(map_with_unused_argument_over_ranges::MapWithUnusedArgumentOverRanges));
11791179
// add lints here, do not remove this comment, it's used in `new_lint`
11801180
}
11811181

clippy_lints/src/trivial_map_over_range.rs renamed to clippy_lints/src/map_with_unused_argument_over_ranges.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ use rustc_session::declare_lint_pass;
1010
declare_clippy_lint! {
1111
/// ### What it does
1212
///
13-
/// Lint to prevent trivial `map`s over ranges when one could use `take`.
13+
/// Checks for `Iterator::map` over ranges without using the parameter which
14+
/// could be more clearly expressed using `std::iter::repeat_with(...).take(...)`.
1415
///
1516
/// ### Why is this bad?
1617
///
@@ -27,14 +28,14 @@ declare_clippy_lint! {
2728
/// let f : Vec<_> = std::iter::repeat_with(|| { 3 + 1 }).take(10).collect();
2829
/// ```
2930
#[clippy::version = "1.81.0"]
30-
pub TRIVIAL_MAP_OVER_RANGE,
31+
pub MAP_WITH_UNUSED_ARGUMENT_OVER_RANGES,
3132
style,
3233
"map of a trivial closure (not dependent on parameter) over a range"
3334
}
3435

35-
declare_lint_pass!(TrivialMapOverRange => [TRIVIAL_MAP_OVER_RANGE]);
36+
declare_lint_pass!(MapWithUnusedArgumentOverRanges => [MAP_WITH_UNUSED_ARGUMENT_OVER_RANGES]);
3637

37-
impl LateLintPass<'_> for TrivialMapOverRange {
38+
impl LateLintPass<'_> for MapWithUnusedArgumentOverRanges {
3839
fn check_expr(&mut self, cx: &LateContext<'_>, ex: &Expr<'_>) {
3940
if let ExprKind::MethodCall(path, receiver, [map_arg_expr], _call_span) = ex.kind
4041
&& path.ident.name == rustc_span::sym::map
@@ -56,7 +57,7 @@ impl LateLintPass<'_> for TrivialMapOverRange {
5657
.replacen("|_|", "||", 1);
5758
span_lint_and_sugg(
5859
cx,
59-
TRIVIAL_MAP_OVER_RANGE,
60+
MAP_WITH_UNUSED_ARGUMENT_OVER_RANGES,
6061
ex.span,
6162
"map of a trivial closure (not dependent on parameter) over a range",
6263
"use",
@@ -70,7 +71,7 @@ impl LateLintPass<'_> for TrivialMapOverRange {
7071
.replacen("|_|", "||", 1);
7172
span_lint_and_sugg(
7273
cx,
73-
TRIVIAL_MAP_OVER_RANGE,
74+
MAP_WITH_UNUSED_ARGUMENT_OVER_RANGES,
7475
ex.span,
7576
"map of a trivial closure (not dependent on parameter) over a range",
7677
"use",

tests/ui/trivial_map_over_range.fixed renamed to tests/ui/map_with_unused_argument_over_ranges.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![allow(unused, clippy::redundant_closure)]
2-
#![warn(clippy::trivial_map_over_range)]
2+
#![warn(clippy::map_with_unused_argument_over_ranges)]
33

44
fn do_something() -> usize {
55
todo!()

tests/ui/trivial_map_over_range.rs renamed to tests/ui/map_with_unused_argument_over_ranges.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![allow(unused, clippy::redundant_closure)]
2-
#![warn(clippy::trivial_map_over_range)]
2+
#![warn(clippy::map_with_unused_argument_over_ranges)]
33

44
fn do_something() -> usize {
55
todo!()

tests/ui/trivial_map_over_range.stderr renamed to tests/ui/map_with_unused_argument_over_ranges.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
error: map of a trivial closure (not dependent on parameter) over a range
2-
--> tests/ui/trivial_map_over_range.rs:14:5
2+
--> tests/ui/map_with_unused_argument_over_ranges.rs:14:5
33
|
44
LL | (0..10).map(|_| do_something());
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `std::iter::repeat_with(|| do_something()).take(10)`
66
|
7-
= note: `-D clippy::trivial-map-over-range` implied by `-D warnings`
8-
= help: to override `-D warnings` add `#[allow(clippy::trivial_map_over_range)]`
7+
= note: `-D clippy::map-with-unused-argument-over-ranges` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(clippy::map_with_unused_argument_over_ranges)]`
99

1010
error: map of a trivial closure (not dependent on parameter) over a range
11-
--> tests/ui/trivial_map_over_range.rs:15:5
11+
--> tests/ui/map_with_unused_argument_over_ranges.rs:15:5
1212
|
1313
LL | (3..10).map(|_| do_something());
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `std::iter::repeat_with(|| do_something()).take(7)`
1515

1616
error: map of a trivial closure (not dependent on parameter) over a range
17-
--> tests/ui/trivial_map_over_range.rs:16:5
17+
--> tests/ui/map_with_unused_argument_over_ranges.rs:16:5
1818
|
1919
LL | (0..10).map(|_| 3);
2020
| ^^^^^^^^^^^^^^^^^^ help: use: `std::iter::repeat_with(|| 3).take(10)`
2121

2222
error: map of a trivial closure (not dependent on parameter) over a range
23-
--> tests/ui/trivial_map_over_range.rs:17:5
23+
--> tests/ui/map_with_unused_argument_over_ranges.rs:17:5
2424
|
2525
LL | / (0..10).map(|_| {
2626
LL | | let x = 3;
@@ -37,19 +37,19 @@ LL ~ }).take(10);
3737
|
3838

3939
error: map of a trivial closure (not dependent on parameter) over a range
40-
--> tests/ui/trivial_map_over_range.rs:21:5
40+
--> tests/ui/map_with_unused_argument_over_ranges.rs:21:5
4141
|
4242
LL | (0..10).map(|_| do_something()).collect::<Vec<_>>();
4343
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `std::iter::repeat_with(|| do_something()).take(10)`
4444

4545
error: map of a trivial closure (not dependent on parameter) over a range
46-
--> tests/ui/trivial_map_over_range.rs:23:5
46+
--> tests/ui/map_with_unused_argument_over_ranges.rs:23:5
4747
|
4848
LL | (0..upper).map(|_| do_something());
4949
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `std::iter::repeat_with(|| do_something()).take(upper)`
5050

5151
error: map of a trivial closure (not dependent on parameter) over a range
52-
--> tests/ui/trivial_map_over_range.rs:25:5
52+
--> tests/ui/map_with_unused_argument_over_ranges.rs:25:5
5353
|
5454
LL | (0..upper_fn()).map(|_| do_something());
5555
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `std::iter::repeat_with(|| do_something()).take(upper_fn())`

tests/ui/repeat_vec_with_capacity.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![allow(clippy::trivial_map_over_range)]
1+
#![allow(clippy::map_with_unused_argument_over_ranges)]
22
#![warn(clippy::repeat_vec_with_capacity)]
33

44
fn main() {

tests/ui/repeat_vec_with_capacity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![allow(clippy::trivial_map_over_range)]
1+
#![allow(clippy::map_with_unused_argument_over_ranges)]
22
#![warn(clippy::repeat_vec_with_capacity)]
33

44
fn main() {

0 commit comments

Comments
 (0)