@@ -3,6 +3,8 @@ use rustc_middle::mir::interpret::{LitToConstError, LitToConstInput};
3
3
use rustc_middle:: ty:: { self , ParamEnv , ScalarInt , TyCtxt } ;
4
4
use rustc_span:: DUMMY_SP ;
5
5
6
+ use crate :: build:: parse_float_into_scalar;
7
+
6
8
pub ( crate ) fn lit_to_const < ' tcx > (
7
9
tcx : TyCtxt < ' tcx > ,
8
10
lit_input : LitToConstInput < ' tcx > ,
@@ -52,6 +54,17 @@ pub(crate) fn lit_to_const<'tcx>(
52
54
ty:: ValTree :: from_scalar_int ( scalar_int)
53
55
}
54
56
( ast:: LitKind :: Bool ( b) , ty:: Bool ) => ty:: ValTree :: from_scalar_int ( ( * b) . into ( ) ) ,
57
+ ( ast:: LitKind :: Float ( n, _) , ty:: Float ( fty) ) => {
58
+ let bits = parse_float_into_scalar ( * n, * fty, neg)
59
+ . ok_or_else ( || {
60
+ LitToConstError :: Reported ( tcx. sess . delay_span_bug (
61
+ DUMMY_SP ,
62
+ format ! ( "couldn't parse float literal: {:?}" , lit_input. lit) ,
63
+ ) )
64
+ } ) ?
65
+ . assert_int ( ) ;
66
+ ty:: ValTree :: from_scalar_int ( bits)
67
+ }
55
68
( ast:: LitKind :: Char ( c) , ty:: Char ) => ty:: ValTree :: from_scalar_int ( ( * c) . into ( ) ) ,
56
69
( ast:: LitKind :: Err , _) => {
57
70
return Err ( LitToConstError :: Reported (
0 commit comments