@@ -101,69 +101,22 @@ pub fn build_ord_signature(item: &Item, trait_: &DeriveTrait, body: &TokenStream
101
101
_ => unreachable ! ( "unsupported trait in `prepare_ord`" ) ,
102
102
} ;
103
103
104
- // Nightly or unsafe (default) implementation.
105
- #[ cfg( any( feature = "nightly" , not( feature = "safe" ) ) ) ]
106
- {
107
- // Nightly implementation.
108
- #[ cfg( feature = "nightly" ) ]
109
- quote ! {
110
- #incomparable
111
-
112
- let __self_disc = :: core:: intrinsics:: discriminant_value( self ) ;
113
- let __other_disc = :: core:: intrinsics:: discriminant_value( __other) ;
114
-
115
- if __self_disc == __other_disc {
116
- #body_equal
117
- } else {
118
- #path:: #method( & __self_disc, & __other_disc)
119
- }
120
- }
121
- // Unsafe (default) implementation.
122
- #[ cfg( not( feature = "nightly" ) ) ]
123
- {
124
- let body_else = match discriminant {
125
- Discriminant :: Single => unreachable ! (
126
- "we should only generate this code with multiple variants"
127
- ) ,
128
- Discriminant :: UnitDefault => quote ! {
129
- #path:: #method(
130
- self as isize ,
131
- __other as isize ,
132
- )
133
- } ,
134
- Discriminant :: Default => {
135
- build_recursive_order ( trait_, variants, & incomparable)
136
- }
137
- Discriminant :: UnitRepr ( repr) => quote ! {
138
- #path:: #method(
139
- self as #repr,
140
- __other as #repr,
141
- )
142
- } ,
143
- Discriminant :: Repr ( repr) => quote ! {
144
- #path:: #method(
145
- unsafe { * <* const _>:: from( self ) . cast:: <#repr>( ) } ,
146
- unsafe { * <* const _>:: from( __other) . cast:: <#repr>( ) } ,
147
- )
148
- } ,
149
- } ;
150
-
151
- quote ! {
152
- #incomparable
104
+ // Nightly implementation.
105
+ #[ cfg( feature = "nightly" ) ]
106
+ quote ! {
107
+ #incomparable
153
108
154
- let __self_disc = :: core:: mem :: discriminant ( self ) ;
155
- let __other_disc = :: core:: mem :: discriminant ( __other) ;
109
+ let __self_disc = :: core:: intrinsics :: discriminant_value ( self ) ;
110
+ let __other_disc = :: core:: intrinsics :: discriminant_value ( __other) ;
156
111
157
- if __self_disc == __other_disc {
158
- #body_equal
159
- } else {
160
- #body_else
161
- }
162
- }
112
+ if __self_disc == __other_disc {
113
+ #body_equal
114
+ } else {
115
+ #path:: #method( & __self_disc, & __other_disc)
163
116
}
164
117
}
165
- // Safe implementation when not on nightly.
166
- #[ cfg( all ( not( feature = "nightly" ) , feature = "safe ") ) ]
118
+
119
+ #[ cfg( not( feature = "nightly" ) ) ]
167
120
{
168
121
let body_else = match discriminant {
169
122
Discriminant :: Single => {
@@ -175,15 +128,26 @@ pub fn build_ord_signature(item: &Item, trait_: &DeriveTrait, body: &TokenStream
175
128
__other as isize ,
176
129
)
177
130
} ,
131
+ Discriminant :: Default => {
132
+ build_recursive_order ( trait_, variants, & incomparable)
133
+ }
178
134
Discriminant :: UnitRepr ( repr) => quote ! {
179
135
#path:: #method(
180
136
self as #repr,
181
137
__other as #repr,
182
138
)
183
139
} ,
184
- Discriminant :: Default | Discriminant :: Repr ( _) => {
185
- build_recursive_order ( trait_, variants, & incomparable)
140
+ #[ cfg( not( feature = "safe" ) ) ]
141
+ Discriminant :: Repr ( repr) => {
142
+ quote ! {
143
+ #path:: #method(
144
+ unsafe { * <* const _>:: from( self ) . cast:: <#repr>( ) } ,
145
+ unsafe { * <* const _>:: from( __other) . cast:: <#repr>( ) } ,
146
+ )
147
+ }
186
148
}
149
+ #[ cfg( feature = "safe" ) ]
150
+ Discriminant :: Repr ( _) => build_recursive_order ( trait_, variants, & incomparable) ,
187
151
} ;
188
152
189
153
quote ! {
0 commit comments