@@ -31,19 +31,21 @@ pub fn escape_byte_str_symbol(bytes: &[u8]) -> Symbol {
3131
3232#[ derive( Debug ) ]
3333pub 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
3939}
4040
4141impl LitKind {
4242 /// Converts literal token into a semantic literal.
4343 pub fn from_token_lit ( lit : token:: Lit ) -> Result < LitKind , LitError > {
4444 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) ) ;
4749 }
4850
4951 // For byte/char/string literals, chars and escapes have already been
@@ -271,12 +273,12 @@ fn filtered_float_lit(
271273 return Err ( LitError :: NonDecimalFloat ( base) ) ;
272274 }
273275 Ok ( match suffix {
274- Some ( suf ) => LitKind :: Float (
276+ Some ( suffix ) => LitKind :: Float (
275277 symbol,
276- ast:: LitFloatType :: Suffixed ( match suf {
278+ ast:: LitFloatType :: Suffixed ( match suffix {
277279 sym:: f32 => ast:: FloatTy :: F32 ,
278280 sym:: f64 => ast:: FloatTy :: F64 ,
279- _ => return Err ( LitError :: InvalidFloatSuffix ) ,
281+ _ => return Err ( LitError :: InvalidFloatSuffix ( suffix ) ) ,
280282 } ) ,
281283 ) ,
282284 None => LitKind :: Float ( symbol, ast:: LitFloatType :: Unsuffixed ) ,
@@ -317,7 +319,7 @@ fn integer_lit(symbol: Symbol, suffix: Option<Symbol>) -> Result<LitKind, LitErr
317319 // `1f64` and `2f32` etc. are valid float literals, and
318320 // `fxxx` looks more like an invalid float literal than invalid integer literal.
319321 _ 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 ) ) ,
321323 } ,
322324 _ => ast:: LitIntType :: Unsuffixed ,
323325 } ;
0 commit comments