@@ -88,6 +88,7 @@ mod unwrap_or_else_default;
88
88
mod unwrap_used;
89
89
mod useless_asref;
90
90
mod utils;
91
+ mod vec_resize_to_zero;
91
92
mod wrong_self_convention;
92
93
mod zst_offset;
93
94
@@ -2799,6 +2800,23 @@ declare_clippy_lint! {
2799
2800
"Use of `Vec::sort_by` when `Vec::sort_by_key` or `Vec::sort` would be clearer"
2800
2801
}
2801
2802
2803
+ declare_clippy_lint ! {
2804
+ /// ### What it does
2805
+ /// Finds occurrences of `Vec::resize(0, an_int)`
2806
+ ///
2807
+ /// ### Why is this bad?
2808
+ /// This is probably an argument inversion mistake.
2809
+ ///
2810
+ /// ### Example
2811
+ /// ```rust
2812
+ /// vec!(1, 2, 3, 4, 5).resize(0, 5)
2813
+ /// ```
2814
+ #[ clippy:: version = "1.46.0" ]
2815
+ pub VEC_RESIZE_TO_ZERO ,
2816
+ correctness,
2817
+ "emptying a vector with `resize(0, an_int)` instead of `clear()` is probably an argument inversion mistake"
2818
+ }
2819
+
2802
2820
pub struct Methods {
2803
2821
avoid_breaking_exported_api : bool ,
2804
2822
msrv : Option < RustcVersion > ,
@@ -2915,6 +2933,7 @@ impl_lint_pass!(Methods => [
2915
2933
STABLE_SORT_PRIMITIVE ,
2916
2934
UNIT_HASH ,
2917
2935
UNNECESSARY_SORT_BY ,
2936
+ VEC_RESIZE_TO_ZERO ,
2918
2937
] ) ;
2919
2938
2920
2939
/// Extracts a method call name, args, and `Span` of the method name.
@@ -3305,6 +3324,9 @@ impl Methods {
3305
3324
( "repeat" , [ arg] ) => {
3306
3325
repeat_once:: check ( cx, expr, recv, arg) ;
3307
3326
} ,
3327
+ ( "resize" , [ count_arg, default_arg] ) => {
3328
+ vec_resize_to_zero:: check ( cx, expr, count_arg, default_arg, span) ;
3329
+ } ,
3308
3330
( "sort" , [ ] ) => {
3309
3331
stable_sort_primitive:: check ( cx, expr, recv) ;
3310
3332
} ,
0 commit comments