Skip to content

Commit 01c0971

Browse files
committed
Allow pattern-matching on any strings, not just unique strings
r=brson Closes #3574
1 parent f675b97 commit 01c0971

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/librustc/middle/trans/alt.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -951,8 +951,18 @@ fn compare_values(cx: block, lhs: ValueRef, rhs: ValueRef, rhs_t: ty::t) ->
951951
scratch_result.val));
952952
return scratch_result.to_result(bcx);
953953
}
954+
ty::ty_estr(_) => {
955+
let scratch_result = scratch_datum(cx, ty::mk_bool(cx.tcx()),
956+
false);
957+
let did = cx.tcx().lang_items.str_eq_fn.get();
958+
let bcx = callee::trans_rtcall_or_lang_call(cx, did,
959+
~[lhs, rhs],
960+
expr::SaveIn(
961+
scratch_result.val));
962+
return scratch_result.to_result(bcx);
963+
}
954964
_ => {
955-
cx.tcx().sess.bug(~"only scalars and unique strings supported in \
965+
cx.tcx().sess.bug(~"only scalars and strings supported in \
956966
compare_values");
957967
}
958968
}

src/test/run-pass/issue-3574.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// xfail-test
1211
// rustc --test match_borrowed_str.rs.rs && ./match_borrowed_str.rs
1312
extern mod std;
1413

@@ -21,8 +20,8 @@ fn compare(x: &str, y: &str) -> bool
2120
}
2221
}
2322

24-
#[test]
25-
fn tester()
23+
fn main()
2624
{
2725
assert compare("foo", "foo");
26+
assert compare(@"foo", @"foo");
2827
}

0 commit comments

Comments
 (0)