提交 3ab86fb7 编写于 作者: B Brian Anderson

Teach rustc to add istrs. Issue #855

上级 aae21272
......@@ -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;
......
......@@ -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();
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册