Allow pattern-matching on any strings, not just unique strings

r=brson

Closes #3574
This commit is contained in:
Tim Chevalier 2012-12-10 21:08:49 -08:00
parent f675b97ddc
commit 01c0971172
2 changed files with 13 additions and 4 deletions

View File

@ -951,8 +951,18 @@ fn compare_values(cx: block, lhs: ValueRef, rhs: ValueRef, rhs_t: ty::t) ->
scratch_result.val));
return scratch_result.to_result(bcx);
}
ty::ty_estr(_) => {
let scratch_result = scratch_datum(cx, ty::mk_bool(cx.tcx()),
false);
let did = cx.tcx().lang_items.str_eq_fn.get();
let bcx = callee::trans_rtcall_or_lang_call(cx, did,
~[lhs, rhs],
expr::SaveIn(
scratch_result.val));
return scratch_result.to_result(bcx);
}
_ => {
cx.tcx().sess.bug(~"only scalars and unique strings supported in \
cx.tcx().sess.bug(~"only scalars and strings supported in \
compare_values");
}
}

View File

@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// xfail-test
// rustc --test match_borrowed_str.rs.rs && ./match_borrowed_str.rs
extern mod std;
@ -21,8 +20,8 @@ fn compare(x: &str, y: &str) -> bool
}
}
#[test]
fn tester()
fn main()
{
assert compare("foo", "foo");
assert compare(@"foo", @"foo");
}