]> git.lizzy.rs Git - rust.git/blob - tests/ui/manual_non_exhaustive_struct.rs
Move MSRV tests into the lint specific test files
[rust.git] / tests / ui / manual_non_exhaustive_struct.rs
1 #![warn(clippy::manual_non_exhaustive)]
2 #![allow(unused)]
3
4 mod structs {
5     struct S {
6         pub a: i32,
7         pub b: i32,
8         _c: (),
9     }
10
11     // user forgot to remove the private field
12     #[non_exhaustive]
13     struct Sp {
14         pub a: i32,
15         pub b: i32,
16         _c: (),
17     }
18
19     // some other fields are private, should be ignored
20     struct PrivateFields {
21         a: i32,
22         pub b: i32,
23         _c: (),
24     }
25
26     // private field name does not start with underscore, should be ignored
27     struct NoUnderscore {
28         pub a: i32,
29         pub b: i32,
30         c: (),
31     }
32
33     // private field is not unit type, should be ignored
34     struct NotUnit {
35         pub a: i32,
36         pub b: i32,
37         _c: i32,
38     }
39
40     // private field is the only field, should be ignored
41     struct OnlyMarker {
42         _a: (),
43     }
44
45     // already non exhaustive and no private fields, should be ignored
46     #[non_exhaustive]
47     struct NonExhaustive {
48         pub a: i32,
49         pub b: i32,
50     }
51 }
52
53 mod tuple_structs {
54     struct T(pub i32, pub i32, ());
55
56     // user forgot to remove the private field
57     #[non_exhaustive]
58     struct Tp(pub i32, pub i32, ());
59
60     // some other fields are private, should be ignored
61     struct PrivateFields(pub i32, i32, ());
62
63     // private field is not unit type, should be ignored
64     struct NotUnit(pub i32, pub i32, i32);
65
66     // private field is the only field, should be ignored
67     struct OnlyMarker(());
68
69     // already non exhaustive and no private fields, should be ignored
70     #[non_exhaustive]
71     struct NonExhaustive(pub i32, pub i32);
72 }
73
74 fn main() {}