]>
Commit | Line | Data |
---|---|---|
f20569fa XL |
1 | #![warn(clippy::rest_pat_in_fully_bound_structs)] |
2 | ||
3 | struct A { | |
4 | a: i32, | |
5 | b: i64, | |
6 | c: &'static str, | |
7 | } | |
8 | ||
9 | macro_rules! foo { | |
10 | ($param:expr) => { | |
11 | match $param { | |
12 | A { a: 0, b: 0, c: "", .. } => {}, | |
13 | _ => {}, | |
14 | } | |
15 | }; | |
16 | } | |
17 | ||
18 | fn main() { | |
19 | let a_struct = A { a: 5, b: 42, c: "A" }; | |
20 | ||
21 | match a_struct { | |
22 | A { a: 5, b: 42, c: "", .. } => {}, // Lint | |
781aab86 FG |
23 | //~^ ERROR: unnecessary use of `..` pattern in struct binding. All fields were alr |
24 | A { a: 0, b: 0, c: "", .. } => {}, // Lint | |
25 | //~^ ERROR: unnecessary use of `..` pattern in struct binding. All fields were alr | |
f20569fa XL |
26 | _ => {}, |
27 | } | |
28 | ||
29 | match a_struct { | |
30 | A { a: 5, b: 42, .. } => {}, | |
31 | A { a: 0, b: 0, c: "", .. } => {}, // Lint | |
781aab86 | 32 | //~^ ERROR: unnecessary use of `..` pattern in struct binding. All fields were alr |
f20569fa XL |
33 | _ => {}, |
34 | } | |
35 | ||
36 | // No lint | |
37 | match a_struct { | |
38 | A { a: 5, .. } => {}, | |
39 | A { a: 0, b: 0, .. } => {}, | |
40 | _ => {}, | |
41 | } | |
42 | ||
43 | // No lint | |
44 | foo!(a_struct); | |
04454e1e FG |
45 | |
46 | #[non_exhaustive] | |
47 | struct B { | |
48 | a: u32, | |
49 | b: u32, | |
50 | c: u64, | |
51 | } | |
52 | ||
53 | let b_struct = B { a: 5, b: 42, c: 342 }; | |
54 | ||
55 | match b_struct { | |
56 | B { a: 5, b: 42, .. } => {}, | |
57 | B { a: 0, b: 0, c: 128, .. } => {}, // No Lint | |
58 | _ => {}, | |
59 | } | |
f20569fa | 60 | } |