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! {
31933193
31943194declare_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
32133219pub struct Methods {
You can’t perform that action at this time.
0 commit comments