@@ -87,28 +87,25 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr, is_const: bool) {
8787 match e. node {
8888 ExprUnary ( UnDeref , _) => { }
8989 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" ) ;
9291 return ;
9392 }
9493 ExprLit ( lit) if ast_util:: lit_is_str ( lit) => { }
9594 ExprBinary ( ..) | ExprUnary ( ..) => {
9695 let method_call = typeck:: MethodCall :: expr ( e. id ) ;
9796 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") ;
10099 }
101100 }
102101 ExprLit ( _) => ( ) ,
103102 ExprCast ( _, _) => {
104103 let ety = ty:: expr_ty ( v. tcx , e) ;
105104 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+ ) ;
112109 }
113110 }
114111 ExprPath ( ref pth) => {
@@ -117,9 +114,8 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr, is_const: bool) {
117114 // foo::<bar> in a const. Currently that is only done on
118115 // a path in trans::callee that only works in block contexts.
119116 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" ) ;
123119 }
124120 match v. tcx . def_map . borrow ( ) . find ( & e. id ) {
125121 Some ( & DefStatic ( ..) ) |
@@ -129,9 +125,8 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr, is_const: bool) {
129125
130126 Some ( & def) => {
131127 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" ) ;
135130 }
136131 None => {
137132 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) {
143138 Some ( & DefStruct ( ..) ) => { } // OK.
144139 Some ( & DefVariant ( ..) ) => { } // OK.
145140 _ => {
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" ) ;
149143 }
150144 }
151145 }
152146 ExprBlock ( ref block) => {
153147 // Check all statements in the block
154148 for stmt in block. stmts . iter ( ) {
155149 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" ) ;
159152 match stmt. node {
160153 StmtDecl ( ref span, _) => {
161154 match span. node {
@@ -187,18 +180,18 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr, is_const: bool) {
187180 ExprRepeat ( ..) |
188181 ExprStruct ( ..) => { }
189182 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" ) ;
193185 } ,
194186 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" ) ;
196189 } ,
197190
198191 _ => {
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 ;
202195 }
203196 }
204197 }
0 commit comments