@@ -1387,13 +1387,8 @@ fn kind_top() -> kind {
1387
1387
kind_( 0xffffffffu32 )
1388
1388
}
1389
1389
1390
- fn remove_const( k: kind, tm: mt) -> kind {
1391
- if tm. mutbl == ast:: m_mutbl {
1392
- k - kind_const( )
1393
- }
1394
- else {
1395
- k
1396
- }
1390
+ fn remove_const( k: kind) -> kind {
1391
+ k - kind_const( )
1397
1392
}
1398
1393
1399
1394
fn remove_implicit( k: kind) -> kind {
@@ -1475,10 +1470,11 @@ fn test_kinds() {
1475
1470
// Return the most permissive kind that a composite object containing a field
1476
1471
// with the given mutability can have.
1477
1472
// This is used to prevent objects containing mutable state from being
1478
- // implicitly copied.
1473
+ // implicitly copied and to compute whether things have const kind .
1479
1474
fn mutability_kind( m: mutability) -> kind {
1480
1475
alt ( m) {
1481
- m_mutbl | m_const { remove_implicit( kind_top( ) ) }
1476
+ m_mutbl { remove_const( remove_implicit( kind_top( ) ) ) }
1477
+ m_const { remove_implicit( kind_top( ) ) }
1482
1478
m_imm { kind_top( ) }
1483
1479
}
1484
1480
}
@@ -1528,18 +1524,18 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
1528
1524
// Unique boxes and vecs have the kind of their contained type,
1529
1525
// but unique boxes can't be implicitly copyable.
1530
1526
ty_uniq( tm) {
1531
- remove_implicit( remove_const ( type_kind ( cx , tm . ty ) , tm) )
1527
+ remove_implicit( mutable_type_kind ( cx , tm) )
1532
1528
}
1533
1529
// Implicit copyability of vecs is configurable
1534
1530
ty_vec( tm) {
1535
- let k = if cx. vecs_implicitly_copyable {
1531
+ if cx. vecs_implicitly_copyable {
1536
1532
mutable_type_kind( cx, tm)
1537
- } else { remove_implicit( type_kind( cx, tm. ty) ) } ;
1538
- remove_const( k, tm)
1533
+ } else { remove_implicit( mutable_type_kind( cx, tm) ) }
1539
1534
}
1540
1535
1541
- // Slice and refcounted evecs are copyable; uniques and interiors
1542
- // depend on the their contained type, but aren't implicitly copyable.
1536
+ // Slices, refcounted evecs are copyable; uniques depend on the their
1537
+ // contained type, but aren't implicitly copyable. Fixed vectors have
1538
+ // the kind of the element they contain, taking mutability into account.
1543
1539
ty_evec( tm, vstore_box) |
1544
1540
ty_evec( tm, vstore_slice( _) ) {
1545
1541
if kind_lteq( kind_const( ) , type_kind( cx, tm. ty) ) {
@@ -1549,23 +1545,24 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
1549
1545
kind_implicitly_copyable( )
1550
1546
}
1551
1547
}
1552
- ty_evec( tm, vstore_uniq) |
1548
+ ty_evec( tm, vstore_uniq) {
1549
+ remove_implicit( mutable_type_kind( cx, tm) )
1550
+ }
1553
1551
ty_evec( tm, vstore_fixed( _) ) {
1554
- remove_implicit ( remove_const ( type_kind ( cx, tm. ty ) , tm ) )
1552
+ mutable_type_kind ( cx, tm)
1555
1553
}
1556
1554
1557
1555
// All estrs are copyable; uniques and interiors are sendable.
1558
1556
ty_estr( vstore_box) |
1559
1557
ty_estr( vstore_slice( _) ) { kind_implicitly_copyable( ) | kind_const( ) }
1560
- ty_estr( vstore_uniq) |
1561
- ty_estr( vstore_fixed( _) ) { kind_sendable ( ) | kind_const( ) }
1558
+ ty_estr( vstore_uniq) { kind_sendable ( ) | kind_const ( ) }
1559
+ ty_estr( vstore_fixed( _) ) { kind_implicitly_sendable ( ) | kind_const( ) }
1562
1560
1563
1561
// Records lower to the lowest of their members.
1564
1562
ty_rec( flds) {
1565
1563
let mut lowest = kind_top( ) ;
1566
1564
for flds. each { |f|
1567
1565
lowest = lower_kind( lowest, mutable_type_kind( cx, f. mt) ) ;
1568
- lowest = remove_const( lowest, f. mt) ;
1569
1566
}
1570
1567
lowest
1571
1568
}
@@ -1614,10 +1611,7 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
1614
1611
( kind_const( ) & type_kind( cx, inner) ) | kind_send_only( )
1615
1612
}
1616
1613
ty_param( _, did) {
1617
- // FIXME: type params shouldn't be implicitly copyable (#2449)
1618
- let k = param_bounds_to_kind( cx. ty_param_bounds. get( did. node) ) ;
1619
- if kind_can_be_copied( k)
1620
- { raise_kind( k, kind_implicitly_copyable( ) ) } else { k }
1614
+ param_bounds_to_kind( cx. ty_param_bounds. get( did. node) )
1621
1615
}
1622
1616
ty_constr( t, _) { type_kind( cx, t) }
1623
1617
// FIXME: is self ever const?
0 commit comments