@@ -26,6 +26,7 @@ use middle::ty::{self, Ty};
26
26
use middle:: astconv_util:: ast_ty_to_prim_ty;
27
27
use util:: num:: ToPrimitive ;
28
28
use util:: nodemap:: NodeMap ;
29
+ use session:: Session ;
29
30
30
31
use graphviz:: IntoCow ;
31
32
use syntax:: ast;
@@ -1117,7 +1118,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
1117
1118
debug ! ( "const call({:?})" , call_args) ;
1118
1119
try!( eval_const_expr_partial ( tcx, & * * result, ty_hint, Some ( & call_args) ) )
1119
1120
} ,
1120
- hir:: ExprLit ( ref lit) => lit_to_const ( & * * lit, ety) ,
1121
+ hir:: ExprLit ( ref lit) => lit_to_const ( tcx . sess , e . span , & * * lit, ety) ,
1121
1122
hir:: ExprBlock ( ref block) => {
1122
1123
match block. expr {
1123
1124
Some ( ref expr) => try!( eval_const_expr_partial ( tcx, & * * expr, ty_hint, fn_args) ) ,
@@ -1319,7 +1320,7 @@ fn cast_const<'tcx>(tcx: &ty::ctxt<'tcx>, val: ConstVal, ty: Ty) -> CastResult {
1319
1320
}
1320
1321
}
1321
1322
1322
- fn lit_to_const ( lit : & ast:: Lit , ty_hint : Option < Ty > ) -> ConstVal {
1323
+ fn lit_to_const ( sess : & Session , span : Span , lit : & ast:: Lit , ty_hint : Option < Ty > ) -> ConstVal {
1323
1324
match lit. node {
1324
1325
ast:: LitStr ( ref s, _) => Str ( ( * s) . clone ( ) ) ,
1325
1326
ast:: LitByteStr ( ref data) => {
@@ -1339,7 +1340,12 @@ fn lit_to_const(lit: &ast::Lit, ty_hint: Option<Ty>) -> ConstVal {
1339
1340
ast:: LitInt ( n, ast:: UnsignedIntLit ( _) ) => Uint ( n) ,
1340
1341
ast:: LitFloat ( ref n, _) |
1341
1342
ast:: LitFloatUnsuffixed ( ref n) => {
1342
- Float ( n. parse :: < f64 > ( ) . unwrap ( ) as f64 )
1343
+ if let Ok ( x) = n. parse :: < f64 > ( ) {
1344
+ Float ( x)
1345
+ } else {
1346
+ // FIXME(#31407) this is only necessary because float parsing is buggy
1347
+ sess. span_bug ( span, "could not evaluate float literal (see issue #31407)" ) ;
1348
+ }
1343
1349
}
1344
1350
ast:: LitBool ( b) => Bool ( b)
1345
1351
}
0 commit comments