1
1
// check-pass
2
- // compile-flags: -Zunpretty=expanded
3
2
// edition:2021
3
+ // revisions: check unpretty
4
+ // [unpretty] compile-flags: -Zunpretty=expanded
4
5
//
5
6
// This test checks the code generated for all[*] the builtin derivable traits
6
7
// on a variety of structs and enums. It protects against accidental changes to
14
15
// also require the `rustc_serialize` crate.
15
16
16
17
#![ crate_type = "lib" ]
17
- #![ allow( dead_code) ]
18
- #![ allow( deprecated) ]
18
+ #![ warn( unused) ] // test that lints are not triggerred in derived code
19
19
20
20
// Empty struct.
21
21
#[ derive( Clone , Copy , Debug , Default , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
22
- struct Empty ;
22
+ pub struct Empty ;
23
23
24
24
// A basic struct.
25
25
#[ derive( Clone , Copy , Debug , Default , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
26
- struct Point {
26
+ pub struct Point {
27
27
x : u32 ,
28
28
y : u32 ,
29
29
}
30
30
31
31
// A large struct.
32
32
#[ derive( Clone , Debug , Default , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
33
- struct Big {
33
+ pub struct Big {
34
34
b1 : u32 , b2 : u32 , b3 : u32 , b4 : u32 , b5 : u32 , b6 : u32 , b7 : u32 , b8 : u32 ,
35
35
}
36
36
37
37
// A struct with an unsized field. Some derives are not usable in this case.
38
38
#[ derive( Debug , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
39
- struct Unsized ( [ u32 ] ) ;
39
+ pub struct Unsized ( [ u32 ] ) ;
40
40
41
41
// A packed tuple struct that impls `Copy`.
42
42
#[ derive( Clone , Copy , Debug , Default , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
43
43
#[ repr( packed) ]
44
- struct PackedCopy ( u32 ) ;
44
+ pub struct PackedCopy ( u32 ) ;
45
45
46
46
// A packed tuple struct that does not impl `Copy`. Note that the alignment of
47
47
// the field must be 1 for this code to be valid. Otherwise it triggers an
@@ -50,28 +50,28 @@ struct PackedCopy(u32);
50
50
// it's possible that this struct is not supposed to work, but for now it does.
51
51
#[ derive( Clone , Debug , Default , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
52
52
#[ repr( packed) ]
53
- struct PackedNonCopy ( u8 ) ;
53
+ pub struct PackedNonCopy ( u8 ) ;
54
54
55
55
// An empty enum.
56
56
#[ derive( Clone , Copy , Debug , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
57
- enum Enum0 { }
57
+ pub enum Enum0 { }
58
58
59
59
// A single-variant enum.
60
60
#[ derive( Clone , Debug , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
61
- enum Enum1 {
61
+ pub enum Enum1 {
62
62
Single { x : u32 }
63
63
}
64
64
65
65
// A C-like, fieldless enum with a single variant.
66
66
#[ derive( Clone , Debug , Default , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
67
- enum Fieldless1 {
67
+ pub enum Fieldless1 {
68
68
#[ default]
69
69
A ,
70
70
}
71
71
72
72
// A C-like, fieldless enum.
73
73
#[ derive( Clone , Copy , Debug , Default , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
74
- enum Fieldless {
74
+ pub enum Fieldless {
75
75
#[ default]
76
76
A ,
77
77
B ,
@@ -80,7 +80,7 @@ enum Fieldless {
80
80
81
81
// An enum with multiple fieldless and fielded variants.
82
82
#[ derive( Clone , Copy , Debug , Default , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
83
- enum Mixed {
83
+ pub enum Mixed {
84
84
#[ default]
85
85
P ,
86
86
Q ,
@@ -91,7 +91,7 @@ enum Mixed {
91
91
// An enum with no fieldless variants. Note that `Default` cannot be derived
92
92
// for this enum.
93
93
#[ derive( Clone , Debug , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
94
- enum Fielded {
94
+ pub enum Fielded {
95
95
X ( u32 ) ,
96
96
Y ( bool ) ,
97
97
Z ( Option < i32 > ) ,
@@ -104,3 +104,20 @@ pub union Union {
104
104
pub u : u32 ,
105
105
pub i : i32 ,
106
106
}
107
+
108
+ #[ derive( Clone , Copy , Debug , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
109
+ pub enum Void { }
110
+
111
+ #[ derive( Clone , Copy , Debug , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
112
+ pub struct WithUninhabited {
113
+ x : u32 ,
114
+ v : Void ,
115
+ y : u32 ,
116
+ }
117
+
118
+ #[ derive( Clone , Copy , Debug , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
119
+ pub enum EnumWithUninhabited {
120
+ A ( u32 ) ,
121
+ B ( Void ) ,
122
+ C ( u16 ) ,
123
+ }
0 commit comments