@@ -3,6 +3,8 @@ use rustc_middle::mir::interpret::{LitToConstError, LitToConstInput};
33use rustc_middle:: ty:: { self , ParamEnv , ScalarInt , TyCtxt } ;
44use rustc_span:: DUMMY_SP ;
55
6+ use crate :: build:: parse_float_into_scalar;
7+
68pub ( crate ) fn lit_to_const < ' tcx > (
79 tcx : TyCtxt < ' tcx > ,
810 lit_input : LitToConstInput < ' tcx > ,
@@ -52,6 +54,17 @@ pub(crate) fn lit_to_const<'tcx>(
5254 ty:: ValTree :: from_scalar_int ( scalar_int)
5355 }
5456 ( 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+ }
5568 ( ast:: LitKind :: Char ( c) , ty:: Char ) => ty:: ValTree :: from_scalar_int ( ( * c) . into ( ) ) ,
5669 ( ast:: LitKind :: Err , _) => {
5770 return Err ( LitToConstError :: Reported (
0 commit comments