@@ -273,6 +273,22 @@ pub enum ConstVal {
273
273
Tuple ( ast:: NodeId ) ,
274
274
}
275
275
276
+ impl ConstVal {
277
+ pub fn description ( & self ) -> & ' static str {
278
+ match * self {
279
+ Float ( _) => "float" ,
280
+ Int ( i) if i < 0 => "negative integer" ,
281
+ Int ( _) => "positive integer" ,
282
+ Uint ( _) => "unsigned integer" ,
283
+ Str ( _) => "string literal" ,
284
+ Binary ( _) => "binary array" ,
285
+ Bool ( _) => "boolean" ,
286
+ Struct ( _) => "struct" ,
287
+ Tuple ( _) => "tuple" ,
288
+ }
289
+ }
290
+ }
291
+
276
292
pub fn const_expr_to_pat ( tcx : & ty:: ctxt , expr : & Expr , span : Span ) -> P < ast:: Pat > {
277
293
let pat = match expr. node {
278
294
ast:: ExprTup ( ref exprs) =>
@@ -352,16 +368,8 @@ pub enum ErrKind {
352
368
InvalidOpForFloats ( ast:: BinOp_ ) ,
353
369
InvalidOpForIntUint ( ast:: BinOp_ ) ,
354
370
InvalidOpForUintInt ( ast:: BinOp_ ) ,
355
- NegateOnString ,
356
- NegateOnBoolean ,
357
- NegateOnBinary ,
358
- NegateOnStruct ,
359
- NegateOnTuple ,
360
- NotOnFloat ,
361
- NotOnString ,
362
- NotOnBinary ,
363
- NotOnStruct ,
364
- NotOnTuple ,
371
+ NegateOn ( ConstVal ) ,
372
+ NotOn ( ConstVal ) ,
365
373
366
374
NegateWithOverflow ( i64 ) ,
367
375
AddiWithOverflow ( i64 , i64 ) ,
@@ -397,16 +405,8 @@ impl ConstEvalErr {
397
405
InvalidOpForFloats ( _) => "can't do this op on floats" . into_cow ( ) ,
398
406
InvalidOpForIntUint ( ..) => "can't do this op on an isize and usize" . into_cow ( ) ,
399
407
InvalidOpForUintInt ( ..) => "can't do this op on a usize and isize" . into_cow ( ) ,
400
- NegateOnString => "negate on string" . into_cow ( ) ,
401
- NegateOnBoolean => "negate on boolean" . into_cow ( ) ,
402
- NegateOnBinary => "negate on binary literal" . into_cow ( ) ,
403
- NegateOnStruct => "negate on struct" . into_cow ( ) ,
404
- NegateOnTuple => "negate on tuple" . into_cow ( ) ,
405
- NotOnFloat => "not on float or string" . into_cow ( ) ,
406
- NotOnString => "not on float or string" . into_cow ( ) ,
407
- NotOnBinary => "not on binary literal" . into_cow ( ) ,
408
- NotOnStruct => "not on struct" . into_cow ( ) ,
409
- NotOnTuple => "not on tuple" . into_cow ( ) ,
408
+ NegateOn ( ref const_val) => format ! ( "negate on {}" , const_val. description( ) ) . into_cow ( ) ,
409
+ NotOn ( ref const_val) => format ! ( "not on {}" , const_val. description( ) ) . into_cow ( ) ,
410
410
411
411
NegateWithOverflow ( ..) => "attempted to negate with overflow" . into_cow ( ) ,
412
412
AddiWithOverflow ( ..) => "attempted to add with overflow" . into_cow ( ) ,
@@ -754,23 +754,15 @@ pub fn eval_const_expr_with_substs<'tcx, S>(tcx: &ty::ctxt<'tcx>,
754
754
}
755
755
try!( const_uint_checked_neg ( i, e, expr_uint_type) )
756
756
}
757
- Str ( _) => signal ! ( e, NegateOnString ) ,
758
- Bool ( _) => signal ! ( e, NegateOnBoolean ) ,
759
- Binary ( _) => signal ! ( e, NegateOnBinary ) ,
760
- Tuple ( _) => signal ! ( e, NegateOnTuple ) ,
761
- Struct ( ..) => signal ! ( e, NegateOnStruct ) ,
757
+ const_val => signal ! ( e, NegateOn ( const_val) ) ,
762
758
}
763
759
}
764
760
ast:: ExprUnary ( ast:: UnNot , ref inner) => {
765
761
match try!( eval_const_expr_partial ( tcx, & * * inner, ety) ) {
766
762
Int ( i) => Int ( !i) ,
767
763
Uint ( i) => const_uint_not ( i, expr_uint_type) ,
768
764
Bool ( b) => Bool ( !b) ,
769
- Str ( _) => signal ! ( e, NotOnString ) ,
770
- Float ( _) => signal ! ( e, NotOnFloat ) ,
771
- Binary ( _) => signal ! ( e, NotOnBinary ) ,
772
- Tuple ( _) => signal ! ( e, NotOnTuple ) ,
773
- Struct ( ..) => signal ! ( e, NotOnStruct ) ,
765
+ const_val => signal ! ( e, NotOn ( const_val) ) ,
774
766
}
775
767
}
776
768
ast:: ExprBinary ( op, ref a, ref b) => {
0 commit comments