Commit 4814577
authored
Since #16733 (related issue:
#16638) `unneeded_wildcard_pattern` have supported
struct patterns, but this is directly contradictory to the lint
`rest_pattern_accessible_field` introduced in
#15000.
This change disable the `unneeded_wildcard_pattern` check for struct
patterns if the `rest_pattern_accessible_field` lint is enabled.
Example:
```rust
#![allow(unused)]
#![warn(clippy::rest_pattern_accessible_field)]
#![warn(clippy::unneeded_wildcard_pattern)]
fn main() {
struct Struct4 {
a: u32,
b: u32,
c: u32,
d: u32,
}
let fourval = Struct4 {
a: 5,
b: 10,
c: 15,
d: 20,
};
let Struct4 { a, b, c: _, .. } = fourval;
}
```
Before:
```
warning: this pattern is unneeded as the `..` pattern can match that element
--> example.rs:20:25
|
20 | let Struct4 { a, b, c: _, .. } = fourval;
| ^^^^^^ help: remove it
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unneeded_wildcard_pattern
note: the lint level is defined here
--> example.rs:3:9
|
3 | #![warn(clippy::unneeded_wildcard_pattern)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: struct destructuring with rest (`..`)
--> example.rs:20:9
|
20 | let Struct4 { a, b, c: _, .. } = fourval;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#rest_pattern_accessible_field
note: the lint level is defined here
--> example.rs:2:9
|
2 | #![warn(clippy::rest_pattern_accessible_field)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider explicitly ignoring remaining fields with wildcard patterns (`x: _`)
|
20 - let Struct4 { a, b, c: _, .. } = fourval;
20 + let Struct4 { a, b, c: _, d: _ } = fourval;
|
```
After:
```
warning: struct destructuring with rest (`..`)
--> example.rs:20:9
|
20 | let Struct4 { a, b, c: _, .. } = fourval;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#rest_pattern_accessible_field
note: the lint level is defined here
--> example.rs:2:9
|
2 | #![warn(clippy::rest_pattern_accessible_field)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider explicitly ignoring remaining fields with wildcard patterns (`x: _`)
|
20 - let Struct4 { a, b, c: _, .. } = fourval;
20 + let Struct4 { a, b, c: _, d: _ } = fourval;
|
warning: 1 warning emitted
```
changelog: [`unneeded_wildcard_pattern`]: Partly disable when
[`rest_pattern_accessible_field`] is enabled.
3 files changed
Lines changed: 5 additions & 3 deletions
File tree
- clippy_lints/src/misc_early
- tests/ui
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
| 44 | + | |
43 | 45 | | |
44 | 46 | | |
45 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
0 commit comments