Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 484c82e

Browse files
committed
Update lint declaration
1 parent 589d7e1 commit 484c82e

File tree

1 file changed

+9
-3
lines changed
  • clippy_lints/src/methods

1 file changed

+9
-3
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3193,21 +3193,27 @@ declare_clippy_lint! {
31933193

31943194
declare_clippy_lint! {
31953195
/// ### What it does
3196+
/// Checks for usage of `.drain(..)` for the sole purpose of clearing a `Vec`.
31963197
///
31973198
/// ### Why is this bad?
3199+
/// This creates an unnecessary iterator that is dropped immediately.
3200+
///
3201+
/// Calling `.clear()` also makes the intent clearer.
31983202
///
31993203
/// ### Example
32003204
/// ```rust
3201-
/// // example code where clippy issues a warning
3205+
/// let mut v = vec![1, 2, 3];
3206+
/// v.drain(..);
32023207
/// ```
32033208
/// Use instead:
32043209
/// ```rust
3205-
/// // example code which does not raise clippy warning
3210+
/// let mut v = vec![1, 2, 3];
3211+
/// v.clear();
32063212
/// ```
32073213
#[clippy::version = "1.69.0"]
32083214
pub CLEAR_WITH_DRAIN,
32093215
nursery,
3210-
"default lint description"
3216+
"calling `drain` in order to `clear` a `Vec`"
32113217
}
32123218

32133219
pub struct Methods {

0 commit comments

Comments
 (0)