@@ -267,6 +267,10 @@ pub enum ConstVal {
267
267
Array ( ast:: NodeId , u64 ) ,
268
268
Repeat ( ast:: NodeId , u64 ) ,
269
269
Char ( char ) ,
270
+ /// A value that only occurs in case `eval_const_expr` reported an error. You should never
271
+ /// handle this case. Its sole purpose is to allow more errors to be reported instead of
272
+ /// causing a fatal error.
273
+ Dummy ,
270
274
}
271
275
272
276
impl hash:: Hash for ConstVal {
@@ -283,6 +287,7 @@ impl hash::Hash for ConstVal {
283
287
Array ( a, n) => { a. hash ( state) ; n. hash ( state) } ,
284
288
Repeat ( a, n) => { a. hash ( state) ; n. hash ( state) } ,
285
289
Char ( c) => c. hash ( state) ,
290
+ Dummy => ( ) . hash ( state) ,
286
291
}
287
292
}
288
293
}
@@ -305,6 +310,7 @@ impl PartialEq for ConstVal {
305
310
( & Array ( a, an) , & Array ( b, bn) ) => ( a == b) && ( an == bn) ,
306
311
( & Repeat ( a, an) , & Repeat ( b, bn) ) => ( a == b) && ( an == bn) ,
307
312
( & Char ( a) , & Char ( b) ) => a == b,
313
+ ( & Dummy , & Dummy ) => true , // FIXME: should this be false?
308
314
_ => false ,
309
315
}
310
316
}
@@ -326,6 +332,7 @@ impl ConstVal {
326
332
Array ( ..) => "array" ,
327
333
Repeat ( ..) => "repeat" ,
328
334
Char ( ..) => "char" ,
335
+ Dummy => "dummy value" ,
329
336
}
330
337
}
331
338
}
@@ -393,7 +400,12 @@ pub fn const_expr_to_pat(tcx: &TyCtxt, expr: &Expr, span: Span) -> P<hir::Pat> {
393
400
pub fn eval_const_expr ( tcx : & TyCtxt , e : & Expr ) -> ConstVal {
394
401
match eval_const_expr_partial ( tcx, e, ExprTypeChecked , None ) {
395
402
Ok ( r) => r,
396
- Err ( s) => tcx. sess . span_fatal ( s. span , & s. description ( ) )
403
+ // non-const path still needs to be a fatal error, because enums are funky
404
+ Err ( ref s) if s. kind == NonConstPath => tcx. sess . span_fatal ( s. span , & s. description ( ) ) ,
405
+ Err ( s) => {
406
+ tcx. sess . span_err ( s. span , & s. description ( ) ) ;
407
+ Dummy
408
+ } ,
397
409
}
398
410
}
399
411
@@ -405,7 +417,7 @@ pub struct ConstEvalErr {
405
417
pub kind : ErrKind ,
406
418
}
407
419
408
- #[ derive( Clone ) ]
420
+ #[ derive( Clone , PartialEq ) ]
409
421
pub enum ErrKind {
410
422
CannotCast ,
411
423
CannotCastTo ( & ' static str ) ,
0 commit comments