File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -3193,21 +3193,27 @@ declare_clippy_lint! {
3193
3193
3194
3194
declare_clippy_lint ! {
3195
3195
/// ### What it does
3196
+ /// Checks for usage of `.drain(..)` for the sole purpose of clearing a `Vec`.
3196
3197
///
3197
3198
/// ### Why is this bad?
3199
+ /// This creates an unnecessary iterator that is dropped immediately.
3200
+ ///
3201
+ /// Calling `.clear()` also makes the intent clearer.
3198
3202
///
3199
3203
/// ### Example
3200
3204
/// ```rust
3201
- /// // example code where clippy issues a warning
3205
+ /// let mut v = vec![1, 2, 3];
3206
+ /// v.drain(..);
3202
3207
/// ```
3203
3208
/// Use instead:
3204
3209
/// ```rust
3205
- /// // example code which does not raise clippy warning
3210
+ /// let mut v = vec![1, 2, 3];
3211
+ /// v.clear();
3206
3212
/// ```
3207
3213
#[ clippy:: version = "1.69.0" ]
3208
3214
pub CLEAR_WITH_DRAIN ,
3209
3215
nursery,
3210
- "default lint description "
3216
+ "calling `drain` in order to `clear` a `Vec` "
3211
3217
}
3212
3218
3213
3219
pub struct Methods {
You can’t perform that action at this time.
0 commit comments