@@ -34,6 +34,7 @@ use std::fmt;
34
34
use syntax:: ast;
35
35
use syntax:: ptr:: P ;
36
36
use syntax_pos:: Span ;
37
+ use syntax_pos:: symbol:: Symbol ;
37
38
38
39
#[ derive( Clone , Debug ) ]
39
40
pub enum PatternError {
@@ -1145,16 +1146,14 @@ fn lit_to_const<'a, 'tcx>(lit: &'tcx ast::LitKind,
1145
1146
Value :: ByVal ( PrimVal :: Bytes ( n) )
1146
1147
} ,
1147
1148
LitKind :: Float ( n, fty) => {
1148
- let n = n. as_str ( ) ;
1149
- parse_float ( & n, fty, neg) . map_err ( |_| ( ) ) ?
1149
+ parse_float ( n, fty, neg) ?
1150
1150
}
1151
1151
LitKind :: FloatUnsuffixed ( n) => {
1152
1152
let fty = match ty. sty {
1153
1153
ty:: TyFloat ( fty) => fty,
1154
1154
_ => bug ! ( )
1155
1155
} ;
1156
- let n = n. as_str ( ) ;
1157
- parse_float ( & n, fty, neg) . map_err ( |_| ( ) ) ?
1156
+ parse_float ( n, fty, neg) ?
1158
1157
}
1159
1158
LitKind :: Bool ( b) => Value :: ByVal ( PrimVal :: Bytes ( b as u128 ) ) ,
1160
1159
LitKind :: Char ( c) => Value :: ByVal ( PrimVal :: Bytes ( c as u128 ) ) ,
@@ -1163,26 +1162,29 @@ fn lit_to_const<'a, 'tcx>(lit: &'tcx ast::LitKind,
1163
1162
}
1164
1163
1165
1164
pub fn parse_float (
1166
- num : & str ,
1165
+ num : Symbol ,
1167
1166
fty : ast:: FloatTy ,
1168
1167
neg : bool ,
1169
- ) -> Result < Value , String > {
1168
+ ) -> Result < Value , ( ) > {
1169
+ let num = num. as_str ( ) ;
1170
1170
use rustc_apfloat:: ieee:: { Single , Double } ;
1171
1171
use rustc_apfloat:: Float ;
1172
1172
let bits = match fty {
1173
1173
ast:: FloatTy :: F32 => {
1174
- let mut f = num. parse :: < Single > ( ) . map_err ( |e| {
1175
- format ! ( "apfloat::ieee::Single failed to parse `{}`: {:?}" , num, e)
1176
- } ) ?;
1174
+ num. parse :: < f32 > ( ) . map_err ( |_| ( ) ) ?;
1175
+ let mut f = num. parse :: < Single > ( ) . unwrap_or_else ( |e| {
1176
+ panic ! ( "apfloat::ieee::Single failed to parse `{}`: {:?}" , num, e)
1177
+ } ) ;
1177
1178
if neg {
1178
1179
f = -f;
1179
1180
}
1180
1181
f. to_bits ( )
1181
1182
}
1182
1183
ast:: FloatTy :: F64 => {
1183
- let mut f = num. parse :: < Double > ( ) . map_err ( |e| {
1184
- format ! ( "apfloat::ieee::Single failed to parse `{}`: {:?}" , num, e)
1185
- } ) ?;
1184
+ num. parse :: < f64 > ( ) . map_err ( |_| ( ) ) ?;
1185
+ let mut f = num. parse :: < Double > ( ) . unwrap_or_else ( |e| {
1186
+ panic ! ( "apfloat::ieee::Single failed to parse `{}`: {:?}" , num, e)
1187
+ } ) ;
1186
1188
if neg {
1187
1189
f = -f;
1188
1190
}
0 commit comments