@@ -41,6 +41,7 @@ use syntax::attr::IntType;
41
41
use std:: borrow:: Cow ;
42
42
use std:: cmp:: Ordering ;
43
43
use std:: collections:: hash_map:: Entry :: Vacant ;
44
+ use std:: collections:: BTreeMap ;
44
45
45
46
use rustc_const_math:: * ;
46
47
@@ -410,7 +411,8 @@ pub enum ErrKind {
410
411
IntermediateUnsignedNegative ,
411
412
/// Expected, Got
412
413
TypeMismatch ( String , ConstInt ) ,
413
- BadType ( ConstVal ) ,
414
+ /// target type, got value
415
+ BadType ( String , ConstVal ) ,
414
416
ErroneousReferencedConstant ( Box < ConstEvalErr > ) ,
415
417
CharCast ( ConstInt ) ,
416
418
Aggregate ( Vec < ConstEvalErr > ) ,
@@ -472,7 +474,7 @@ impl ConstEvalErr {
472
474
format ! ( "mismatched types: expected `{}`, found `{}`" ,
473
475
expected, got. description( ) ) . into_cow ( )
474
476
} ,
475
- BadType ( ref i) => format ! ( "value of wrong type: {:?}" , i) . into_cow ( ) ,
477
+ BadType ( ref ty , ref i) => format ! ( "expected `{}`, found ` {:?}`" , ty , i) . into_cow ( ) ,
476
478
ErroneousReferencedConstant ( _) => "could not evaluate referenced constant" . into_cow ( ) ,
477
479
CharCast ( ref got) => {
478
480
format ! ( "only `u8` can be cast as `char`, not `{}`" , got. description( ) ) . into_cow ( )
@@ -1023,7 +1025,8 @@ fn infer<'a, 'tcx>(i: ConstInt,
1023
1025
let int_ty = tcx. enum_repr_type ( hints. iter ( ) . next ( ) ) ;
1024
1026
infer ( i, tcx, & int_ty. to_ty ( tcx) . sty )
1025
1027
} ,
1026
- ( _, i) => Err ( BadType ( ConstVal :: Integral ( i) ) ) ,
1028
+ ( & ty:: TyParam ( _) , i) => Ok ( i) ,
1029
+ ( ty, i) => Err ( BadType ( ty. to_string ( ) , ConstVal :: Integral ( i) ) ) ,
1027
1030
}
1028
1031
}
1029
1032
0 commit comments