提交 b0d4f092 编写于 作者: M Michael Sullivan

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

上级 7babcf55
......@@ -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;
......
......@@ -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 }
}
}
......
class CMap/& {
let buf: [u8]/&;
new(buf: [u8]/&) {
self.buf = buf;
}
}
fn main() { }
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]);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册