Skip to content

Commit c84c4a8

Browse files
committed
Handle str/~ in patterns.
1 parent 2ea9c8d commit c84c4a8

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

src/rustc/middle/check_const.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ fn check_item(sess: session, ast_map: ast_map::map, def_map: resolve::def_map,
3737

3838
fn check_pat(p: @pat, &&_is_const: bool, v: visit::vt<bool>) {
3939
fn is_str(e: @expr) -> bool {
40-
alt e.node { expr_lit(@{node: lit_str(_), _}) { true } _ { false } }
40+
alt e.node {
41+
expr_lit(@{node: lit_str(_), _}) |
42+
expr_vstore(@{node: expr_lit(@{node: lit_str(_), _}), _},
43+
vstore_uniq) { true }
44+
_ { false }
45+
}
4146
}
4247
alt p.node {
4348
// Let through plain string literals here

src/rustc/middle/const_eval.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ fn eval_const_expr(tcx: middle::ty::ctxt, e: @expr) -> const_val {
103103
}
104104
}
105105
expr_lit(lit) { lit_to_const(lit) }
106+
// If we have a vstore, just keep going; it has to be a string
107+
expr_vstore(e, _) { eval_const_expr(tcx, e) }
106108
}
107109
}
108110

src/rustc/middle/trans/alt.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ fn trans_opt(bcx: block, o: opt) -> opt_result {
4747
alt o {
4848
lit(l) {
4949
alt l.node {
50-
ast::expr_lit(@{node: ast::lit_str(s), _}) {
50+
ast::expr_lit(@{node: ast::lit_str(s), _}) |
51+
ast::expr_vstore(@{node: ast::expr_lit(
52+
@{node: ast::lit_str(s), _}), _},
53+
ast::vstore_uniq) {
5154
let strty = ty::mk_str(bcx.tcx());
5255
let cell = empty_dest_cell();
5356
bcx = tvec::trans_estr(bcx, s, ast::vstore_uniq, by_val(cell));

src/rustc/middle/trans/base.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4613,7 +4613,9 @@ fn trans_enum_variant(ccx: @crate_ctxt, enum_id: ast::node_id,
46134613
fn trans_const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
46144614
let _icx = cx.insn_ctxt("trans_const_expr");
46154615
alt e.node {
4616-
ast::expr_lit(lit) { ret trans_crate_lit(cx, e, *lit); }
4616+
ast::expr_lit(lit) { trans_crate_lit(cx, e, *lit) }
4617+
// If we have a vstore, just keep going; it has to be a string
4618+
ast::expr_vstore(e, _) { trans_const_expr(cx, e) }
46174619
ast::expr_binary(b, e1, e2) {
46184620
let te1 = trans_const_expr(cx, e1);
46194621
let te2 = trans_const_expr(cx, e2);

0 commit comments

Comments
 (0)