@@ -31,20 +31,21 @@ pub fn escape_byte_str_symbol(bytes: &[u8]) -> Symbol {
3131
3232#[ derive( Debug ) ]  
3333pub  enum  LitError  { 
34-     LexerError , 
35-     InvalidSuffix , 
36-     InvalidIntSuffix , 
37-     InvalidFloatSuffix , 
38-     NonDecimalFloat ( u32 ) , 
39-     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 
4039} 
4140
4241impl  LitKind  { 
4342    /// Converts literal token into a semantic literal. 
4443     pub  fn  from_token_lit ( lit :  token:: Lit )  -> Result < LitKind ,  LitError >  { 
4544        let  token:: Lit  {  kind,  symbol,  suffix }  = lit; 
46-         if  suffix. is_some ( )  && !kind. may_have_suffix ( )  { 
47-             return  Err ( LitError :: InvalidSuffix ) ; 
45+         if  let  Some ( suffix)  = suffix
46+             && !kind. may_have_suffix ( ) 
47+         { 
48+             return  Err ( LitError :: InvalidSuffix ( suffix) ) ; 
4849        } 
4950
5051        // For byte/char/string literals, chars and escapes have already been 
@@ -145,7 +146,7 @@ impl LitKind {
145146                buf. push ( 0 ) ; 
146147                LitKind :: CStr ( buf. into ( ) ,  StrStyle :: Raw ( n) ) 
147148            } 
148-             token:: Err  => LitKind :: Err , 
149+             token:: Err ( guar )  => LitKind :: Err ( guar ) , 
149150        } ) 
150151    } 
151152} 
@@ -202,7 +203,7 @@ impl fmt::Display for LitKind {
202203                } 
203204            } 
204205            LitKind :: Bool ( b)  => write ! ( f,  "{}" ,  if  b {  "true"  }  else {  "false"  } ) ?, 
205-             LitKind :: Err  => { 
206+             LitKind :: Err ( _ )  => { 
206207                // This only shows up in places like `-Zunpretty=hir` output, so we 
207208                // don't bother to produce something useful. 
208209                write ! ( f,  "<bad-literal>" ) ?; 
@@ -238,7 +239,7 @@ impl MetaItemLit {
238239            LitKind :: Char ( _)  => token:: Char , 
239240            LitKind :: Int ( ..)  => token:: Integer , 
240241            LitKind :: Float ( ..)  => token:: Float , 
241-             LitKind :: Err  => token:: Err , 
242+             LitKind :: Err ( guar )  => token:: Err ( guar ) , 
242243        } ; 
243244
244245        token:: Lit :: new ( kind,  self . symbol ,  self . suffix ) 
@@ -272,12 +273,12 @@ fn filtered_float_lit(
272273        return  Err ( LitError :: NonDecimalFloat ( base) ) ; 
273274    } 
274275    Ok ( match  suffix { 
275-         Some ( suf )  => LitKind :: Float ( 
276+         Some ( suffix )  => LitKind :: Float ( 
276277            symbol, 
277-             ast:: LitFloatType :: Suffixed ( match  suf  { 
278+             ast:: LitFloatType :: Suffixed ( match  suffix  { 
278279                sym:: f32 => ast:: FloatTy :: F32 , 
279280                sym:: f64 => ast:: FloatTy :: F64 , 
280-                 _ => return  Err ( LitError :: InvalidFloatSuffix ) , 
281+                 _ => return  Err ( LitError :: InvalidFloatSuffix ( suffix ) ) , 
281282            } ) , 
282283        ) , 
283284        None  => LitKind :: Float ( symbol,  ast:: LitFloatType :: Unsuffixed ) , 
@@ -318,17 +319,13 @@ fn integer_lit(symbol: Symbol, suffix: Option<Symbol>) -> Result<LitKind, LitErr
318319            // `1f64` and `2f32` etc. are valid float literals, and 
319320            // `fxxx` looks more like an invalid float literal than invalid integer literal. 
320321            _ if  suf. as_str ( ) . starts_with ( 'f' )  => return  filtered_float_lit ( symbol,  suffix,  base) , 
321-             _ => return  Err ( LitError :: InvalidIntSuffix ) , 
322+             _ => return  Err ( LitError :: InvalidIntSuffix ( suf ) ) , 
322323        } , 
323324        _ => ast:: LitIntType :: Unsuffixed , 
324325    } ; 
325326
326327    let  s = & s[ if  base != 10  {  2  }  else  {  0  } ..] ; 
327-     u128:: from_str_radix ( s,  base) . map ( |i| LitKind :: Int ( i. into ( ) ,  ty) ) . map_err ( |_| { 
328-         // Small bases are lexed as if they were base 10, e.g, the string 
329-         // might be `0b10201`. This will cause the conversion above to fail, 
330-         // but these kinds of errors are already reported by the lexer. 
331-         let  from_lexer = base < 10  && s. chars ( ) . any ( |c| c. to_digit ( 10 ) . is_some_and ( |d| d >= base) ) ; 
332-         if  from_lexer {  LitError :: LexerError  }  else  {  LitError :: IntTooLarge ( base)  } 
333-     } ) 
328+     u128:: from_str_radix ( s,  base) 
329+         . map ( |i| LitKind :: Int ( i. into ( ) ,  ty) ) 
330+         . map_err ( |_| LitError :: IntTooLarge ( base) ) 
334331} 
0 commit comments