Skip to content

False-positive in redundant_pattern lint. #4428

Closed
@ghost

Description

The nightly slice_patterns feature (see https://doc.rust-lang.org/nightly/unstable-book/language-features/slice-patterns.html) introduces the syntax .. which matches any leftover elements in the slice, versus the _ for a single item in stable Rust.

Clippy's redundant_pattern lint checks for variable @ _ and correctly recommends it be changed to plain variable. However, there is (currently) no shorter syntax for variable @ .. in patterns, and the recommendation to change it to variable is incorrect and changes the meaning. There is also a cosmetic error in that it gives the binding as _ rather than ...

I am using the latest nightly clippy ("clippy 0.0.212 (cd3df6b 2019-08-20)") and this is one example of the cascade of warnings it gives when choking on my parser library:

warning: the `stream @ _` pattern can be written as just `stream`
   --> src/bencode.rs:321:20
    |
321 |             [b'l', stream @ ..] => decode_list(stream).map(wrap),
    |                    ^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern

(In case it's not obvious, this is within a match { ... } block.)

The desired behaviour is for Clippy is to not treat .. as equivalent to _ in patterns, because it isn't. Perhaps it was at some point in the evolution of this feature, but it isn't now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesL-suggestionLint: Improving, adding or fixing lint suggestionsgood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions