Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}