@@ -156,37 +156,14 @@ impl<'ctx> CannotDerive<'ctx> {
156
156
157
157
trace ! ( "ty: {:?}" , ty) ;
158
158
if item. is_opaque ( self . ctx , & ( ) ) {
159
- if !self . derive_trait . can_derive_union ( ) &&
160
- ty. is_union ( ) &&
161
- self . ctx . options ( ) . rust_features ( ) . untagged_union
162
- {
163
- trace ! (
164
- " cannot derive {} for Rust unions" ,
165
- self . derive_trait
166
- ) ;
167
- return CanDerive :: No ;
168
- }
169
-
170
- let layout_can_derive =
171
- ty. layout ( self . ctx ) . map_or ( CanDerive :: Yes , |l| {
159
+ let can_derive_opaque = self . derive_trait . can_derive_opaque ( ) ;
160
+ if can_derive_opaque == CanDerive :: Yes {
161
+ return ty. layout ( self . ctx ) . map_or ( can_derive_opaque, |l| {
172
162
l. opaque ( ) . array_size_within_derive_limit ( self . ctx )
173
163
} ) ;
174
-
175
- match layout_can_derive {
176
- CanDerive :: Yes => {
177
- trace ! (
178
- " we can trivially derive {} for the layout" ,
179
- self . derive_trait
180
- ) ;
181
- }
182
- _ => {
183
- trace ! (
184
- " we cannot derive {} for the layout" ,
185
- self . derive_trait
186
- ) ;
187
- }
188
- } ;
189
- return layout_can_derive;
164
+ } else {
165
+ return can_derive_opaque;
166
+ }
190
167
}
191
168
192
169
match * ty. kind ( ) {
@@ -513,6 +490,16 @@ impl DeriveTrait {
513
490
}
514
491
}
515
492
493
+ fn can_derive_opaque ( & self ) -> CanDerive {
494
+ match self {
495
+ DeriveTrait :: Copy |
496
+ DeriveTrait :: Hash |
497
+ DeriveTrait :: PartialEqOrPartialOrd => CanDerive :: No ,
498
+ DeriveTrait :: Default => CanDerive :: Yes ,
499
+ DeriveTrait :: Debug => CanDerive :: Manually ,
500
+ }
501
+ }
502
+
516
503
fn can_derive_fnptr ( & self , f : & FunctionSig ) -> CanDerive {
517
504
match ( self , f. function_pointers_can_derive ( ) ) {
518
505
( DeriveTrait :: Copy , _) | ( DeriveTrait :: Default , _) | ( _, true ) => {
0 commit comments