mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 07:04:18 +00:00
Finish tests - add rustfix
This commit is contained in:
parent
1d0acce984
commit
e8ec242a61
4 changed files with 69 additions and 2 deletions
|
@ -10,8 +10,6 @@ use rustc_span::Span;
|
|||
|
||||
use super::CLEAR_WITH_DRAIN;
|
||||
|
||||
// TODO: Adjust the parameters as necessary
|
||||
// see clippy_lints/src/methods/mod.rs to add call to this check in `check_methods`
|
||||
pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, span: Span, arg: &Expr<'_>) {
|
||||
let ty = cx.typeck_results().expr_ty(recv);
|
||||
if is_type_diagnostic_item(cx, ty, sym::Vec) && let Some(range) = Range::hir(arg) && is_range_full(cx, recv, range)
|
||||
|
|
40
tests/ui/clear_with_drain.fixed
Normal file
40
tests/ui/clear_with_drain.fixed
Normal file
|
@ -0,0 +1,40 @@
|
|||
// run-rustfix
|
||||
#![allow(unused)]
|
||||
#![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
|
||||
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
|
||||
v.clear(); // Nay
|
||||
}
|
||||
|
||||
fn range_full() {
|
||||
let (mut u, mut v) = (vec![1, 2, 3], vec![1, 2, 3]);
|
||||
let iter = u.drain(..); // Yay
|
||||
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
|
||||
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(..v.len() - 1); // Yay
|
||||
|
||||
let mut v = vec![1, 2, 3];
|
||||
v.drain(1..v.len() - 1); // Yay
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -1,3 +1,4 @@
|
|||
// run-rustfix
|
||||
#![allow(unused)]
|
||||
#![warn(clippy::clear_with_drain)]
|
||||
|
||||
|
|
28
tests/ui/clear_with_drain.stderr
Normal file
28
tests/ui/clear_with_drain.stderr
Normal file
|
@ -0,0 +1,28 @@
|
|||
error: `drain` used to clear a `Vec`
|
||||
--> $DIR/clear_with_drain.rs:8: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:14:7
|
||||
|
|
||||
LL | v.drain(0..); // Nay
|
||||
| ^^^^^^^^^^ help: try: `clear()`
|
||||
|
||||
error: `drain` used to clear a `Vec`
|
||||
--> $DIR/clear_with_drain.rs:20:7
|
||||
|
|
||||
LL | v.drain(..); // Nay
|
||||
| ^^^^^^^^^ help: try: `clear()`
|
||||
|
||||
error: `drain` used to clear a `Vec`
|
||||
--> $DIR/clear_with_drain.rs:26:7
|
||||
|
|
||||
LL | v.drain(..v.len()); // Nay
|
||||
| ^^^^^^^^^^^^^^^^ help: try: `clear()`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
Loading…
Reference in a new issue