mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 13:43:17 +00:00
57 lines
1 KiB
Rust
57 lines
1 KiB
Rust
// run-rustfix
|
|
#![warn(clippy::reversed_empty_ranges)]
|
|
|
|
fn main() {
|
|
const MAX_LEN: usize = 42;
|
|
|
|
for i in 10..0 {
|
|
println!("{}", i);
|
|
}
|
|
|
|
for i in 10..=0 {
|
|
println!("{}", i);
|
|
}
|
|
|
|
for i in MAX_LEN..0 {
|
|
println!("{}", i);
|
|
}
|
|
|
|
for i in 5..=5 {
|
|
// not an error, this is the range with only one element “5”
|
|
println!("{}", i);
|
|
}
|
|
|
|
for i in 0..10 {
|
|
// not an error, the start index is less than the end index
|
|
println!("{}", i);
|
|
}
|
|
|
|
for i in -10..0 {
|
|
// not an error
|
|
println!("{}", i);
|
|
}
|
|
|
|
for i in (10..0).map(|x| x * 2) {
|
|
println!("{}", i);
|
|
}
|
|
|
|
// testing that the empty range lint folds constants
|
|
for i in 10..5 + 4 {
|
|
println!("{}", i);
|
|
}
|
|
|
|
for i in (5 + 2)..(3 - 1) {
|
|
println!("{}", i);
|
|
}
|
|
|
|
for i in (2 * 2)..(2 * 3) {
|
|
// no error, 4..6 is fine
|
|
println!("{}", i);
|
|
}
|
|
|
|
let x = 42;
|
|
for i in x..10 {
|
|
// no error, not constant-foldable
|
|
println!("{}", i);
|
|
}
|
|
}
|