@@ -152,7 +152,7 @@ impl Constant {
152
152
}
153
153
154
154
/// 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 {
156
156
use syntax:: ast:: * ;
157
157
158
158
match * lit {
@@ -161,7 +161,9 @@ pub fn lit_to_constant(lit: &LitKind, ty: Ty<'_>) -> Constant {
161
161
LitKind :: ByteStr ( ref s) => Constant :: Binary ( Lrc :: clone ( s) ) ,
162
162
LitKind :: Char ( c) => Constant :: Char ( c) ,
163
163
LitKind :: Int ( n, _) => Constant :: Int ( n) ,
164
- LitKind :: Float ( ref is, _) | LitKind :: FloatUnsuffixed ( ref is) => match ty. sty {
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" ) . sty {
165
167
ty:: Float ( FloatTy :: F32 ) => Constant :: F32 ( is. as_str ( ) . parse ( ) . unwrap ( ) ) ,
166
168
ty:: Float ( FloatTy :: F64 ) => Constant :: F64 ( is. as_str ( ) . parse ( ) . unwrap ( ) ) ,
167
169
_ => bug ! ( ) ,
@@ -225,7 +227,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
225
227
match e. node {
226
228
ExprKind :: Path ( ref qpath) => self . fetch_path ( qpath, e. hir_id ) ,
227
229
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) ) ) ,
229
231
ExprKind :: Array ( ref vec) => self . multi ( vec) . map ( Constant :: Vec ) ,
230
232
ExprKind :: Tup ( ref tup) => self . multi ( tup) . map ( Constant :: Tuple ) ,
231
233
ExprKind :: Repeat ( ref value, _) => {
0 commit comments