-
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 #5258 - ThibsG:UselessBindingInStruct638, r=flip1995
Add lint for .. use in fully binded struct This PR adds the lint `match-wild-in-fully-binded-struct` to prevent the use of the `..` pattern when all fields of the struct are already binded. Fixes: #638 changelog: Add [`rest_pat_in_fully_bound_structs`] lint to warn against the use of `..` in fully binded struct
- Loading branch information
Showing
7 changed files
with
124 additions
and
5 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,30 @@ | ||
#![warn(clippy::rest_pat_in_fully_bound_structs)] | ||
|
||
struct A { | ||
a: i32, | ||
b: i64, | ||
c: &'static str, | ||
} | ||
|
||
fn main() { | ||
let a_struct = A { a: 5, b: 42, c: "A" }; | ||
|
||
match a_struct { | ||
A { a: 5, b: 42, c: "", .. } => {}, // Lint | ||
A { a: 0, b: 0, c: "", .. } => {}, // Lint | ||
_ => {}, | ||
} | ||
|
||
match a_struct { | ||
A { a: 5, b: 42, .. } => {}, | ||
A { a: 0, b: 0, c: "", .. } => {}, // Lint | ||
_ => {}, | ||
} | ||
|
||
// No lint | ||
match a_struct { | ||
A { a: 5, .. } => {}, | ||
A { a: 0, b: 0, .. } => {}, | ||
_ => {}, | ||
} | ||
} |
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,27 @@ | ||
error: unnecessary use of `..` pattern in struct binding. All fields were already bound | ||
--> $DIR/rest_pat_in_fully_bound_structs.rs:13:9 | ||
| | ||
LL | A { a: 5, b: 42, c: "", .. } => {}, // Lint | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `-D clippy::rest-pat-in-fully-bound-structs` implied by `-D warnings` | ||
= help: consider removing `..` from this binding | ||
|
||
error: unnecessary use of `..` pattern in struct binding. All fields were already bound | ||
--> $DIR/rest_pat_in_fully_bound_structs.rs:14:9 | ||
| | ||
LL | A { a: 0, b: 0, c: "", .. } => {}, // Lint | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: consider removing `..` from this binding | ||
|
||
error: unnecessary use of `..` pattern in struct binding. All fields were already bound | ||
--> $DIR/rest_pat_in_fully_bound_structs.rs:20:9 | ||
| | ||
LL | A { a: 0, b: 0, c: "", .. } => {}, // Lint | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: consider removing `..` from this binding | ||
|
||
error: aborting due to 3 previous errors | ||
|