Skip to content

Commit 1f62869

Browse files
committed
rustc: check_const: remove ~str support in patterns.
1 parent 496dc4e commit 1f62869

File tree

1 file changed

+6
-23
lines changed

1 file changed

+6
-23
lines changed

src/librustc/middle/check_const.rs

+6-23
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use middle::ty;
1414
use util::ppaux;
1515

1616
use syntax::ast;
17-
use syntax::ast_util;
1817
use syntax::visit::Visitor;
1918
use syntax::visit;
2019

@@ -82,26 +81,11 @@ fn check_item(v: &mut CheckCrateVisitor, it: &ast::Item) {
8281
}
8382

8483
fn check_pat(v: &mut CheckCrateVisitor, p: &ast::Pat) {
85-
fn is_str(e: &ast::Expr) -> bool {
86-
match e.node {
87-
ast::ExprBox(_, ref expr) => {
88-
match expr.node {
89-
ast::ExprLit(ref lit) => ast_util::lit_is_str(&**lit),
90-
_ => false,
91-
}
92-
}
93-
_ => false,
94-
}
95-
}
96-
match p.node {
97-
// Let through plain ~-string literals here
98-
ast::PatLit(ref a) => if !is_str(&**a) { v.inside_const(|v| v.visit_expr(&**a)); },
99-
ast::PatRange(ref a, ref b) => {
100-
if !is_str(&**a) { v.inside_const(|v| v.visit_expr(&**a)); }
101-
if !is_str(&**b) { v.inside_const(|v| v.visit_expr(&**b)); }
102-
}
103-
_ => v.outside_const(|v| visit::walk_pat(v, p))
104-
}
84+
let is_const = match p.node {
85+
ast::PatLit(_) | ast::PatRange(..) => true,
86+
_ => false
87+
};
88+
v.with_const(is_const, |v| visit::walk_pat(v, p))
10589
}
10690

10791
fn check_expr(v: &mut CheckCrateVisitor, e: &ast::Expr) -> bool {
@@ -114,7 +98,6 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &ast::Expr) -> bool {
11498
"cannot do allocations in constant expressions");
11599
return false;
116100
}
117-
ast::ExprLit(ref lit) if ast_util::lit_is_str(&**lit) => {}
118101
ast::ExprBinary(..) | ast::ExprUnary(..) => {
119102
let method_call = ty::MethodCall::expr(e.id);
120103
if v.tcx.method_map.borrow().contains_key(&method_call) {
@@ -123,7 +106,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &ast::Expr) -> bool {
123106
expressions");
124107
}
125108
}
126-
ast::ExprLit(_) => (),
109+
ast::ExprLit(_) => {}
127110
ast::ExprCast(ref from, _) => {
128111
let toty = ty::expr_ty(v.tcx, e);
129112
let fromty = ty::expr_ty(v.tcx, &**from);

0 commit comments

Comments
 (0)