@@ -3,6 +3,7 @@ mod double_neg;
33mod literal_suffix;
44mod mixed_case_hex_literals;
55mod redundant_pattern;
6+ mod redundant_rest_pattern;
67mod unneeded_field_pattern;
78mod unneeded_wildcard_pattern;
89mod zero_prefixed_literal;
@@ -318,6 +319,34 @@ declare_clippy_lint! {
318319 "tuple patterns with a wildcard pattern (`_`) is next to a rest pattern (`..`)"
319320}
320321
322+ declare_clippy_lint ! {
323+ /// ### What it does
324+ /// Checks for `[all @ ..]` patterns.
325+ ///
326+ /// ### Why is this bad?
327+ /// In all cases, `all` works fine and can often make code simpler, as you possibly won't need
328+ /// to convert from say a `Vec` to a slice by dereferencing.
329+ ///
330+ /// ### Example
331+ /// ```rust,ignore
332+ /// if let [all @ ..] = &*v {
333+ /// // NOTE: Type is a slice here
334+ /// println!("all elements: {all:#?}");
335+ /// }
336+ /// ```
337+ /// Use instead:
338+ /// ```rust,ignore
339+ /// if let all = v {
340+ /// // NOTE: Type is a `Vec` here
341+ /// println!("all elements: {all:#?}");
342+ /// }
343+ /// ```
344+ #[ clippy:: version = "1.72.0" ]
345+ pub REDUNDANT_REST_PATTERN ,
346+ complexity,
347+ "checks for `[all @ ..]` where `all` would suffice"
348+ }
349+
321350declare_lint_pass ! ( MiscEarlyLints => [
322351 UNNEEDED_FIELD_PATTERN ,
323352 DUPLICATE_UNDERSCORE_ARGUMENT ,
@@ -329,6 +358,7 @@ declare_lint_pass!(MiscEarlyLints => [
329358 BUILTIN_TYPE_SHADOW ,
330359 REDUNDANT_PATTERN ,
331360 UNNEEDED_WILDCARD_PATTERN ,
361+ REDUNDANT_REST_PATTERN ,
332362] ) ;
333363
334364impl EarlyLintPass for MiscEarlyLints {
@@ -345,6 +375,7 @@ impl EarlyLintPass for MiscEarlyLints {
345375
346376 unneeded_field_pattern:: check ( cx, pat) ;
347377 redundant_pattern:: check ( cx, pat) ;
378+ redundant_rest_pattern:: check ( cx, pat) ;
348379 unneeded_wildcard_pattern:: check ( cx, pat) ;
349380 }
350381
0 commit comments