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