-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add unneeded-wildcard-pattern
lint
#4537
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
Changes from all commits
4a3bc6b
00ca42f
99be522
fed1709
d04bf15
be4e415
ca6d36b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// run-rustfix | ||
#![feature(stmt_expr_attributes)] | ||
#![deny(clippy::unneeded_wildcard_pattern)] | ||
|
||
fn main() { | ||
let t = (0, 1, 2, 3); | ||
|
||
if let (0, ..) = t {}; | ||
if let (0, ..) = t {}; | ||
if let (.., 0) = t {}; | ||
if let (.., 0) = t {}; | ||
if let (0, ..) = t {}; | ||
if let (0, ..) = t {}; | ||
if let (_, 0, ..) = t {}; | ||
if let (.., 0, _) = t {}; | ||
if let (0, _, _, _) = t {}; | ||
if let (0, ..) = t {}; | ||
if let (.., 0) = t {}; | ||
|
||
#[rustfmt::skip] | ||
{ | ||
if let (0, ..,) = t {}; | ||
} | ||
|
||
struct S(usize, usize, usize, usize); | ||
|
||
let s = S(0, 1, 2, 3); | ||
|
||
if let S(0, ..) = s {}; | ||
if let S(0, ..) = s {}; | ||
if let S(.., 0) = s {}; | ||
if let S(.., 0) = s {}; | ||
if let S(0, ..) = s {}; | ||
if let S(0, ..) = s {}; | ||
if let S(_, 0, ..) = s {}; | ||
if let S(.., 0, _) = s {}; | ||
if let S(0, _, _, _) = s {}; | ||
if let S(0, ..) = s {}; | ||
if let S(.., 0) = s {}; | ||
|
||
#[rustfmt::skip] | ||
{ | ||
if let S(0, ..,) = s {}; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// run-rustfix | ||
#![feature(stmt_expr_attributes)] | ||
#![deny(clippy::unneeded_wildcard_pattern)] | ||
|
||
fn main() { | ||
let t = (0, 1, 2, 3); | ||
|
||
if let (0, .., _) = t {}; | ||
if let (0, _, ..) = t {}; | ||
if let (_, .., 0) = t {}; | ||
if let (.., _, 0) = t {}; | ||
if let (0, _, _, ..) = t {}; | ||
if let (0, .., _, _) = t {}; | ||
if let (_, 0, ..) = t {}; | ||
if let (.., 0, _) = t {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It absolutely will. This is the purpose of this lint. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't remember what I had in mind. And I also cannot come up with something. Can you add a test for it though? |
||
if let (0, _, _, _) = t {}; | ||
if let (0, ..) = t {}; | ||
if let (.., 0) = t {}; | ||
|
||
#[rustfmt::skip] | ||
{ | ||
if let (0, .., _, _,) = t {}; | ||
} | ||
|
||
struct S(usize, usize, usize, usize); | ||
|
||
let s = S(0, 1, 2, 3); | ||
|
||
if let S(0, .., _) = s {}; | ||
if let S(0, _, ..) = s {}; | ||
if let S(_, .., 0) = s {}; | ||
if let S(.., _, 0) = s {}; | ||
if let S(0, _, _, ..) = s {}; | ||
if let S(0, .., _, _) = s {}; | ||
if let S(_, 0, ..) = s {}; | ||
if let S(.., 0, _) = s {}; | ||
if let S(0, _, _, _) = s {}; | ||
if let S(0, ..) = s {}; | ||
if let S(.., 0) = s {}; | ||
|
||
#[rustfmt::skip] | ||
{ | ||
if let S(0, .., _, _,) = s {}; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
error: this pattern is unneeded as the `..` pattern can match that element | ||
--> $DIR/unneeded_wildcard_pattern.rs:8:18 | ||
| | ||
LL | if let (0, .., _) = t {}; | ||
| ^^^ help: remove it | ||
| | ||
note: lint level defined here | ||
--> $DIR/unneeded_wildcard_pattern.rs:3:9 | ||
| | ||
LL | #![deny(clippy::unneeded_wildcard_pattern)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: this pattern is unneeded as the `..` pattern can match that element | ||
--> $DIR/unneeded_wildcard_pattern.rs:9:16 | ||
| | ||
LL | if let (0, _, ..) = t {}; | ||
| ^^^ help: remove it | ||
|
||
error: this pattern is unneeded as the `..` pattern can match that element | ||
--> $DIR/unneeded_wildcard_pattern.rs:10:13 | ||
| | ||
LL | if let (_, .., 0) = t {}; | ||
| ^^^ help: remove it | ||
|
||
error: this pattern is unneeded as the `..` pattern can match that element | ||
--> $DIR/unneeded_wildcard_pattern.rs:11:15 | ||
| | ||
LL | if let (.., _, 0) = t {}; | ||
| ^^^ help: remove it | ||
|
||
error: these patterns are unneeded as the `..` pattern can match those elements | ||
--> $DIR/unneeded_wildcard_pattern.rs:12:16 | ||
| | ||
LL | if let (0, _, _, ..) = t {}; | ||
| ^^^^^^ help: remove them | ||
|
||
error: these patterns are unneeded as the `..` pattern can match those elements | ||
--> $DIR/unneeded_wildcard_pattern.rs:13:18 | ||
| | ||
LL | if let (0, .., _, _) = t {}; | ||
| ^^^^^^ help: remove them | ||
|
||
error: these patterns are unneeded as the `..` pattern can match those elements | ||
--> $DIR/unneeded_wildcard_pattern.rs:22:22 | ||
| | ||
LL | if let (0, .., _, _,) = t {}; | ||
| ^^^^^^ help: remove them | ||
|
||
error: this pattern is unneeded as the `..` pattern can match that element | ||
--> $DIR/unneeded_wildcard_pattern.rs:29:19 | ||
| | ||
LL | if let S(0, .., _) = s {}; | ||
| ^^^ help: remove it | ||
|
||
error: this pattern is unneeded as the `..` pattern can match that element | ||
--> $DIR/unneeded_wildcard_pattern.rs:30:17 | ||
| | ||
LL | if let S(0, _, ..) = s {}; | ||
| ^^^ help: remove it | ||
|
||
error: this pattern is unneeded as the `..` pattern can match that element | ||
--> $DIR/unneeded_wildcard_pattern.rs:31:14 | ||
| | ||
LL | if let S(_, .., 0) = s {}; | ||
| ^^^ help: remove it | ||
|
||
error: this pattern is unneeded as the `..` pattern can match that element | ||
--> $DIR/unneeded_wildcard_pattern.rs:32:16 | ||
| | ||
LL | if let S(.., _, 0) = s {}; | ||
| ^^^ help: remove it | ||
|
||
error: these patterns are unneeded as the `..` pattern can match those elements | ||
--> $DIR/unneeded_wildcard_pattern.rs:33:17 | ||
| | ||
LL | if let S(0, _, _, ..) = s {}; | ||
| ^^^^^^ help: remove them | ||
|
||
error: these patterns are unneeded as the `..` pattern can match those elements | ||
--> $DIR/unneeded_wildcard_pattern.rs:34:19 | ||
| | ||
LL | if let S(0, .., _, _) = s {}; | ||
| ^^^^^^ help: remove them | ||
|
||
error: these patterns are unneeded as the `..` pattern can match those elements | ||
--> $DIR/unneeded_wildcard_pattern.rs:43:23 | ||
| | ||
LL | if let S(0, .., _, _,) = s {}; | ||
| ^^^^^^ help: remove them | ||
|
||
error: aborting due to 14 previous errors | ||
|
Uh oh!
There was an error while loading. Please reload this page.