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

Unneeded multiple pattern with wildcard #4640

Closed
ghost opened this issue Oct 7, 2019 · 3 comments · Fixed by #4960
Closed

Unneeded multiple pattern with wildcard #4640

ghost opened this issue Oct 7, 2019 · 3 comments · Fixed by #4960
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-complexity Lint: Belongs in the complexity lint group L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@ghost
Copy link

ghost commented Oct 7, 2019

Any multiple patterns with the wildcard pattern can be removed as the wildcard will match anyway

match "foo" {
    "a" => {
        dbg!("matched a");
    }
    "bar" | _ => {
        dbg!("bar or wildcat");
    }
}

Should be written as

match "foo" {
    "a" => {
        dbg!("matched a");
    }
    _ => {
        dbg!("matched (bar or) wildcard");
    }
}

cc #1272

@flip1995 flip1995 added L-complexity Lint: Belongs in the complexity lint group L-suggestion Lint: Improving, adding or fixing lint suggestions good-first-issue These issues are a good way to get started with Clippy A-lint Area: New lints labels Oct 8, 2019
@Anubhav007
Copy link

In which file do we need to change this?

@ghost
Copy link
Author

ghost commented Oct 8, 2019

looking at this PR #1273 , I guess clippy_lints/src/copies.rs

@flip1995
Copy link
Member

flip1995 commented Oct 9, 2019

I'd recommend to put this in clippy_lints/src/matches.rs

bors added a commit that referenced this issue Jan 7, 2020
New lint: pats_with_wild_match_arm

Wildcard use with other pattern in same match arm.

The wildcard covers other(s) pattern(s) as it will match anyway.

Changelog: add new lint when multiple patterns (including wildcard) are used in a match arm.

Fixes #4640.
@bors bors closed this as completed in ac795a6 Jan 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-complexity Lint: Belongs in the complexity lint group L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants