Consider slices to be a structural type. Closes #2748.
This commit is contained in:
parent
7babcf55d7
commit
b0d4f09201
4 changed files with 23 additions and 4 deletions
|
@ -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 }
|
||||
}
|
||||
}
|
||||
|
|
9
src/test/run-pass/issue-2748-a.rs
Normal file
9
src/test/run-pass/issue-2748-a.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
class CMap/& {
|
||||
let buf: [u8]/&;
|
||||
|
||||
new(buf: [u8]/&) {
|
||||
self.buf = buf;
|
||||
}
|
||||
}
|
||||
|
||||
fn main() { }
|
8
src/test/run-pass/issue-2748-b.rs
Normal file
8
src/test/run-pass/issue-2748-b.rs
Normal 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]);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue