Rust

Rust

Made by DeepSource

Unneeded wildcard pattern RS-C1004

Anti-pattern
Minor
Autofix

In tuple or struct patterns, zero or more "remaining" elements can be discarded using the rest (..) pattern and exactly one element can be discarded using the wildcard pattern (_). This checker looks for wildcard patterns next to a rest pattern. The wildcard is unnecessary because the rest pattern can match that element as well.

While _, .. means that there is at least one element left, and .. means there are zero or more elements left, it makes little sense to keep the wildcard pattern since it is essentially unused.

Bad practice

struct Point(i32, i32, i32);
let t = (1, 2, 3);
match t {
    Point(0, .., _) => (),
    _ => (),
}

Recommended

struct Point(i32, i32, i32);
let t = (1, 2, 3);
match t {
    Point(0, ..) => (),
    _ => (),
}