Skip to content

Commit 9db4445

Browse files
committed
Merge pull request #3316 from Vincent-Belliard/issue_3222
fix issue #3222
2 parents fa2fb0f + d12128f commit 9db4445

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

src/rustc/middle/trans/alt.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ fn trans_opt(bcx: block, o: opt) -> opt_result {
5858
return single_result(rslt(bcx, *cell));
5959
}
6060
_ => {
61-
return single_result(
62-
rslt(bcx, consts::const_expr(ccx, l)));
61+
return single_result(trans_temp_expr(bcx, l));
6362
}
6463
}
6564
}
@@ -636,13 +635,14 @@ fn compile_submatch(bcx: block, m: match_, vals: ~[ValueRef],
636635
}
637636
}
638637
lit(_) => {
639-
test_val = Load(bcx, val);
640638
let pty = node_id_type(bcx, pat_id);
639+
test_val = load_if_immediate(bcx, val, pty);
641640
kind = if ty::type_is_integral(pty) { switch }
642641
else { compare };
643642
}
644643
range(_, _) => {
645-
test_val = Load(bcx, val);
644+
let pty = node_id_type(bcx, pat_id);
645+
test_val = load_if_immediate(bcx, val, pty);
646646
kind = compare;
647647
}
648648
}

src/test/run-pass/alt-borrowed_str.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// -*- rust -*-
2+
fn f1(ref_string: &str) {
3+
match ref_string {
4+
"a" => io::println("found a"),
5+
"b" => io::println("found b"),
6+
_ => io::println("not found")
7+
}
8+
}
9+
10+
fn f2(ref_string: &str) {
11+
match ref_string {
12+
"a" => io::println("found a"),
13+
"b" => io::println("found b"),
14+
s => io::println(fmt!("not found (%s)", s))
15+
}
16+
}
17+
18+
fn g1(ref_1: &str, ref_2: &str) {
19+
match (ref_1, ref_2) {
20+
("a", "b") => io::println("found a,b"),
21+
("b", "c") => io::println("found b,c"),
22+
_ => io::println("not found")
23+
}
24+
}
25+
26+
fn g2(ref_1: &str, ref_2: &str) {
27+
match (ref_1, ref_2) {
28+
("a", "b") => io::println("found a,b"),
29+
("b", "c") => io::println("found b,c"),
30+
(s1, s2) => io::println(fmt!("not found (%s, %s)", s1, s2))
31+
}
32+
}
33+
34+
fn main() {
35+
f1(@"a");
36+
f1(~"b");
37+
f1(&"c");
38+
f1("d");
39+
f2(@"a");
40+
f2(~"b");
41+
f2(&"c");
42+
f2("d");
43+
g1(@"a", @"b");
44+
g1(~"b", ~"c");
45+
g1(&"c", &"d");
46+
g1("d", "e");
47+
g2(@"a", @"b");
48+
g2(~"b", ~"c");
49+
g2(&"c", &"d");
50+
g2("d", "e");
51+
}

0 commit comments

Comments
 (0)