Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False-positive in redundant_pattern lint. #4428

Closed
ghost opened this issue Aug 21, 2019 · 0 comments · Fixed by #4489
Closed

False-positive in redundant_pattern lint. #4428

ghost opened this issue Aug 21, 2019 · 0 comments · Fixed by #4489
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@ghost
Copy link

ghost commented Aug 21, 2019

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.

@flip1995 flip1995 added L-suggestion Lint: Improving, adding or fixing lint suggestions good-first-issue These issues are a good way to get started with Clippy C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages labels Aug 26, 2019
@bors bors closed this as completed in 313b41f Sep 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant