@@ -14,7 +14,7 @@ use middle::ty;
14
14
use middle:: typeck;
15
15
use util:: ppaux;
16
16
17
- use syntax:: ast:: * ;
17
+ use syntax:: ast;
18
18
use syntax:: ast_util;
19
19
use syntax:: visit:: Visitor ;
20
20
use syntax:: visit;
@@ -40,13 +40,13 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
40
40
}
41
41
42
42
impl < ' a , ' tcx , ' v > Visitor < ' v > for CheckCrateVisitor < ' a , ' tcx > {
43
- fn visit_item ( & mut self , i : & Item ) {
43
+ fn visit_item ( & mut self , i : & ast :: Item ) {
44
44
check_item ( self , i) ;
45
45
}
46
- fn visit_pat ( & mut self , p : & Pat ) {
46
+ fn visit_pat ( & mut self , p : & ast :: Pat ) {
47
47
check_pat ( self , p) ;
48
48
}
49
- fn visit_expr ( & mut self , ex : & Expr ) {
49
+ fn visit_expr ( & mut self , ex : & ast :: Expr ) {
50
50
if check_expr ( self , ex) {
51
51
visit:: walk_expr ( self , ex) ;
52
52
}
@@ -59,13 +59,13 @@ pub fn check_crate(tcx: &ty::ctxt) {
59
59
tcx. sess . abort_if_errors ( ) ;
60
60
}
61
61
62
- fn check_item ( v : & mut CheckCrateVisitor , it : & Item ) {
62
+ fn check_item ( v : & mut CheckCrateVisitor , it : & ast :: Item ) {
63
63
match it. node {
64
- ItemStatic ( _, _, ref ex) |
65
- ItemConst ( _, ref ex) => {
64
+ ast :: ItemStatic ( _, _, ref ex) |
65
+ ast :: ItemConst ( _, ref ex) => {
66
66
v. inside_const ( |v| v. visit_expr ( & * * ex) ) ;
67
67
}
68
- ItemEnum ( ref enum_definition, _) => {
68
+ ast :: ItemEnum ( ref enum_definition, _) => {
69
69
for var in ( * enum_definition) . variants . iter ( ) {
70
70
for ex in var. node . disr_expr . iter ( ) {
71
71
v. inside_const ( |v| v. visit_expr ( & * * ex) ) ;
@@ -76,12 +76,12 @@ fn check_item(v: &mut CheckCrateVisitor, it: &Item) {
76
76
}
77
77
}
78
78
79
- fn check_pat ( v : & mut CheckCrateVisitor , p : & Pat ) {
80
- fn is_str ( e : & Expr ) -> bool {
79
+ fn check_pat ( v : & mut CheckCrateVisitor , p : & ast :: Pat ) {
80
+ fn is_str ( e : & ast :: Expr ) -> bool {
81
81
match e. node {
82
- ExprBox ( _, ref expr) => {
82
+ ast :: ExprBox ( _, ref expr) => {
83
83
match expr. node {
84
- ExprLit ( ref lit) => ast_util:: lit_is_str ( & * * lit) ,
84
+ ast :: ExprLit ( ref lit) => ast_util:: lit_is_str ( & * * lit) ,
85
85
_ => false ,
86
86
}
87
87
}
@@ -90,36 +90,36 @@ fn check_pat(v: &mut CheckCrateVisitor, p: &Pat) {
90
90
}
91
91
match p. node {
92
92
// Let through plain ~-string literals here
93
- PatLit ( ref a) => if !is_str ( & * * a) { v. inside_const ( |v| v. visit_expr ( & * * a) ) ; } ,
94
- PatRange ( ref a, ref b) => {
93
+ ast :: PatLit ( ref a) => if !is_str ( & * * a) { v. inside_const ( |v| v. visit_expr ( & * * a) ) ; } ,
94
+ ast :: PatRange ( ref a, ref b) => {
95
95
if !is_str ( & * * a) { v. inside_const ( |v| v. visit_expr ( & * * a) ) ; }
96
96
if !is_str ( & * * b) { v. inside_const ( |v| v. visit_expr ( & * * b) ) ; }
97
97
}
98
98
_ => v. outside_const ( |v| visit:: walk_pat ( v, p) )
99
99
}
100
100
}
101
101
102
- fn check_expr ( v : & mut CheckCrateVisitor , e : & Expr ) -> bool {
102
+ fn check_expr ( v : & mut CheckCrateVisitor , e : & ast :: Expr ) -> bool {
103
103
if !v. in_const { return true }
104
104
105
105
match e. node {
106
- ExprUnary ( UnDeref , _) => { }
107
- ExprUnary ( UnUniq , _) => {
106
+ ast :: ExprUnary ( ast :: UnDeref , _) => { }
107
+ ast :: ExprUnary ( ast :: UnUniq , _) => {
108
108
span_err ! ( v. tcx. sess, e. span, E0010 ,
109
109
"cannot do allocations in constant expressions" ) ;
110
110
return false ;
111
111
}
112
- ExprLit ( ref lit) if ast_util:: lit_is_str ( & * * lit) => { }
113
- ExprBinary ( ..) | ExprUnary ( ..) => {
112
+ ast :: ExprLit ( ref lit) if ast_util:: lit_is_str ( & * * lit) => { }
113
+ ast :: ExprBinary ( ..) | ast :: ExprUnary ( ..) => {
114
114
let method_call = typeck:: MethodCall :: expr ( e. id ) ;
115
115
if v. tcx . method_map . borrow ( ) . contains_key ( & method_call) {
116
116
span_err ! ( v. tcx. sess, e. span, E0011 ,
117
117
"user-defined operators are not allowed in constant \
118
118
expressions") ;
119
119
}
120
120
}
121
- ExprLit ( _) => ( ) ,
122
- ExprCast ( ref from, _) => {
121
+ ast :: ExprLit ( _) => ( ) ,
122
+ ast :: ExprCast ( ref from, _) => {
123
123
let toty = ty:: expr_ty ( v. tcx , e) ;
124
124
let fromty = ty:: expr_ty ( v. tcx , & * * from) ;
125
125
if !ty:: type_is_numeric ( toty) && !ty:: type_is_unsafe_ptr ( toty) {
@@ -133,7 +133,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool {
133
133
expression") ;
134
134
}
135
135
}
136
- ExprPath ( ref pth) => {
136
+ ast :: ExprPath ( ref pth) => {
137
137
// NB: In the future you might wish to relax this slightly
138
138
// to handle on-demand instantiation of functions via
139
139
// foo::<bar> in a const. Currently that is only done on
@@ -161,7 +161,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool {
161
161
}
162
162
}
163
163
}
164
- ExprCall ( ref callee, _) => {
164
+ ast :: ExprCall ( ref callee, _) => {
165
165
match v. tcx . def_map . borrow ( ) . get ( & callee. id ) {
166
166
Some ( & DefStruct ( ..) ) |
167
167
Some ( & DefVariant ( ..) ) => { } // OK.
@@ -173,25 +173,25 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool {
173
173
}
174
174
}
175
175
}
176
- ExprBlock ( ref block) => {
176
+ ast :: ExprBlock ( ref block) => {
177
177
// Check all statements in the block
178
178
for stmt in block. stmts . iter ( ) {
179
179
let block_span_err = |span|
180
180
span_err ! ( v. tcx. sess, span, E0016 ,
181
181
"blocks in constants are limited to items and \
182
182
tail expressions") ;
183
183
match stmt. node {
184
- StmtDecl ( ref span, _) => {
184
+ ast :: StmtDecl ( ref span, _) => {
185
185
match span. node {
186
- DeclLocal ( _) => block_span_err ( span. span ) ,
186
+ ast :: DeclLocal ( _) => block_span_err ( span. span ) ,
187
187
188
188
// Item statements are allowed
189
- DeclItem ( _) => { }
189
+ ast :: DeclItem ( _) => { }
190
190
}
191
191
}
192
- StmtExpr ( ref expr, _) => block_span_err ( expr. span ) ,
193
- StmtSemi ( ref semi, _) => block_span_err ( semi. span ) ,
194
- StmtMac ( ..) => {
192
+ ast :: StmtExpr ( ref expr, _) => block_span_err ( expr. span ) ,
193
+ ast :: StmtSemi ( ref semi, _) => block_span_err ( semi. span ) ,
194
+ ast :: StmtMac ( ..) => {
195
195
v. tcx . sess . span_bug ( e. span , "unexpanded statement \
196
196
macro in const?!")
197
197
}
@@ -202,20 +202,20 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool {
202
202
None => { }
203
203
}
204
204
}
205
- ExprVec ( _) |
206
- ExprAddrOf ( MutImmutable , _) |
207
- ExprParen ( ..) |
208
- ExprField ( ..) |
209
- ExprTupField ( ..) |
210
- ExprIndex ( ..) |
211
- ExprTup ( ..) |
212
- ExprRepeat ( ..) |
213
- ExprStruct ( ..) => { }
214
-
215
- ExprAddrOf ( _, ref inner) => {
205
+ ast :: ExprVec ( _) |
206
+ ast :: ExprAddrOf ( ast :: MutImmutable , _) |
207
+ ast :: ExprParen ( ..) |
208
+ ast :: ExprField ( ..) |
209
+ ast :: ExprTupField ( ..) |
210
+ ast :: ExprIndex ( ..) |
211
+ ast :: ExprTup ( ..) |
212
+ ast :: ExprRepeat ( ..) |
213
+ ast :: ExprStruct ( ..) => { }
214
+
215
+ ast :: ExprAddrOf ( _, ref inner) => {
216
216
match inner. node {
217
217
// Mutable slices are allowed.
218
- ExprVec ( _) => { }
218
+ ast :: ExprVec ( _) => { }
219
219
_ => span_err ! ( v. tcx. sess, e. span, E0017 ,
220
220
"references in constants may only refer \
221
221
to immutable values")
0 commit comments