2023-03-21 21:46:59 +00:00
|
|
|
// run-rustfix
|
2023-03-18 09:43:02 +00:00
|
|
|
#![allow(unused)]
|
|
|
|
#![warn(clippy::clear_with_drain)]
|
|
|
|
|
2023-03-18 13:45:57 +00:00
|
|
|
fn range() {
|
2023-03-23 21:29:30 +00:00
|
|
|
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
|
|
|
|
|
2023-03-26 16:59:20 +00:00
|
|
|
let mut v = vec![1, 2, 3];
|
2023-03-27 09:11:40 +00:00
|
|
|
let iter = v.drain(usize::MIN..v.len()); // Yay
|
|
|
|
let n = iter.count();
|
2023-03-26 16:59:20 +00:00
|
|
|
|
2023-03-23 21:29:30 +00:00
|
|
|
let mut v = vec![1, 2, 3];
|
2023-03-18 13:45:57 +00:00
|
|
|
v.drain(0..v.len()); // Nay
|
2023-03-26 16:59:20 +00:00
|
|
|
|
|
|
|
let mut v = vec![1, 2, 3];
|
|
|
|
v.drain(usize::MIN..v.len()); // Nay
|
2023-03-18 13:45:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn range_from() {
|
2023-03-23 21:29:30 +00:00
|
|
|
let mut v = vec![1, 2, 3];
|
|
|
|
let iter = v.drain(0..); // Yay
|
|
|
|
|
|
|
|
let mut v = vec![1, 2, 3];
|
2023-03-27 09:11:40 +00:00
|
|
|
let mut iter = v.drain(0..); // Yay
|
|
|
|
let next = iter.next();
|
2023-03-23 21:29:30 +00:00
|
|
|
|
2023-03-26 16:59:20 +00:00
|
|
|
let mut v = vec![1, 2, 3];
|
|
|
|
let next = v.drain(usize::MIN..).next(); // Yay
|
|
|
|
|
2023-03-23 21:29:30 +00:00
|
|
|
let mut v = vec![1, 2, 3];
|
2023-03-18 13:45:57 +00:00
|
|
|
v.drain(0..); // Nay
|
2023-03-26 16:59:20 +00:00
|
|
|
|
|
|
|
let mut v = vec![1, 2, 3];
|
|
|
|
v.drain(usize::MIN..); // Nay
|
2023-03-18 13:45:57 +00:00
|
|
|
}
|
2023-03-18 09:43:02 +00:00
|
|
|
|
2023-03-18 13:45:57 +00:00
|
|
|
fn range_full() {
|
2023-03-23 21:29:30 +00:00
|
|
|
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];
|
2023-03-18 13:45:57 +00:00
|
|
|
v.drain(..); // Nay
|
2023-03-18 09:43:02 +00:00
|
|
|
}
|
2023-03-18 13:45:57 +00:00
|
|
|
|
|
|
|
fn range_to() {
|
2023-03-23 21:29:30 +00:00
|
|
|
let mut v = vec![1, 2, 3];
|
|
|
|
let iter = v.drain(..v.len()); // Yay
|
|
|
|
|
|
|
|
let mut v = vec![1, 2, 3];
|
2023-03-27 09:11:40 +00:00
|
|
|
let iter = v.drain(..v.len()); // Yay
|
|
|
|
for x in iter {
|
2023-03-23 21:29:30 +00:00
|
|
|
let y = format!("x = {x}");
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut v = vec![1, 2, 3];
|
2023-03-18 13:45:57 +00:00
|
|
|
v.drain(..v.len()); // Nay
|
|
|
|
}
|
|
|
|
|
2023-03-21 21:09:26 +00:00
|
|
|
fn partial_drains() {
|
|
|
|
let mut v = vec![1, 2, 3];
|
|
|
|
v.drain(1..); // Yay
|
2023-03-23 21:29:30 +00:00
|
|
|
let mut v = vec![1, 2, 3];
|
|
|
|
v.drain(1..).max(); // Yay
|
2023-03-21 21:09:26 +00:00
|
|
|
|
|
|
|
let mut v = vec![1, 2, 3];
|
|
|
|
v.drain(..v.len() - 1); // Yay
|
2023-03-23 21:29:30 +00:00
|
|
|
let mut v = vec![1, 2, 3];
|
|
|
|
v.drain(..v.len() - 1).min(); // Yay
|
2023-03-21 21:09:26 +00:00
|
|
|
|
|
|
|
let mut v = vec![1, 2, 3];
|
|
|
|
v.drain(1..v.len() - 1); // Yay
|
2023-03-23 21:29:30 +00:00
|
|
|
let mut v = vec![1, 2, 3];
|
|
|
|
let w: Vec<i8> = v.drain(1..v.len() - 1).collect(); // Yay
|
2023-03-21 21:09:26 +00:00
|
|
|
}
|
|
|
|
|
2023-03-18 13:45:57 +00:00
|
|
|
fn main() {}
|