-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-add old tests for empty range loops
- Loading branch information
Showing
5 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// run-rustfix | ||
#![warn(clippy::reversed_empty_ranges)] | ||
|
||
fn main() { | ||
const MAX_LEN: usize = 42; | ||
|
||
for i in (0..10).rev() { | ||
println!("{}", i); | ||
} | ||
|
||
for i in (0..=10).rev() { | ||
println!("{}", i); | ||
} | ||
|
||
for i in (0..MAX_LEN).rev() { | ||
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 (0..10).rev().map(|x| x * 2) { | ||
println!("{}", i); | ||
} | ||
|
||
// testing that the empty range lint folds constants | ||
for i in (5 + 4..10).rev() { | ||
println!("{}", i); | ||
} | ||
|
||
for i in ((3 - 1)..(5 + 2)).rev() { | ||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
error: this range is empty so it will yield no values | ||
--> $DIR/reversed_empty_ranges_loops_fixable.rs:7:14 | ||
| | ||
LL | for i in 10..0 { | ||
| ^^^^^ | ||
| | ||
= note: `-D clippy::reversed-empty-ranges` implied by `-D warnings` | ||
help: consider using the following if you are attempting to iterate over this range in reverse | ||
| | ||
LL | for i in (0..10).rev() { | ||
| ^^^^^^^^^^^^^ | ||
|
||
error: this range is empty so it will yield no values | ||
--> $DIR/reversed_empty_ranges_loops_fixable.rs:11:14 | ||
| | ||
LL | for i in 10..=0 { | ||
| ^^^^^^ | ||
| | ||
help: consider using the following if you are attempting to iterate over this range in reverse | ||
| | ||
LL | for i in (0..=10).rev() { | ||
| ^^^^^^^^^^^^^^ | ||
|
||
error: this range is empty so it will yield no values | ||
--> $DIR/reversed_empty_ranges_loops_fixable.rs:15:14 | ||
| | ||
LL | for i in MAX_LEN..0 { | ||
| ^^^^^^^^^^ | ||
| | ||
help: consider using the following if you are attempting to iterate over this range in reverse | ||
| | ||
LL | for i in (0..MAX_LEN).rev() { | ||
| ^^^^^^^^^^^^^^^^^^ | ||
|
||
error: this range is empty so it will yield no values | ||
--> $DIR/reversed_empty_ranges_loops_fixable.rs:34:14 | ||
| | ||
LL | for i in (10..0).map(|x| x * 2) { | ||
| ^^^^^^^ | ||
| | ||
help: consider using the following if you are attempting to iterate over this range in reverse | ||
| | ||
LL | for i in (0..10).rev().map(|x| x * 2) { | ||
| ^^^^^^^^^^^^^ | ||
|
||
error: this range is empty so it will yield no values | ||
--> $DIR/reversed_empty_ranges_loops_fixable.rs:39:14 | ||
| | ||
LL | for i in 10..5 + 4 { | ||
| ^^^^^^^^^ | ||
| | ||
help: consider using the following if you are attempting to iterate over this range in reverse | ||
| | ||
LL | for i in (5 + 4..10).rev() { | ||
| ^^^^^^^^^^^^^^^^^ | ||
|
||
error: this range is empty so it will yield no values | ||
--> $DIR/reversed_empty_ranges_loops_fixable.rs:43:14 | ||
| | ||
LL | for i in (5 + 2)..(3 - 1) { | ||
| ^^^^^^^^^^^^^^^^ | ||
| | ||
help: consider using the following if you are attempting to iterate over this range in reverse | ||
| | ||
LL | for i in ((3 - 1)..(5 + 2)).rev() { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 6 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#![warn(clippy::reversed_empty_ranges)] | ||
|
||
fn main() { | ||
for i in 5..5 { | ||
println!("{}", i); | ||
} | ||
|
||
for i in (5 + 2)..(8 - 1) { | ||
println!("{}", i); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
error: this range is empty so it will yield no values | ||
--> $DIR/reversed_empty_ranges_loops_unfixable.rs:4:14 | ||
| | ||
LL | for i in 5..5 { | ||
| ^^^^ | ||
| | ||
= note: `-D clippy::reversed-empty-ranges` implied by `-D warnings` | ||
|
||
error: this range is empty so it will yield no values | ||
--> $DIR/reversed_empty_ranges_loops_unfixable.rs:8:14 | ||
| | ||
LL | for i in (5 + 2)..(8 - 1) { | ||
| ^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|