@@ -872,7 +872,7 @@ pub fn eval_const_expr_partial<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
872
872
debug ! ( "const call({:?})" , call_args) ;
873
873
eval_const_expr_partial ( tcx, & result, ty_hint, Some ( & call_args) ) ?
874
874
} ,
875
- hir:: ExprLit ( ref lit) => match lit_to_const ( & lit. node , tcx, ety, lit . span ) {
875
+ hir:: ExprLit ( ref lit) => match lit_to_const ( & lit. node , tcx, ety) {
876
876
Ok ( val) => val,
877
877
Err ( err) => signal ! ( e, err) ,
878
878
} ,
@@ -1208,8 +1208,7 @@ fn cast_const<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, val: ConstVal, ty: ty::Ty)
1208
1208
1209
1209
fn lit_to_const < ' a , ' tcx > ( lit : & ast:: LitKind ,
1210
1210
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1211
- ty_hint : Option < Ty < ' tcx > > ,
1212
- span : Span )
1211
+ ty_hint : Option < Ty < ' tcx > > )
1213
1212
-> Result < ConstVal , ErrKind > {
1214
1213
use syntax:: ast:: * ;
1215
1214
use syntax:: ast:: LitIntType :: * ;
@@ -1243,21 +1242,22 @@ fn lit_to_const<'a, 'tcx>(lit: &ast::LitKind,
1243
1242
} ,
1244
1243
1245
1244
LitKind :: Float ( ref n, fty) => {
1246
- Ok ( Float ( parse_float ( n, Some ( fty) , span ) ) )
1245
+ parse_float ( n, Some ( fty) ) . map ( Float )
1247
1246
}
1248
1247
LitKind :: FloatUnsuffixed ( ref n) => {
1249
1248
let fty_hint = match ty_hint. map ( |t| & t. sty ) {
1250
1249
Some ( & ty:: TyFloat ( fty) ) => Some ( fty) ,
1251
1250
_ => None
1252
1251
} ;
1253
- Ok ( Float ( parse_float ( n, fty_hint, span ) ) )
1252
+ parse_float ( n, fty_hint) . map ( Float )
1254
1253
}
1255
1254
LitKind :: Bool ( b) => Ok ( Bool ( b) ) ,
1256
1255
LitKind :: Char ( c) => Ok ( Char ( c) ) ,
1257
1256
}
1258
1257
}
1259
1258
1260
- fn parse_float ( num : & str , fty_hint : Option < ast:: FloatTy > , span : Span ) -> ConstFloat {
1259
+ fn parse_float ( num : & str , fty_hint : Option < ast:: FloatTy > )
1260
+ -> Result < ConstFloat , ErrKind > {
1261
1261
let val = match fty_hint {
1262
1262
Some ( ast:: FloatTy :: F32 ) => num. parse :: < f32 > ( ) . map ( F32 ) ,
1263
1263
Some ( ast:: FloatTy :: F64 ) => num. parse :: < f64 > ( ) . map ( F64 ) ,
@@ -1269,9 +1269,9 @@ fn parse_float(num: &str, fty_hint: Option<ast::FloatTy>, span: Span) -> ConstFl
1269
1269
} )
1270
1270
}
1271
1271
} ;
1272
- val. unwrap_or_else ( |_| {
1272
+ val. map_err ( |_| {
1273
1273
// FIXME(#31407) this is only necessary because float parsing is buggy
1274
- span_bug ! ( span , "could not evaluate float literal (see issue #31407)" ) ;
1274
+ UnimplementedConstVal ( "could not evaluate float literal (see issue #31407)" )
1275
1275
} )
1276
1276
}
1277
1277
0 commit comments