mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 07:04:18 +00:00
Add some tests
This commit is contained in:
parent
1d168b31c3
commit
ee0de538d4
3 changed files with 84 additions and 20 deletions
|
@ -3,38 +3,70 @@
|
|||
#![warn(clippy::clear_with_drain)]
|
||||
|
||||
fn range() {
|
||||
let (mut u, mut v) = (vec![1, 2, 3], vec![1, 2, 3]);
|
||||
let iter = u.drain(0..u.len()); // Yay
|
||||
let mut v = vec![1, 2, 3];
|
||||
let iter = v.drain(0..v.len()); // Yay
|
||||
|
||||
let mut v = vec![1, 2, 3];
|
||||
let n = v.drain(0..v.len()).count(); // Yay
|
||||
|
||||
let mut v = vec![1, 2, 3];
|
||||
v.clear(); // Nay
|
||||
}
|
||||
|
||||
fn range_from() {
|
||||
let (mut u, mut v) = (vec![1, 2, 3], vec![1, 2, 3]);
|
||||
let iter = u.drain(0..); // Yay
|
||||
let mut v = vec![1, 2, 3];
|
||||
let iter = v.drain(0..); // Yay
|
||||
|
||||
let mut v = vec![1, 2, 3];
|
||||
let next = v.drain(0..).next(); // Yay
|
||||
|
||||
let mut v = vec![1, 2, 3];
|
||||
v.clear(); // Nay
|
||||
}
|
||||
|
||||
fn range_full() {
|
||||
let (mut u, mut v) = (vec![1, 2, 3], vec![1, 2, 3]);
|
||||
let iter = u.drain(..); // Yay
|
||||
let mut v = vec![1, 2, 3];
|
||||
let iter = v.drain(..); // Yay
|
||||
|
||||
let mut v = vec![1, 2, 3];
|
||||
// Yay
|
||||
for x in v.drain(..) {
|
||||
let y = format!("x = {x}");
|
||||
}
|
||||
|
||||
let mut v = vec![1, 2, 3];
|
||||
v.clear(); // Nay
|
||||
}
|
||||
|
||||
fn range_to() {
|
||||
let (mut u, mut v) = (vec![1, 2, 3], vec![1, 2, 3]);
|
||||
let iter = u.drain(..u.len()); // Yay
|
||||
let mut v = vec![1, 2, 3];
|
||||
let iter = v.drain(..v.len()); // Yay
|
||||
|
||||
let mut v = vec![1, 2, 3];
|
||||
// Yay
|
||||
for x in v.drain(..v.len()) {
|
||||
let y = format!("x = {x}");
|
||||
}
|
||||
|
||||
let mut v = vec![1, 2, 3];
|
||||
v.clear(); // Nay
|
||||
}
|
||||
|
||||
fn partial_drains() {
|
||||
let mut v = vec![1, 2, 3];
|
||||
v.drain(1..); // Yay
|
||||
let mut v = vec![1, 2, 3];
|
||||
v.drain(1..).max(); // Yay
|
||||
|
||||
let mut v = vec![1, 2, 3];
|
||||
v.drain(..v.len() - 1); // Yay
|
||||
let mut v = vec![1, 2, 3];
|
||||
v.drain(..v.len() - 1).min(); // Yay
|
||||
|
||||
let mut v = vec![1, 2, 3];
|
||||
v.drain(1..v.len() - 1); // Yay
|
||||
let mut v = vec![1, 2, 3];
|
||||
let w: Vec<i8> = v.drain(1..v.len() - 1).collect(); // Yay
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -3,38 +3,70 @@
|
|||
#![warn(clippy::clear_with_drain)]
|
||||
|
||||
fn range() {
|
||||
let (mut u, mut v) = (vec![1, 2, 3], vec![1, 2, 3]);
|
||||
let iter = u.drain(0..u.len()); // Yay
|
||||
let mut v = vec![1, 2, 3];
|
||||
let iter = v.drain(0..v.len()); // Yay
|
||||
|
||||
let mut v = vec![1, 2, 3];
|
||||
let n = v.drain(0..v.len()).count(); // Yay
|
||||
|
||||
let mut v = vec![1, 2, 3];
|
||||
v.drain(0..v.len()); // Nay
|
||||
}
|
||||
|
||||
fn range_from() {
|
||||
let (mut u, mut v) = (vec![1, 2, 3], vec![1, 2, 3]);
|
||||
let iter = u.drain(0..); // Yay
|
||||
let mut v = vec![1, 2, 3];
|
||||
let iter = v.drain(0..); // Yay
|
||||
|
||||
let mut v = vec![1, 2, 3];
|
||||
let next = v.drain(0..).next(); // Yay
|
||||
|
||||
let mut v = vec![1, 2, 3];
|
||||
v.drain(0..); // Nay
|
||||
}
|
||||
|
||||
fn range_full() {
|
||||
let (mut u, mut v) = (vec![1, 2, 3], vec![1, 2, 3]);
|
||||
let iter = u.drain(..); // Yay
|
||||
let mut v = vec![1, 2, 3];
|
||||
let iter = v.drain(..); // Yay
|
||||
|
||||
let mut v = vec![1, 2, 3];
|
||||
// Yay
|
||||
for x in v.drain(..) {
|
||||
let y = format!("x = {x}");
|
||||
}
|
||||
|
||||
let mut v = vec![1, 2, 3];
|
||||
v.drain(..); // Nay
|
||||
}
|
||||
|
||||
fn range_to() {
|
||||
let (mut u, mut v) = (vec![1, 2, 3], vec![1, 2, 3]);
|
||||
let iter = u.drain(..u.len()); // Yay
|
||||
let mut v = vec![1, 2, 3];
|
||||
let iter = v.drain(..v.len()); // Yay
|
||||
|
||||
let mut v = vec![1, 2, 3];
|
||||
// Yay
|
||||
for x in v.drain(..v.len()) {
|
||||
let y = format!("x = {x}");
|
||||
}
|
||||
|
||||
let mut v = vec![1, 2, 3];
|
||||
v.drain(..v.len()); // Nay
|
||||
}
|
||||
|
||||
fn partial_drains() {
|
||||
let mut v = vec![1, 2, 3];
|
||||
v.drain(1..); // Yay
|
||||
let mut v = vec![1, 2, 3];
|
||||
v.drain(1..).max(); // Yay
|
||||
|
||||
let mut v = vec![1, 2, 3];
|
||||
v.drain(..v.len() - 1); // Yay
|
||||
let mut v = vec![1, 2, 3];
|
||||
v.drain(..v.len() - 1).min(); // Yay
|
||||
|
||||
let mut v = vec![1, 2, 3];
|
||||
v.drain(1..v.len() - 1); // Yay
|
||||
let mut v = vec![1, 2, 3];
|
||||
let w: Vec<i8> = v.drain(1..v.len() - 1).collect(); // Yay
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error: `drain` used to clear a `Vec`
|
||||
--> $DIR/clear_with_drain.rs:8:7
|
||||
--> $DIR/clear_with_drain.rs:13:7
|
||||
|
|
||||
LL | v.drain(0..v.len()); // Nay
|
||||
| ^^^^^^^^^^^^^^^^^ help: try: `clear()`
|
||||
|
@ -7,19 +7,19 @@ LL | v.drain(0..v.len()); // Nay
|
|||
= note: `-D clippy::clear-with-drain` implied by `-D warnings`
|
||||
|
||||
error: `drain` used to clear a `Vec`
|
||||
--> $DIR/clear_with_drain.rs:14:7
|
||||
--> $DIR/clear_with_drain.rs:24:7
|
||||
|
|
||||
LL | v.drain(0..); // Nay
|
||||
| ^^^^^^^^^^ help: try: `clear()`
|
||||
|
||||
error: `drain` used to clear a `Vec`
|
||||
--> $DIR/clear_with_drain.rs:20:7
|
||||
--> $DIR/clear_with_drain.rs:38:7
|
||||
|
|
||||
LL | v.drain(..); // Nay
|
||||
| ^^^^^^^^^ help: try: `clear()`
|
||||
|
||||
error: `drain` used to clear a `Vec`
|
||||
--> $DIR/clear_with_drain.rs:26:7
|
||||
--> $DIR/clear_with_drain.rs:52:7
|
||||
|
|
||||
LL | v.drain(..v.len()); // Nay
|
||||
| ^^^^^^^^^^^^^^^^ help: try: `clear()`
|
||||
|
|
Loading…
Reference in a new issue