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