Teach rustc to add istrs. Issue #855

This commit is contained in:
Brian Anderson 2011-08-22 16:39:18 -07:00
parent aae212727d
commit 3ab86fb79e
2 changed files with 33 additions and 2 deletions

View File

@ -494,6 +494,16 @@ fn trans_add(cx: &@block_ctxt, vec_ty: ty::t, lhs: ValueRef,
let lhs_len = lhs_len_and_data.len;
let lhs_data = lhs_len_and_data.data;
bcx = lhs_len_and_data.bcx;
lhs_len = alt ty::struct(bcx_tcx(bcx), vec_ty) {
ty::ty_istr. {
// Forget about the trailing null on the left side
bcx.build.Sub(lhs_len, C_uint(1u))
}
ty::ty_vec(_) { lhs_len }
_ { bcx_tcx(bcx).sess.bug("non-istr/ivec in trans_add") }
};
let rhs_len_and_data = get_len_and_data(bcx, rhs, unit_ty);
let rhs_len = rhs_len_and_data.len;
let rhs_data = rhs_len_and_data.data;

View File

@ -12,8 +12,11 @@ fn test_heap_lit() {
}
fn test_heap_assign() {
let s: istr;
s = ~"AAAA";
let s: istr = ~"a big ol' string";
let t: istr = ~"a big ol' string";
assert s == t;
let u: istr = ~"a bad ol' string";
assert s != u;
}
fn test_heap_log() {
@ -21,9 +24,27 @@ fn test_heap_log() {
log s;
}
fn test_stack_add() {
assert ~"a" + ~"b" == ~"ab";
let s: istr = ~"a";
assert s + s == ~"aa";
assert ~"" + ~"" == ~"";
}
fn test_stack_heap_add() {
assert ~"a" + ~"bracadabra" == ~"abracadabra";
}
fn test_heap_add() {
assert ~"this should" + ~" totally work" == ~"this should totally work";
}
fn main() {
test_stack_assign();
test_heap_lit();
test_heap_assign();
test_heap_log();
test_stack_add();
test_stack_heap_add();
test_heap_add();
}