1
Fork 0

Consider slices to be a structural type. Closes #2748.

This commit is contained in:
Michael Sullivan 2012-07-05 14:38:38 -07:00
parent 7babcf55d7
commit b0d4f09201
4 changed files with 23 additions and 4 deletions

View file

@ -1369,7 +1369,7 @@ fn copy_val_no_check(bcx: block, action: copy_action, dst: ValueRef,
let _icx = bcx.insn_ctxt("copy_val_no_check");
let ccx = bcx.ccx();
let mut bcx = bcx;
if ty::type_is_scalar(t) || ty::type_is_slice(t) {
if ty::type_is_scalar(t) {
Store(bcx, src, dst);
ret bcx;
}
@ -1401,7 +1401,7 @@ fn move_val(cx: block, action: copy_action, dst: ValueRef,
let mut src_val = src.val;
let tcx = cx.tcx();
let mut cx = cx;
if ty::type_is_scalar(t) || ty::type_is_slice(t) {
if ty::type_is_scalar(t) {
if src.kind == owned { src_val = Load(cx, src_val); }
Store(cx, src_val, dst);
ret cx;

View file

@ -1074,8 +1074,10 @@ fn type_is_bool(ty: t) -> bool { get(ty).struct == ty_bool }
fn type_is_structural(ty: t) -> bool {
alt get(ty).struct {
ty_rec(_) | ty_class(*) | ty_tup(_) | ty_enum(*) | ty_fn(_) |
ty_trait(*) | ty_evec(_, vstore_fixed(_))
| ty_estr(vstore_fixed(_)) { true }
ty_trait(*) |
ty_evec(_, vstore_fixed(_)) | ty_estr(vstore_fixed(_)) |
ty_evec(_, vstore_slice(_)) | ty_estr(vstore_slice(_))
{ true }
_ { false }
}
}

View file

@ -0,0 +1,9 @@
class CMap/& {
let buf: [u8]/&;
new(buf: [u8]/&) {
self.buf = buf;
}
}
fn main() { }

View file

@ -0,0 +1,8 @@
fn thing(x: &[int]) -> &[int] { x }
fn main() {
let x = &[1,2,3];
let y = x;
let z = thing(x);
assert(z[2] == x[2]);
assert(z[1] == y[1]);
}