@@ -45,6 +45,7 @@ export field_idx;
45
45
export get_field;
46
46
export get_fields;
47
47
export get_element_type;
48
+ export has_dtor;
48
49
export is_binopable;
49
50
export is_pred_ty;
50
51
export lookup_class_field, lookup_class_fields;
@@ -1288,7 +1289,7 @@ fn type_needs_unwind_cleanup_(cx: ctxt, ty: t,
1288
1289
1289
1290
enum kind { kind_( u32 ) }
1290
1291
1291
- // *ALL* implicity copiable things must be copiable
1292
+ // *ALL* implicitly copiable things must be copiable
1292
1293
const KIND_MASK_COPY : u32 = 0b00000000000000000000000000000001u32 ;
1293
1294
const KIND_MASK_SEND : u32 = 0b00000000000000000000000000000010u32 ;
1294
1295
const KIND_MASK_CONST : u32 = 0b00000000000000000000000000000100u32 ;
@@ -1495,15 +1496,20 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
1495
1496
}
1496
1497
lowest
1497
1498
}
1498
- // FIXME: (tjc) there are rules about when classes are copyable/
1499
- // sendable, but I'm just treating them like records (#1726)
1500
1499
ty_class( did, substs) {
1500
+ // Classes are sendable if all their fields are sendable,
1501
+ // likewise for copyable...
1501
1502
// also factor out this code, copied from the records case
1502
1503
let mut lowest = kind_top( ) ;
1503
1504
let flds = class_items_as_fields( cx, did, substs) ;
1504
1505
for flds. each { |f|
1505
1506
lowest = lower_kind( lowest, mutable_type_kind( cx, f. mt) ) ;
1506
1507
}
1508
+ // ...but classes with dtors are never copyable (they can be
1509
+ // sendable)
1510
+ if ty:: has_dtor( cx, did) {
1511
+ lowest = lower_kind( lowest, kind_noncopyable( ) ) ;
1512
+ }
1507
1513
lowest
1508
1514
}
1509
1515
// Tuples lower to the lowest of their members.
@@ -2562,6 +2568,10 @@ fn ty_dtor(cx: ctxt, class_id: def_id) -> option<def_id> {
2562
2568
}
2563
2569
}
2564
2570
2571
+ fn has_dtor( cx: ctxt, class_id: def_id) -> bool {
2572
+ option:: is_some( ty_dtor( cx, class_id) )
2573
+ }
2574
+
2565
2575
fn item_path( cx: ctxt, id: ast:: def_id) -> ast_map:: path {
2566
2576
if id. crate != ast:: local_crate {
2567
2577
csearch:: get_item_path( cx, id)
0 commit comments