2020-05-17 15:36:26 +00:00
|
|
|
#![warn(clippy::reversed_empty_ranges)]
|
|
|
|
|
|
|
|
const ANSWER: i32 = 42;
|
|
|
|
const SOME_NUM: usize = 3;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let arr = [1, 2, 3, 4, 5];
|
|
|
|
let _ = &arr[3usize..=1usize];
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: this range is reversed and using it to index a slice will panic at run-tim
|
|
|
|
//~| NOTE: `-D clippy::reversed-empty-ranges` implied by `-D warnings`
|
2020-05-17 15:36:26 +00:00
|
|
|
let _ = &arr[SOME_NUM..1];
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: this range is reversed and using it to index a slice will panic at run-tim
|
2020-05-17 15:36:26 +00:00
|
|
|
|
|
|
|
for _ in ANSWER..ANSWER {}
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: this range is empty so it will yield no values
|
2020-06-09 14:36:01 +00:00
|
|
|
|
|
|
|
// Should not be linted, see issue #5689
|
|
|
|
let _ = (42 + 10..42 + 10).map(|x| x / 2).find(|&x| x == 21);
|
2020-05-17 15:36:26 +00:00
|
|
|
}
|