1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
#![warn(clippy::manual_non_exhaustive)]
#![allow(unused)]
//@no-rustfix
pub mod structs {
pub struct S {
//~^ manual_non_exhaustive
pub a: i32,
pub b: i32,
_c: (),
}
// user forgot to remove the private field
#[non_exhaustive]
pub struct Sp {
//~^ manual_non_exhaustive
pub a: i32,
pub b: i32,
_c: (),
}
// some other fields are private, should be ignored
pub struct PrivateFields {
a: i32,
pub b: i32,
_c: (),
}
pub struct NoUnderscore {
//~^ manual_non_exhaustive
pub a: i32,
pub b: i32,
c: (),
}
// private field is not unit type, should be ignored
pub struct NotUnit {
pub a: i32,
pub b: i32,
_c: i32,
}
// private field is the only field, should be ignored
pub struct OnlyMarker {
_a: (),
}
// already non exhaustive and no private fields, should be ignored
#[non_exhaustive]
pub struct NonExhaustive {
pub a: i32,
pub b: i32,
}
}
pub mod tuple_structs {
pub struct T(pub i32, pub i32, ());
//~^ manual_non_exhaustive
// user forgot to remove the private field
#[non_exhaustive]
pub struct Tp(pub i32, pub i32, ());
//~^ manual_non_exhaustive
// some other fields are private, should be ignored
pub struct PrivateFields(pub i32, i32, ());
// private field is not unit type, should be ignored
pub struct NotUnit(pub i32, pub i32, i32);
// private field is the only field, should be ignored
pub struct OnlyMarker(());
// already non exhaustive and no private fields, should be ignored
#[non_exhaustive]
pub struct NonExhaustive(pub i32, pub i32);
}
mod private {
// Don't lint structs that are not actually public as `#[non_exhaustive]` only applies to
// external crates. The manual pattern can still be used to get module local non exhaustiveness
pub struct NotPublic {
pub a: i32,
pub b: i32,
_c: (),
}
}
|