Skip to content

Commit

Permalink
Allow pattern-matching on any strings, not just unique strings
Browse files Browse the repository at this point in the history
  • Loading branch information
catamorphism committed Dec 11, 2012
1 parent e7dd3af commit b654ae0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
12 changes: 11 additions & 1 deletion src/librustc/middle/trans/alt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/test/run-pass/issue-3574.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -21,8 +20,8 @@ fn compare(x: &str, y: &str) -> bool
}
}

#[test]
fn tester()
fn main()
{
assert compare("foo", "foo");
assert compare(@"foo", @"foo");
}

0 comments on commit b654ae0

Please sign in to comment.