Skip to content

Commit a569023

Browse files
committed
Make fixed length vecs implicitly copyable. Clean up some other kind code. Closes #2629
1 parent 999ab54 commit a569023

File tree

1 file changed

+18
-24
lines changed

1 file changed

+18
-24
lines changed

src/rustc/middle/ty.rs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,13 +1387,8 @@ fn kind_top() -> kind {
13871387
kind_(0xffffffffu32)
13881388
}
13891389

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()
13971392
}
13981393

13991394
fn remove_implicit(k: kind) -> kind {
@@ -1475,10 +1470,11 @@ fn test_kinds() {
14751470
// Return the most permissive kind that a composite object containing a field
14761471
// with the given mutability can have.
14771472
// 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.
14791474
fn mutability_kind(m: mutability) -> kind {
14801475
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()) }
14821478
m_imm { kind_top() }
14831479
}
14841480
}
@@ -1528,18 +1524,18 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
15281524
// Unique boxes and vecs have the kind of their contained type,
15291525
// but unique boxes can't be implicitly copyable.
15301526
ty_uniq(tm) {
1531-
remove_implicit(remove_const(type_kind(cx, tm.ty), tm))
1527+
remove_implicit(mutable_type_kind(cx, tm))
15321528
}
15331529
// Implicit copyability of vecs is configurable
15341530
ty_vec(tm) {
1535-
let k = if cx.vecs_implicitly_copyable {
1531+
if cx.vecs_implicitly_copyable {
15361532
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)) }
15391534
}
15401535

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.
15431539
ty_evec(tm, vstore_box) |
15441540
ty_evec(tm, vstore_slice(_)) {
15451541
if kind_lteq(kind_const(), type_kind(cx, tm.ty)) {
@@ -1549,23 +1545,24 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
15491545
kind_implicitly_copyable()
15501546
}
15511547
}
1552-
ty_evec(tm, vstore_uniq) |
1548+
ty_evec(tm, vstore_uniq) {
1549+
remove_implicit(mutable_type_kind(cx, tm))
1550+
}
15531551
ty_evec(tm, vstore_fixed(_)) {
1554-
remove_implicit(remove_const(type_kind(cx, tm.ty), tm))
1552+
mutable_type_kind(cx, tm)
15551553
}
15561554

15571555
// All estrs are copyable; uniques and interiors are sendable.
15581556
ty_estr(vstore_box) |
15591557
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() }
15621560

15631561
// Records lower to the lowest of their members.
15641562
ty_rec(flds) {
15651563
let mut lowest = kind_top();
15661564
for flds.each {|f|
15671565
lowest = lower_kind(lowest, mutable_type_kind(cx, f.mt));
1568-
lowest = remove_const(lowest, f.mt);
15691566
}
15701567
lowest
15711568
}
@@ -1614,10 +1611,7 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
16141611
(kind_const() & type_kind(cx, inner)) | kind_send_only()
16151612
}
16161613
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))
16211615
}
16221616
ty_constr(t, _) { type_kind(cx, t) }
16231617
// FIXME: is self ever const?

0 commit comments

Comments
 (0)