@@ -1423,15 +1423,17 @@ impl<'a> StringReader<'a> {
14231423
14241424 // If the character is an ident start not followed by another single
14251425 // quote, then this is a lifetime name:
1426- if ident_start ( Some ( c2) ) && !self . ch_is ( '\'' ) {
1426+ if ( ident_start ( Some ( c2) ) || c2 . is_numeric ( ) ) && !self . ch_is ( '\'' ) {
14271427 while ident_continue ( self . ch ) {
14281428 self . bump ( ) ;
14291429 }
14301430 // lifetimes shouldn't end with a single quote
14311431 // if we find one, then this is an invalid character literal
14321432 if self . ch_is ( '\'' ) {
1433- self . err_span_ ( start_with_quote, self . next_pos ,
1434- "character literal may only contain one codepoint" ) ;
1433+ self . err_span_ (
1434+ start_with_quote,
1435+ self . next_pos ,
1436+ "character literal may only contain one codepoint" ) ;
14351437 self . bump ( ) ;
14361438 return Ok ( token:: Literal ( token:: Err ( Symbol :: intern ( "??" ) ) , None ) )
14371439
@@ -1444,6 +1446,16 @@ impl<'a> StringReader<'a> {
14441446 self . mk_ident ( & format ! ( "'{}" , lifetime_name) )
14451447 } ) ;
14461448
1449+ if c2. is_numeric ( ) {
1450+ // this is a recovered lifetime written `'1`, error but accept it
1451+ self . err_span_ (
1452+ start_with_quote,
1453+ self . pos ,
1454+ "lifetimes can't start with a number" ,
1455+ ) ;
1456+ }
1457+
1458+
14471459 return Ok ( token:: Lifetime ( ident) ) ;
14481460 }
14491461
@@ -1873,13 +1885,14 @@ fn is_block_doc_comment(s: &str) -> bool {
18731885 res
18741886}
18751887
1888+ /// Determine whether `c` is a valid start for an ident.
18761889fn ident_start ( c : Option < char > ) -> bool {
18771890 let c = match c {
18781891 Some ( c) => c,
18791892 None => return false ,
18801893 } ;
18811894
1882- ( c >= 'a' && c <= 'z' ) || ( c >= 'A' && c <= 'Z' ) || c == '_' || ( c > '\x7f' && c. is_xid_start ( ) )
1895+ ( c. is_alphabetic ( ) || c == '_' || ( c > '\x7f' && c. is_xid_start ( ) ) )
18831896}
18841897
18851898fn ident_continue ( c : Option < char > ) -> bool {
@@ -1888,8 +1901,7 @@ fn ident_continue(c: Option<char>) -> bool {
18881901 None => return false ,
18891902 } ;
18901903
1891- ( c >= 'a' && c <= 'z' ) || ( c >= 'A' && c <= 'Z' ) || ( c >= '0' && c <= '9' ) || c == '_' ||
1892- ( c > '\x7f' && c. is_xid_continue ( ) )
1904+ ( c. is_alphabetic ( ) || c. is_numeric ( ) || c == '_' || ( c > '\x7f' && c. is_xid_continue ( ) ) )
18931905}
18941906
18951907#[ inline]
0 commit comments