@@ -87,28 +87,25 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr, is_const: bool) {
87
87
match e. node {
88
88
ExprUnary ( UnDeref , _) => { }
89
89
ExprUnary ( UnBox , _) | ExprUnary ( UnUniq , _) => {
90
- v. tcx . sess . span_err ( e. span ,
91
- "cannot do allocations in constant expressions" ) ;
90
+ span_err ! ( v. tcx. sess, e. span, E0010 , "cannot do allocations in constant expressions" ) ;
92
91
return ;
93
92
}
94
93
ExprLit ( lit) if ast_util:: lit_is_str ( lit) => { }
95
94
ExprBinary ( ..) | ExprUnary ( ..) => {
96
95
let method_call = typeck:: MethodCall :: expr ( e. id ) ;
97
96
if v. tcx . method_map . borrow ( ) . contains_key ( & method_call) {
98
- v. tcx . sess . span_err ( e. span , "user-defined operators are not \
99
- allowed in constant expressions") ;
97
+ span_err ! ( v. tcx. sess, e. span, E0011 ,
98
+ "user-defined operators are not allowed in constant expressions") ;
100
99
}
101
100
}
102
101
ExprLit ( _) => ( ) ,
103
102
ExprCast ( _, _) => {
104
103
let ety = ty:: expr_ty ( v. tcx , e) ;
105
104
if !ty:: type_is_numeric ( ety) && !ty:: type_is_unsafe_ptr ( ety) {
106
- v. tcx
107
- . sess
108
- . span_err ( e. span ,
109
- format ! ( "can not cast to `{}` in a constant \
110
- expression",
111
- ppaux:: ty_to_string( v. tcx, ety) ) . as_slice ( ) )
105
+ span_err ! ( v. tcx. sess, e. span, E0012 ,
106
+ "can not cast to `{}` in a constant expression" ,
107
+ ppaux:: ty_to_string( v. tcx, ety)
108
+ ) ;
112
109
}
113
110
}
114
111
ExprPath ( ref pth) => {
@@ -117,9 +114,8 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr, is_const: bool) {
117
114
// foo::<bar> in a const. Currently that is only done on
118
115
// a path in trans::callee that only works in block contexts.
119
116
if !pth. segments . iter ( ) . all ( |segment| segment. types . is_empty ( ) ) {
120
- v. tcx . sess . span_err ( e. span ,
121
- "paths in constants may only refer to \
122
- items without type parameters") ;
117
+ span_err ! ( v. tcx. sess, e. span, E0013 ,
118
+ "paths in constants may only refer to items without type parameters" ) ;
123
119
}
124
120
match v. tcx . def_map . borrow ( ) . find ( & e. id ) {
125
121
Some ( & DefStatic ( ..) ) |
@@ -129,9 +125,8 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr, is_const: bool) {
129
125
130
126
Some ( & def) => {
131
127
debug ! ( "(checking const) found bad def: {:?}" , def) ;
132
- v. tcx . sess . span_err ( e. span ,
133
- "paths in constants may only refer to \
134
- constants or functions") ;
128
+ span_err ! ( v. tcx. sess, e. span, E0014 ,
129
+ "paths in constants may only refer to constants or functions" ) ;
135
130
}
136
131
None => {
137
132
v. tcx . sess . span_bug ( e. span , "unbound path in const?!" ) ;
@@ -143,19 +138,17 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr, is_const: bool) {
143
138
Some ( & DefStruct ( ..) ) => { } // OK.
144
139
Some ( & DefVariant ( ..) ) => { } // OK.
145
140
_ => {
146
- v. tcx . sess . span_err ( e. span ,
147
- "function calls in constants are limited to \
148
- struct and enum constructors") ;
141
+ span_err ! ( v. tcx. sess, e. span, E0015 ,
142
+ "function calls in constants are limited to struct and enum constructors" ) ;
149
143
}
150
144
}
151
145
}
152
146
ExprBlock ( ref block) => {
153
147
// Check all statements in the block
154
148
for stmt in block. stmts . iter ( ) {
155
149
let block_span_err = |span|
156
- v. tcx . sess . span_err ( span,
157
- "blocks in constants are limited to \
158
- items and tail expressions") ;
150
+ span_err ! ( v. tcx. sess, span, E0016 ,
151
+ "blocks in constants are limited to items and tail expressions" ) ;
159
152
match stmt. node {
160
153
StmtDecl ( ref span, _) => {
161
154
match span. node {
@@ -187,18 +180,18 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr, is_const: bool) {
187
180
ExprRepeat ( ..) |
188
181
ExprStruct ( ..) => { }
189
182
ExprAddrOf ( ..) => {
190
- v. tcx . sess . span_err ( e. span ,
191
- "references in constants may only refer to \
192
- immutable values") ;
183
+ span_err ! ( v. tcx. sess, e. span, E0017 ,
184
+ "references in constants may only refer to immutable values" ) ;
193
185
} ,
194
186
ExprVstore ( _, ExprVstoreUniq ) => {
195
- v. tcx . sess . span_err ( e. span , "cannot allocate vectors in constant expressions" )
187
+ span_err ! ( v. tcx. sess, e. span, E0018 ,
188
+ "cannot allocate vectors in constant expressions" ) ;
196
189
} ,
197
190
198
191
_ => {
199
- v. tcx . sess . span_err ( e. span ,
200
- "constant contains unimplemented expression type" ) ;
201
- return ;
192
+ span_err ! ( v. tcx. sess, e. span, E0019 ,
193
+ "constant contains unimplemented expression type" ) ;
194
+ return ;
202
195
}
203
196
}
204
197
}
0 commit comments