@@ -814,7 +814,10 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &TyCtxt<'tcx>,
814
814
debug ! ( "const call({:?})" , call_args) ;
815
815
eval_const_expr_partial ( tcx, & result, ty_hint, Some ( & call_args) ) ?
816
816
} ,
817
- hir:: ExprLit ( ref lit) => lit_to_const ( & lit. node , tcx, ety, lit. span ) ?,
817
+ hir:: ExprLit ( ref lit) => match lit_to_const ( & lit. node , tcx, ety, lit. span ) {
818
+ Ok ( val) => val,
819
+ Err ( err) => signal ! ( e, err) ,
820
+ } ,
818
821
hir:: ExprBlock ( ref block) => {
819
822
match block. expr {
820
823
Some ( ref expr) => eval_const_expr_partial ( tcx, & expr, ty_hint, fn_args) ?,
@@ -920,7 +923,10 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &TyCtxt<'tcx>,
920
923
} ;
921
924
922
925
match ( ety. map ( |t| & t. sty ) , result) {
923
- ( Some ( ref ty_hint) , Integral ( i) ) => Ok ( Integral ( infer ( i, tcx, ty_hint, e. span ) ?) ) ,
926
+ ( Some ( ref ty_hint) , Integral ( i) ) => match infer ( i, tcx, ty_hint) {
927
+ Ok ( inferred) => Ok ( Integral ( inferred) ) ,
928
+ Err ( err) => signal ! ( e, err) ,
929
+ } ,
924
930
( _, result) => Ok ( result) ,
925
931
}
926
932
}
@@ -929,15 +935,9 @@ fn infer<'tcx>(
929
935
i : ConstInt ,
930
936
tcx : & TyCtxt < ' tcx > ,
931
937
ty_hint : & ty:: TypeVariants < ' tcx > ,
932
- span : Span
933
- ) -> Result < ConstInt , ConstEvalErr > {
938
+ ) -> Result < ConstInt , ErrKind > {
934
939
use syntax:: ast:: * ;
935
940
936
- let err = |e| ConstEvalErr {
937
- span : span,
938
- kind : e,
939
- } ;
940
-
941
941
match ( ty_hint, i) {
942
942
( & ty:: TyInt ( IntTy :: I8 ) , result @ I8 ( _) ) => Ok ( result) ,
943
943
( & ty:: TyInt ( IntTy :: I16 ) , result @ I16 ( _) ) => Ok ( result) ,
@@ -983,17 +983,17 @@ fn infer<'tcx>(
983
983
Err ( _) => Ok ( Usize ( ConstUsize :: Us32 ( i as u32 ) ) ) ,
984
984
}
985
985
} ,
986
- ( & ty:: TyUint ( _) , InferSigned ( _) ) => Err ( err ( IntermediateUnsignedNegative ) ) ,
986
+ ( & ty:: TyUint ( _) , InferSigned ( _) ) => Err ( IntermediateUnsignedNegative ) ,
987
987
988
- ( & ty:: TyInt ( ity) , i) => Err ( err ( TypeMismatch ( ity. to_string ( ) , i) ) ) ,
989
- ( & ty:: TyUint ( ity) , i) => Err ( err ( TypeMismatch ( ity. to_string ( ) , i) ) ) ,
988
+ ( & ty:: TyInt ( ity) , i) => Err ( TypeMismatch ( ity. to_string ( ) , i) ) ,
989
+ ( & ty:: TyUint ( ity) , i) => Err ( TypeMismatch ( ity. to_string ( ) , i) ) ,
990
990
991
991
( & ty:: TyEnum ( ref adt, _) , i) => {
992
992
let hints = tcx. lookup_repr_hints ( adt. did ) ;
993
993
let int_ty = tcx. enum_repr_type ( hints. iter ( ) . next ( ) ) ;
994
- infer ( i, tcx, & int_ty. to_ty ( tcx) . sty , span )
994
+ infer ( i, tcx, & int_ty. to_ty ( tcx) . sty )
995
995
} ,
996
- ( _, i) => Err ( err ( BadType ( ConstVal :: Integral ( i) ) ) ) ,
996
+ ( _, i) => Err ( BadType ( ConstVal :: Integral ( i) ) ) ,
997
997
}
998
998
}
999
999
@@ -1125,36 +1125,36 @@ fn lit_to_const<'tcx>(lit: &ast::LitKind,
1125
1125
tcx : & TyCtxt < ' tcx > ,
1126
1126
ty_hint : Option < Ty < ' tcx > > ,
1127
1127
span : Span ,
1128
- ) -> Result < ConstVal , ConstEvalErr > {
1128
+ ) -> Result < ConstVal , ErrKind > {
1129
1129
use syntax:: ast:: * ;
1130
1130
use syntax:: ast:: LitIntType :: * ;
1131
1131
match * lit {
1132
1132
LitKind :: Str ( ref s, _) => Ok ( Str ( ( * s) . clone ( ) ) ) ,
1133
1133
LitKind :: ByteStr ( ref data) => Ok ( ByteStr ( data. clone ( ) ) ) ,
1134
1134
LitKind :: Byte ( n) => Ok ( Integral ( U8 ( n) ) ) ,
1135
1135
LitKind :: Int ( n, Signed ( ity) ) => {
1136
- infer ( InferSigned ( n as i64 ) , tcx, & ty:: TyInt ( ity) , span ) . map ( Integral )
1136
+ infer ( InferSigned ( n as i64 ) , tcx, & ty:: TyInt ( ity) ) . map ( Integral )
1137
1137
} ,
1138
1138
1139
1139
LitKind :: Int ( n, Unsuffixed ) => {
1140
1140
match ty_hint. map ( |t| & t. sty ) {
1141
1141
Some ( & ty:: TyInt ( ity) ) => {
1142
- infer ( InferSigned ( n as i64 ) , tcx, & ty:: TyInt ( ity) , span ) . map ( Integral )
1142
+ infer ( InferSigned ( n as i64 ) , tcx, & ty:: TyInt ( ity) ) . map ( Integral )
1143
1143
} ,
1144
1144
Some ( & ty:: TyUint ( uty) ) => {
1145
- infer ( Infer ( n) , tcx, & ty:: TyUint ( uty) , span ) . map ( Integral )
1145
+ infer ( Infer ( n) , tcx, & ty:: TyUint ( uty) ) . map ( Integral )
1146
1146
} ,
1147
1147
None => Ok ( Integral ( Infer ( n) ) ) ,
1148
1148
Some ( & ty:: TyEnum ( ref adt, _) ) => {
1149
1149
let hints = tcx. lookup_repr_hints ( adt. did ) ;
1150
1150
let int_ty = tcx. enum_repr_type ( hints. iter ( ) . next ( ) ) ;
1151
- infer ( Infer ( n) , tcx, & int_ty. to_ty ( tcx) . sty , span ) . map ( Integral )
1151
+ infer ( Infer ( n) , tcx, & int_ty. to_ty ( tcx) . sty ) . map ( Integral )
1152
1152
} ,
1153
1153
Some ( ty_hint) => bug ! ( "bad ty_hint: {:?}, {:?}" , ty_hint, lit) ,
1154
1154
}
1155
1155
} ,
1156
1156
LitKind :: Int ( n, Unsigned ( ity) ) => {
1157
- infer ( Infer ( n) , tcx, & ty:: TyUint ( ity) , span ) . map ( Integral )
1157
+ infer ( Infer ( n) , tcx, & ty:: TyUint ( ity) ) . map ( Integral )
1158
1158
} ,
1159
1159
1160
1160
LitKind :: Float ( ref n, _) |
0 commit comments