-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #4960 - ThibsG:patterns_with_wildcard_#4640, r=flip1995
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.
- Loading branch information
Showing
10 changed files
with
145 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#![warn(clippy::wildcard_in_or_patterns)] | ||
|
||
fn main() { | ||
match "foo" { | ||
"a" => { | ||
dbg!("matched a"); | ||
}, | ||
"bar" | _ => { | ||
dbg!("matched (bar or) wild"); | ||
}, | ||
}; | ||
match "foo" { | ||
"a" => { | ||
dbg!("matched a"); | ||
}, | ||
"bar" | "bar2" | _ => { | ||
dbg!("matched (bar or bar2 or) wild"); | ||
}, | ||
}; | ||
match "foo" { | ||
"a" => { | ||
dbg!("matched a"); | ||
}, | ||
_ | "bar" | _ => { | ||
dbg!("matched (bar or) wild"); | ||
}, | ||
}; | ||
match "foo" { | ||
"a" => { | ||
dbg!("matched a"); | ||
}, | ||
_ | "bar" => { | ||
dbg!("matched (bar or) wild"); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
error: wildcard pattern covers any other pattern as it will match anyway. | ||
--> $DIR/wild_in_or_pats.rs:8:9 | ||
| | ||
LL | "bar" | _ => { | ||
| ^^^^^^^^^ | ||
| | ||
= note: `-D clippy::wildcard-in-or-patterns` implied by `-D warnings` | ||
= help: Consider handling `_` separately. | ||
|
||
error: wildcard pattern covers any other pattern as it will match anyway. | ||
--> $DIR/wild_in_or_pats.rs:16:9 | ||
| | ||
LL | "bar" | "bar2" | _ => { | ||
| ^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: Consider handling `_` separately. | ||
|
||
error: wildcard pattern covers any other pattern as it will match anyway. | ||
--> $DIR/wild_in_or_pats.rs:24:9 | ||
| | ||
LL | _ | "bar" | _ => { | ||
| ^^^^^^^^^^^^^ | ||
| | ||
= help: Consider handling `_` separately. | ||
|
||
error: wildcard pattern covers any other pattern as it will match anyway. | ||
--> $DIR/wild_in_or_pats.rs:32:9 | ||
| | ||
LL | _ | "bar" => { | ||
| ^^^^^^^^^ | ||
| | ||
= help: Consider handling `_` separately. | ||
|
||
error: aborting due to 4 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters