acc3842d43
This lint checks for code that looks like ```rust let something : Vec<_> = (0..100).map(|_| { 1 + 2 + 3 }).collect(); ``` which is more clear as ```rust let something : Vec<_> = std::iter::repeat_with(|| { 1 + 2 + 3 }).take(100).collect(); ``` or ```rust let something : Vec<_> = std::iter::repeat_n(1 + 2 + 3, 100) .collect(); ``` That is, a map over a range which does nothing with the parameter passed to it is simply a function (or closure) being called `n` times and could be more semantically expressed using `take`.
224 lines
7.5 KiB
Plaintext
224 lines
7.5 KiB
Plaintext
error: map of a closure that does not depend on its parameter over a range
|
|
--> tests/ui/map_with_unused_argument_over_ranges.rs:25:5
|
|
|
|
|
LL | (0..10).map(|_| do_something());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
= note: `-D clippy::map-with-unused-argument-over-ranges` implied by `-D warnings`
|
|
= help: to override `-D warnings` add `#[allow(clippy::map_with_unused_argument_over_ranges)]`
|
|
help: remove the explicit range and use `repeat_with` and `take`
|
|
|
|
|
LL - (0..10).map(|_| do_something());
|
|
LL + std::iter::repeat_with(|| do_something()).take(10);
|
|
|
|
|
|
|
error: map of a closure that does not depend on its parameter over a range
|
|
--> tests/ui/map_with_unused_argument_over_ranges.rs:26:5
|
|
|
|
|
LL | (0..10).map(|_foo| do_something());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove the explicit range and use `repeat_with` and `take`
|
|
|
|
|
LL - (0..10).map(|_foo| do_something());
|
|
LL + std::iter::repeat_with(|| do_something()).take(10);
|
|
|
|
|
|
|
error: map of a closure that does not depend on its parameter over a range
|
|
--> tests/ui/map_with_unused_argument_over_ranges.rs:27:5
|
|
|
|
|
LL | (0..=10).map(|_| do_something());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove the explicit range and use `repeat_with` and `take`
|
|
|
|
|
LL - (0..=10).map(|_| do_something());
|
|
LL + std::iter::repeat_with(|| do_something()).take(11);
|
|
|
|
|
|
|
error: map of a closure that does not depend on its parameter over a range
|
|
--> tests/ui/map_with_unused_argument_over_ranges.rs:28:5
|
|
|
|
|
LL | (3..10).map(|_| do_something());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove the explicit range and use `repeat_with` and `take`
|
|
|
|
|
LL - (3..10).map(|_| do_something());
|
|
LL + std::iter::repeat_with(|| do_something()).take(7);
|
|
|
|
|
|
|
error: map of a closure that does not depend on its parameter over a range
|
|
--> tests/ui/map_with_unused_argument_over_ranges.rs:29:5
|
|
|
|
|
LL | (3..=10).map(|_| do_something());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove the explicit range and use `repeat_with` and `take`
|
|
|
|
|
LL - (3..=10).map(|_| do_something());
|
|
LL + std::iter::repeat_with(|| do_something()).take(8);
|
|
|
|
|
|
|
error: map of a closure that does not depend on its parameter over a range
|
|
--> tests/ui/map_with_unused_argument_over_ranges.rs:30:5
|
|
|
|
|
LL | (0..10).map(|_| 3);
|
|
| ^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove the explicit range and use `repeat_n`
|
|
|
|
|
LL | std::iter::repeat_n(3, 10);
|
|
| ~~~~~~~~~~~~~~~~~~~ ~~~~~
|
|
|
|
error: map of a closure that does not depend on its parameter over a range
|
|
--> tests/ui/map_with_unused_argument_over_ranges.rs:31:5
|
|
|
|
|
LL | / (0..10).map(|_| {
|
|
LL | | let x = 3;
|
|
LL | | x + 2
|
|
LL | | });
|
|
| |______^
|
|
|
|
|
help: remove the explicit range and use `repeat_with` and `take`
|
|
|
|
|
LL ~ std::iter::repeat_with(|| {
|
|
LL | let x = 3;
|
|
LL | x + 2
|
|
LL ~ }).take(10);
|
|
|
|
|
|
|
error: map of a closure that does not depend on its parameter over a range
|
|
--> tests/ui/map_with_unused_argument_over_ranges.rs:35:5
|
|
|
|
|
LL | (0..10).map(|_| do_something()).collect::<Vec<_>>();
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove the explicit range and use `repeat_with` and `take`
|
|
|
|
|
LL - (0..10).map(|_| do_something()).collect::<Vec<_>>();
|
|
LL + std::iter::repeat_with(|| do_something()).take(10).collect::<Vec<_>>();
|
|
|
|
|
|
|
error: map of a closure that does not depend on its parameter over a range
|
|
--> tests/ui/map_with_unused_argument_over_ranges.rs:37:5
|
|
|
|
|
LL | (0..upper).map(|_| do_something());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove the explicit range and use `repeat_with` and `take`
|
|
|
|
|
LL - (0..upper).map(|_| do_something());
|
|
LL + std::iter::repeat_with(|| do_something()).take(upper);
|
|
|
|
|
|
|
error: map of a closure that does not depend on its parameter over a range
|
|
--> tests/ui/map_with_unused_argument_over_ranges.rs:39:5
|
|
|
|
|
LL | (0..upper_fn()).map(|_| do_something());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove the explicit range and use `repeat_with` and `take`
|
|
|
|
|
LL - (0..upper_fn()).map(|_| do_something());
|
|
LL + std::iter::repeat_with(|| do_something()).take(upper_fn());
|
|
|
|
|
|
|
error: map of a closure that does not depend on its parameter over a range
|
|
--> tests/ui/map_with_unused_argument_over_ranges.rs:40:5
|
|
|
|
|
LL | (0..=upper_fn()).map(|_| do_something());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove the explicit range and use `repeat_with` and `take`
|
|
|
|
|
LL - (0..=upper_fn()).map(|_| do_something());
|
|
LL + std::iter::repeat_with(|| do_something()).take(upper_fn() + 1);
|
|
|
|
|
|
|
error: map of a closure that does not depend on its parameter over a range
|
|
--> tests/ui/map_with_unused_argument_over_ranges.rs:41:5
|
|
|
|
|
LL | (2..upper_fn()).map(|_| do_something());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove the explicit range and use `repeat_with` and `take`
|
|
|
|
|
LL - (2..upper_fn()).map(|_| do_something());
|
|
LL + std::iter::repeat_with(|| do_something()).take(upper_fn() - 2);
|
|
|
|
|
|
|
error: map of a closure that does not depend on its parameter over a range
|
|
--> tests/ui/map_with_unused_argument_over_ranges.rs:42:5
|
|
|
|
|
LL | (2..=upper_fn()).map(|_| do_something());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove the explicit range and use `repeat_with` and `take`
|
|
|
|
|
LL - (2..=upper_fn()).map(|_| do_something());
|
|
LL + std::iter::repeat_with(|| do_something()).take(upper_fn() - 1);
|
|
|
|
|
|
|
error: map of a closure that does not depend on its parameter over a range
|
|
--> tests/ui/map_with_unused_argument_over_ranges.rs:44:5
|
|
|
|
|
LL | (9..3).map(|_| do_something());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove the explicit range and use `repeat_with` and `take`
|
|
|
|
|
LL - (9..3).map(|_| do_something());
|
|
LL + std::iter::repeat_with(|| do_something()).take(0);
|
|
|
|
|
|
|
error: map of a closure that does not depend on its parameter over a range
|
|
--> tests/ui/map_with_unused_argument_over_ranges.rs:45:5
|
|
|
|
|
LL | (9..=9).map(|_| do_something());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove the explicit range and use `repeat_with` and `take`
|
|
|
|
|
LL - (9..=9).map(|_| do_something());
|
|
LL + std::iter::repeat_with(|| do_something()).take(1);
|
|
|
|
|
|
|
error: map of a closure that does not depend on its parameter over a range
|
|
--> tests/ui/map_with_unused_argument_over_ranges.rs:46:5
|
|
|
|
|
LL | (1..=1 << 4).map(|_| do_something());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove the explicit range and use `repeat_with` and `take`
|
|
|
|
|
LL - (1..=1 << 4).map(|_| do_something());
|
|
LL + std::iter::repeat_with(|| do_something()).take((1 << 4) - 0);
|
|
|
|
|
|
|
error: map of a closure that does not depend on its parameter over a range
|
|
--> tests/ui/map_with_unused_argument_over_ranges.rs:67:5
|
|
|
|
|
LL | (0..10).map(|_| do_something());
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove the explicit range and use `repeat_with` and `take`
|
|
|
|
|
LL - (0..10).map(|_| do_something());
|
|
LL + std::iter::repeat_with(|| do_something()).take(10);
|
|
|
|
|
|
|
error: map of a closure that does not depend on its parameter over a range
|
|
--> tests/ui/map_with_unused_argument_over_ranges.rs:72:5
|
|
|
|
|
LL | (0..10).map(|_| 3);
|
|
| ^^^^^^^^^^^^^^^^^^
|
|
|
|
|
help: remove the explicit range and use `repeat` and `take`
|
|
|
|
|
LL | std::iter::repeat(3).take(10);
|
|
| ~~~~~~~~~~~~~~~~~ ~ +++++++++
|
|
|
|
error: aborting due to 18 previous errors
|
|
|