Skip to content

Commit

Permalink
Consider slices to be a structural type. Closes #2748.
Browse files Browse the repository at this point in the history
  • Loading branch information
msullivan committed Jul 5, 2012
1 parent 7babcf5 commit b0d4f09
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/rustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions src/rustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/test/run-pass/issue-2748-a.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CMap/& {
let buf: [u8]/&;

new(buf: [u8]/&) {
self.buf = buf;
}
}

fn main() { }
8 changes: 8 additions & 0 deletions src/test/run-pass/issue-2748-b.rs
Original file line number Diff line number Diff line change
@@ -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]);
}

0 comments on commit b0d4f09

Please sign in to comment.