]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.fixed
Rollup merge of #78216 - workingjubilee:duration-zero, r=m-ou-se
[rust.git] / src / tools / clippy / tests / ui / reversed_empty_ranges_fixable.fixed
1 // run-rustfix
2 #![warn(clippy::reversed_empty_ranges)]
3
4 const ANSWER: i32 = 42;
5
6 fn main() {
7     // These should be linted:
8
9     (21..=42).rev().for_each(|x| println!("{}", x));
10     let _ = (21..ANSWER).rev().filter(|x| x % 2 == 0).take(10).collect::<Vec<_>>();
11
12     for _ in (-42..=-21).rev() {}
13     for _ in (21u32..42u32).rev() {}
14
15     // These should be ignored as they are not empty ranges:
16
17     (21..=42).for_each(|x| println!("{}", x));
18     (21..42).for_each(|x| println!("{}", x));
19
20     let arr = [1, 2, 3, 4, 5];
21     let _ = &arr[1..=3];
22     let _ = &arr[1..3];
23
24     for _ in 21..=42 {}
25     for _ in 21..42 {}
26
27     // This range is empty but should be ignored, see issue #5689
28     let _ = &arr[0..0];
29 }