@@ -14,7 +14,6 @@ use middle::ty;
14
14
use util:: ppaux;
15
15
16
16
use syntax:: ast;
17
- use syntax:: ast_util;
18
17
use syntax:: visit:: Visitor ;
19
18
use syntax:: visit;
20
19
@@ -82,26 +81,11 @@ fn check_item(v: &mut CheckCrateVisitor, it: &ast::Item) {
82
81
}
83
82
84
83
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) )
105
89
}
106
90
107
91
fn check_expr ( v : & mut CheckCrateVisitor , e : & ast:: Expr ) -> bool {
@@ -114,7 +98,6 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &ast::Expr) -> bool {
114
98
"cannot do allocations in constant expressions" ) ;
115
99
return false ;
116
100
}
117
- ast:: ExprLit ( ref lit) if ast_util:: lit_is_str ( & * * lit) => { }
118
101
ast:: ExprBinary ( ..) | ast:: ExprUnary ( ..) => {
119
102
let method_call = ty:: MethodCall :: expr ( e. id ) ;
120
103
if v. tcx . method_map . borrow ( ) . contains_key ( & method_call) {
@@ -123,7 +106,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &ast::Expr) -> bool {
123
106
expressions") ;
124
107
}
125
108
}
126
- ast:: ExprLit ( _) => ( ) ,
109
+ ast:: ExprLit ( _) => { }
127
110
ast:: ExprCast ( ref from, _) => {
128
111
let toty = ty:: expr_ty ( v. tcx , e) ;
129
112
let fromty = ty:: expr_ty ( v. tcx , & * * from) ;
0 commit comments