73 lines
1.5 KiB
Rust
73 lines
1.5 KiB
Rust
// run-rustfix
|
|
#![allow(unused)]
|
|
#![warn(clippy::clear_with_drain)]
|
|
|
|
fn range() {
|
|
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 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 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 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() {}
|