Skip to content

Commit ba92f3a

Browse files
committed
Add more tests for empty ranges and singletons
1 parent a3e6d8a commit ba92f3a

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

tests/ui/map_with_unused_argument_over_ranges.fixed

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![allow(unused, clippy::redundant_closure)]
1+
#![allow(unused, clippy::redundant_closure, clippy::reversed_empty_ranges)]
22
#![warn(clippy::map_with_unused_argument_over_ranges)]
33

44
fn do_something() -> usize {
@@ -36,6 +36,8 @@ fn main() {
3636
std::iter::repeat_with(|| do_something()).take(upper_fn() - 2);
3737
std::iter::repeat_with(|| do_something()).take(upper_fn() - 1);
3838
(-3..9).map(|_| do_something());
39+
std::iter::repeat_with(|| do_something()).take(0);
40+
std::iter::repeat_with(|| do_something()).take(1);
3941
// These should not be raised
4042
gen!();
4143
let lower = 2;

tests/ui/map_with_unused_argument_over_ranges.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![allow(unused, clippy::redundant_closure)]
1+
#![allow(unused, clippy::redundant_closure, clippy::reversed_empty_ranges)]
22
#![warn(clippy::map_with_unused_argument_over_ranges)]
33

44
fn do_something() -> usize {
@@ -36,6 +36,8 @@ fn main() {
3636
(2..upper_fn()).map(|_| do_something());
3737
(2..=upper_fn()).map(|_| do_something());
3838
(-3..9).map(|_| do_something());
39+
(9..3).map(|_| do_something());
40+
(9..=9).map(|_| do_something());
3941
// These should not be raised
4042
gen!();
4143
let lower = 2;

tests/ui/map_with_unused_argument_over_ranges.stderr

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,31 @@ LL + std::iter::repeat_with(|| do_something()).take(upper_fn() - 1);
161161
|
162162

163163
error: map of a closure that does not depend on its parameter over a range
164-
--> tests/ui/map_with_unused_argument_over_ranges.rs:57:5
164+
--> tests/ui/map_with_unused_argument_over_ranges.rs:39:5
165+
|
166+
LL | (9..3).map(|_| do_something());
167+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
168+
|
169+
help: remove the explicit range and use `repeat_with` and `take`
170+
|
171+
LL - (9..3).map(|_| do_something());
172+
LL + std::iter::repeat_with(|| do_something()).take(0);
173+
|
174+
175+
error: map of a closure that does not depend on its parameter over a range
176+
--> tests/ui/map_with_unused_argument_over_ranges.rs:40:5
177+
|
178+
LL | (9..=9).map(|_| do_something());
179+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
180+
|
181+
help: remove the explicit range and use `repeat_with` and `take`
182+
|
183+
LL - (9..=9).map(|_| do_something());
184+
LL + std::iter::repeat_with(|| do_something()).take(1);
185+
|
186+
187+
error: map of a closure that does not depend on its parameter over a range
188+
--> tests/ui/map_with_unused_argument_over_ranges.rs:59:5
165189
|
166190
LL | (0..10).map(|_| do_something());
167191
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -172,5 +196,5 @@ LL - (0..10).map(|_| do_something());
172196
LL + std::iter::repeat_with(|| do_something()).take(10);
173197
|
174198

175-
error: aborting due to 14 previous errors
199+
error: aborting due to 16 previous errors
176200

0 commit comments

Comments
 (0)