@@ -235,6 +235,16 @@ impl Type {
235
235
}
236
236
}
237
237
238
+ fn can_derive_copy ( & self ) -> bool {
239
+ !self . is_opaque ( ) && match * self {
240
+ TVoid => false ,
241
+ TArray ( ref t, _, _) => t. can_derive_copy ( ) ,
242
+ TNamed ( ref ti) => ti. borrow ( ) . ty . can_derive_copy ( ) ,
243
+ TComp ( ref comp) => comp. borrow ( ) . can_derive_copy ( ) ,
244
+ _ => true ,
245
+ }
246
+ }
247
+
238
248
pub fn is_opaque ( & self ) -> bool {
239
249
match * self {
240
250
TArray ( ref t, _, _) => t. is_opaque ( ) ,
@@ -475,7 +485,7 @@ impl CompInfo {
475
485
// not having destructor.
476
486
//
477
487
// This is unfortunate, but...
478
- ! self . args . is_empty ( ) ||
488
+ self . args . iter ( ) . any ( |t| t . has_destructor ( ) ) ||
479
489
self . members . iter ( ) . enumerate ( ) . any ( |( index, m) | match * m {
480
490
CompMember :: Field ( ref f) |
481
491
CompMember :: CompField ( _, ref f) => {
@@ -492,6 +502,33 @@ impl CompInfo {
492
502
}
493
503
}
494
504
505
+ // We only
506
+ pub fn can_derive_copy ( & self ) -> bool {
507
+ match self . kind {
508
+ CompKind :: Union => true ,
509
+ CompKind :: Struct => {
510
+ if self . has_destructor ( ) {
511
+ return false ;
512
+ }
513
+
514
+ // Anything not destructible and with template parameters
515
+ // is copiable
516
+ if self . args . is_empty ( ) {
517
+ return true ;
518
+ }
519
+
520
+ // With template args, use a safe subset of the types,
521
+ // since copyability depends on the types itself.
522
+ self . ref_template . as_ref ( ) . map_or ( true , |t| t. can_derive_copy ( ) ) &&
523
+ self . members . iter ( ) . all ( |m| match * m {
524
+ CompMember :: Field ( ref f) |
525
+ CompMember :: CompField ( _, ref f) => f. ty . can_derive_copy ( ) ,
526
+ _ => true ,
527
+ } )
528
+ }
529
+ }
530
+ }
531
+
495
532
pub fn is_translatable ( & self ) -> bool {
496
533
match self . kind {
497
534
CompKind :: Union => true ,
@@ -504,7 +541,7 @@ impl CompInfo {
504
541
505
542
impl fmt:: Debug for CompInfo {
506
543
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
507
- self . name . fmt ( f )
544
+ write ! ( f , "CompInfo({}, ref: {:?}, args: {:?}, members: {:?}" , self . name, self . ref_template , self . args , self . members )
508
545
}
509
546
}
510
547
0 commit comments