@@ -152,7 +152,7 @@ impl Constant {
152152}
153153
154154/// Parses a `LitKind` to a `Constant`.
155- pub fn lit_to_constant ( lit : & LitKind , ty : Ty < ' _ > ) -> Constant {
155+ pub fn lit_to_constant ( lit : & LitKind , ty : Option < Ty < ' _ > > ) -> Constant {
156156 use syntax:: ast:: * ;
157157
158158 match * lit {
@@ -161,7 +161,9 @@ pub fn lit_to_constant(lit: &LitKind, ty: Ty<'_>) -> Constant {
161161 LitKind :: ByteStr ( ref s) => Constant :: Binary ( Lrc :: clone ( s) ) ,
162162 LitKind :: Char ( c) => Constant :: Char ( c) ,
163163 LitKind :: Int ( n, _) => Constant :: Int ( n) ,
164- LitKind :: Float ( ref is, _) | LitKind :: FloatUnsuffixed ( ref is) => match ty. kind {
164+ LitKind :: Float ( ref is, FloatTy :: F32 ) => Constant :: F32 ( is. as_str ( ) . parse ( ) . unwrap ( ) ) ,
165+ LitKind :: Float ( ref is, FloatTy :: F64 ) => Constant :: F64 ( is. as_str ( ) . parse ( ) . unwrap ( ) ) ,
166+ LitKind :: FloatUnsuffixed ( ref is) => match ty. expect ( "type of float is known" ) . kind {
165167 ty:: Float ( FloatTy :: F32 ) => Constant :: F32 ( is. as_str ( ) . parse ( ) . unwrap ( ) ) ,
166168 ty:: Float ( FloatTy :: F64 ) => Constant :: F64 ( is. as_str ( ) . parse ( ) . unwrap ( ) ) ,
167169 _ => bug ! ( ) ,
@@ -225,7 +227,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
225227 match e. kind {
226228 ExprKind :: Path ( ref qpath) => self . fetch_path ( qpath, e. hir_id ) ,
227229 ExprKind :: Block ( ref block, _) => self . block ( block) ,
228- ExprKind :: Lit ( ref lit) => Some ( lit_to_constant ( & lit. node , self . tables . expr_ty ( e) ) ) ,
230+ ExprKind :: Lit ( ref lit) => Some ( lit_to_constant ( & lit. node , self . tables . expr_ty_opt ( e) ) ) ,
229231 ExprKind :: Array ( ref vec) => self . multi ( vec) . map ( Constant :: Vec ) ,
230232 ExprKind :: Tup ( ref tup) => self . multi ( tup) . map ( Constant :: Tuple ) ,
231233 ExprKind :: Repeat ( ref value, _) => {
0 commit comments