@@ -31,19 +31,21 @@ pub fn escape_byte_str_symbol(bytes: &[u8]) -> Symbol {
31
31
32
32
#[ derive( Debug ) ]
33
33
pub enum LitError {
34
- InvalidSuffix ,
35
- InvalidIntSuffix ,
36
- InvalidFloatSuffix ,
37
- NonDecimalFloat ( u32 ) ,
38
- IntTooLarge ( u32 ) ,
34
+ InvalidSuffix ( Symbol ) ,
35
+ InvalidIntSuffix ( Symbol ) ,
36
+ InvalidFloatSuffix ( Symbol ) ,
37
+ NonDecimalFloat ( u32 ) , // u32 is the base
38
+ IntTooLarge ( u32 ) , // u32 is the base
39
39
}
40
40
41
41
impl LitKind {
42
42
/// Converts literal token into a semantic literal.
43
43
pub fn from_token_lit ( lit : token:: Lit ) -> Result < LitKind , LitError > {
44
44
let token:: Lit { kind, symbol, suffix } = lit;
45
- if suffix. is_some ( ) && !kind. may_have_suffix ( ) {
46
- return Err ( LitError :: InvalidSuffix ) ;
45
+ if let Some ( suffix) = suffix
46
+ && !kind. may_have_suffix ( )
47
+ {
48
+ return Err ( LitError :: InvalidSuffix ( suffix) ) ;
47
49
}
48
50
49
51
// For byte/char/string literals, chars and escapes have already been
@@ -271,12 +273,12 @@ fn filtered_float_lit(
271
273
return Err ( LitError :: NonDecimalFloat ( base) ) ;
272
274
}
273
275
Ok ( match suffix {
274
- Some ( suf ) => LitKind :: Float (
276
+ Some ( suffix ) => LitKind :: Float (
275
277
symbol,
276
- ast:: LitFloatType :: Suffixed ( match suf {
278
+ ast:: LitFloatType :: Suffixed ( match suffix {
277
279
sym:: f32 => ast:: FloatTy :: F32 ,
278
280
sym:: f64 => ast:: FloatTy :: F64 ,
279
- _ => return Err ( LitError :: InvalidFloatSuffix ) ,
281
+ _ => return Err ( LitError :: InvalidFloatSuffix ( suffix ) ) ,
280
282
} ) ,
281
283
) ,
282
284
None => LitKind :: Float ( symbol, ast:: LitFloatType :: Unsuffixed ) ,
@@ -317,7 +319,7 @@ fn integer_lit(symbol: Symbol, suffix: Option<Symbol>) -> Result<LitKind, LitErr
317
319
// `1f64` and `2f32` etc. are valid float literals, and
318
320
// `fxxx` looks more like an invalid float literal than invalid integer literal.
319
321
_ if suf. as_str ( ) . starts_with ( 'f' ) => return filtered_float_lit ( symbol, suffix, base) ,
320
- _ => return Err ( LitError :: InvalidIntSuffix ) ,
322
+ _ => return Err ( LitError :: InvalidIntSuffix ( suf ) ) ,
321
323
} ,
322
324
_ => ast:: LitIntType :: Unsuffixed ,
323
325
} ;
0 commit comments