Skip to content

Commit

Permalink
Add tests with usize::MIN
Browse files Browse the repository at this point in the history
  • Loading branch information
bluthej committed Mar 26, 2023
1 parent 2493be2 commit 3966580
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
12 changes: 12 additions & 0 deletions tests/ui/clear_with_drain.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ fn range() {
let mut v = vec![1, 2, 3];
let n = v.drain(0..v.len()).count(); // Yay

let mut v = vec![1, 2, 3];
let n = v.drain(usize::MIN..v.len()).count(); // Yay

let mut v = vec![1, 2, 3];
v.clear(); // Nay

let mut v = vec![1, 2, 3];
v.clear(); // Nay
}
Expand All @@ -20,6 +26,12 @@ fn range_from() {
let mut v = vec![1, 2, 3];
let next = v.drain(0..).next(); // Yay

let mut v = vec![1, 2, 3];
let next = v.drain(usize::MIN..).next(); // Yay

let mut v = vec![1, 2, 3];
v.clear(); // Nay

let mut v = vec![1, 2, 3];
v.clear(); // Nay
}
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/clear_with_drain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ fn range() {
let mut v = vec![1, 2, 3];
let n = v.drain(0..v.len()).count(); // Yay

let mut v = vec![1, 2, 3];
let n = v.drain(usize::MIN..v.len()).count(); // Yay

let mut v = vec![1, 2, 3];
v.drain(0..v.len()); // Nay

let mut v = vec![1, 2, 3];
v.drain(usize::MIN..v.len()); // Nay
}

fn range_from() {
Expand All @@ -20,8 +26,14 @@ fn range_from() {
let mut v = vec![1, 2, 3];
let next = v.drain(0..).next(); // Yay

let mut v = vec![1, 2, 3];
let next = v.drain(usize::MIN..).next(); // Yay

let mut v = vec![1, 2, 3];
v.drain(0..); // Nay

let mut v = vec![1, 2, 3];
v.drain(usize::MIN..); // Nay
}

fn range_full() {
Expand Down
22 changes: 17 additions & 5 deletions tests/ui/clear_with_drain.stderr
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
error: `drain` used to clear a `Vec`
--> $DIR/clear_with_drain.rs:13:7
--> $DIR/clear_with_drain.rs:16:7
|
LL | v.drain(0..v.len()); // Nay
| ^^^^^^^^^^^^^^^^^ help: try: `clear()`
|
= note: `-D clippy::clear-with-drain` implied by `-D warnings`

error: `drain` used to clear a `Vec`
--> $DIR/clear_with_drain.rs:24:7
--> $DIR/clear_with_drain.rs:19:7
|
LL | v.drain(usize::MIN..v.len()); // Nay
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `clear()`

error: `drain` used to clear a `Vec`
--> $DIR/clear_with_drain.rs:33:7
|
LL | v.drain(0..); // Nay
| ^^^^^^^^^^ help: try: `clear()`

error: `drain` used to clear a `Vec`
--> $DIR/clear_with_drain.rs:38:7
--> $DIR/clear_with_drain.rs:36:7
|
LL | v.drain(usize::MIN..); // Nay
| ^^^^^^^^^^^^^^^^^^^ help: try: `clear()`

error: `drain` used to clear a `Vec`
--> $DIR/clear_with_drain.rs:50:7
|
LL | v.drain(..); // Nay
| ^^^^^^^^^ help: try: `clear()`

error: `drain` used to clear a `Vec`
--> $DIR/clear_with_drain.rs:52:7
--> $DIR/clear_with_drain.rs:64:7
|
LL | v.drain(..v.len()); // Nay
| ^^^^^^^^^^^^^^^^ help: try: `clear()`

error: aborting due to 4 previous errors
error: aborting due to 6 previous errors

0 comments on commit 3966580

Please sign in to comment.