mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-21 04:03:11 +00:00
Create clear_with_drain
lint
This commit is contained in:
parent
6cebe58dfe
commit
7f44530f54
@ -4441,6 +4441,7 @@ Released 2018-09-13
|
||||
[`chars_last_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#chars_last_cmp
|
||||
[`chars_next_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#chars_next_cmp
|
||||
[`checked_conversions`]: https://rust-lang.github.io/rust-clippy/master/index.html#checked_conversions
|
||||
[`clear_with_drain`]: https://rust-lang.github.io/rust-clippy/master/index.html#clear_with_drain
|
||||
[`clone_double_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#clone_double_ref
|
||||
[`clone_on_copy`]: https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy
|
||||
[`clone_on_ref_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_ref_ptr
|
||||
|
@ -307,6 +307,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
|
||||
crate::methods::CASE_SENSITIVE_FILE_EXTENSION_COMPARISONS_INFO,
|
||||
crate::methods::CHARS_LAST_CMP_INFO,
|
||||
crate::methods::CHARS_NEXT_CMP_INFO,
|
||||
crate::methods::CLEAR_WITH_DRAIN_INFO,
|
||||
crate::methods::CLONED_INSTEAD_OF_COPIED_INFO,
|
||||
crate::methods::CLONE_DOUBLE_REF_INFO,
|
||||
crate::methods::CLONE_ON_COPY_INFO,
|
||||
|
8
clippy_lints/src/methods/clear_with_drain.rs
Normal file
8
clippy_lints/src/methods/clear_with_drain.rs
Normal file
@ -0,0 +1,8 @@
|
||||
use rustc_lint::{LateContext, LintContext};
|
||||
|
||||
use super::CLEAR_WITH_DRAIN;
|
||||
|
||||
// TODO: Adjust the parameters as necessary
|
||||
pub(super) fn check(cx: &LateContext) {
|
||||
todo!();
|
||||
}
|
@ -9,6 +9,7 @@ mod chars_last_cmp;
|
||||
mod chars_last_cmp_with_unwrap;
|
||||
mod chars_next_cmp;
|
||||
mod chars_next_cmp_with_unwrap;
|
||||
mod clear_with_drain;
|
||||
mod clone_on_copy;
|
||||
mod clone_on_ref_ptr;
|
||||
mod cloned_instead_of_copied;
|
||||
@ -3190,6 +3191,25 @@ declare_clippy_lint! {
|
||||
"single command line argument that looks like it should be multiple arguments"
|
||||
}
|
||||
|
||||
declare_clippy_lint! {
|
||||
/// ### What it does
|
||||
///
|
||||
/// ### Why is this bad?
|
||||
///
|
||||
/// ### Example
|
||||
/// ```rust
|
||||
/// // example code where clippy issues a warning
|
||||
/// ```
|
||||
/// Use instead:
|
||||
/// ```rust
|
||||
/// // example code which does not raise clippy warning
|
||||
/// ```
|
||||
#[clippy::version = "1.69.0"]
|
||||
pub CLEAR_WITH_DRAIN,
|
||||
nursery,
|
||||
"default lint description"
|
||||
}
|
||||
|
||||
pub struct Methods {
|
||||
avoid_breaking_exported_api: bool,
|
||||
msrv: Msrv,
|
||||
@ -3318,6 +3338,7 @@ impl_lint_pass!(Methods => [
|
||||
SEEK_TO_START_INSTEAD_OF_REWIND,
|
||||
NEEDLESS_COLLECT,
|
||||
SUSPICIOUS_COMMAND_ARG_SPACE,
|
||||
CLEAR_WITH_DRAIN,
|
||||
]);
|
||||
|
||||
/// Extracts a method call name, args, and `Span` of the method name.
|
||||
|
12
tests/ui/clear_with_drain.rs
Normal file
12
tests/ui/clear_with_drain.rs
Normal file
@ -0,0 +1,12 @@
|
||||
#![allow(unused)]
|
||||
#![warn(clippy::clear_with_drain)]
|
||||
|
||||
fn main() {
|
||||
let mut vec: Vec<i32> = Vec::new();
|
||||
//Lint
|
||||
vec.drain(..);
|
||||
vec.drain(0..vec.len());
|
||||
|
||||
// Dont Lint
|
||||
let iter = vec.drain(..);
|
||||
}
|
Loading…
Reference in New Issue
Block a user