@@ -26,6 +26,7 @@ use middle::ty::{self, Ty};
2626use middle:: astconv_util:: ast_ty_to_prim_ty;
2727use util:: num:: ToPrimitive ;
2828use util:: nodemap:: NodeMap ;
29+ use session:: Session ;
2930
3031use graphviz:: IntoCow ;
3132use syntax:: ast;
@@ -1117,7 +1118,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
11171118 debug ! ( "const call({:?})" , call_args) ;
11181119 try!( eval_const_expr_partial ( tcx, & * * result, ty_hint, Some ( & call_args) ) )
11191120 } ,
1120- hir:: ExprLit ( ref lit) => lit_to_const ( & * * lit, ety) ,
1121+ hir:: ExprLit ( ref lit) => lit_to_const ( tcx . sess , e . span , & * * lit, ety) ,
11211122 hir:: ExprBlock ( ref block) => {
11221123 match block. expr {
11231124 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 {
13191320 }
13201321}
13211322
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 {
13231324 match lit. node {
13241325 ast:: LitStr ( ref s, _) => Str ( ( * s) . clone ( ) ) ,
13251326 ast:: LitByteStr ( ref data) => {
@@ -1339,7 +1340,12 @@ fn lit_to_const(lit: &ast::Lit, ty_hint: Option<Ty>) -> ConstVal {
13391340 ast:: LitInt ( n, ast:: UnsignedIntLit ( _) ) => Uint ( n) ,
13401341 ast:: LitFloat ( ref n, _) |
13411342 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+ }
13431349 }
13441350 ast:: LitBool ( b) => Bool ( b)
13451351 }
0 commit comments