@@ -1423,15 +1423,17 @@ impl<'a> StringReader<'a> {
1423
1423
1424
1424
// If the character is an ident start not followed by another single
1425
1425
// 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 ( '\'' ) {
1427
1427
while ident_continue ( self . ch ) {
1428
1428
self . bump ( ) ;
1429
1429
}
1430
1430
// lifetimes shouldn't end with a single quote
1431
1431
// if we find one, then this is an invalid character literal
1432
1432
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" ) ;
1435
1437
self . bump ( ) ;
1436
1438
return Ok ( token:: Literal ( token:: Err ( Symbol :: intern ( "??" ) ) , None ) )
1437
1439
@@ -1444,6 +1446,16 @@ impl<'a> StringReader<'a> {
1444
1446
self . mk_ident ( & format ! ( "'{}" , lifetime_name) )
1445
1447
} ) ;
1446
1448
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
+
1447
1459
return Ok ( token:: Lifetime ( ident) ) ;
1448
1460
}
1449
1461
@@ -1873,13 +1885,14 @@ fn is_block_doc_comment(s: &str) -> bool {
1873
1885
res
1874
1886
}
1875
1887
1888
+ /// Determine whether `c` is a valid start for an ident.
1876
1889
fn ident_start ( c : Option < char > ) -> bool {
1877
1890
let c = match c {
1878
1891
Some ( c) => c,
1879
1892
None => return false ,
1880
1893
} ;
1881
1894
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 ( ) ) )
1883
1896
}
1884
1897
1885
1898
fn ident_continue ( c : Option < char > ) -> bool {
@@ -1888,8 +1901,7 @@ fn ident_continue(c: Option<char>) -> bool {
1888
1901
None => return false ,
1889
1902
} ;
1890
1903
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 ( ) ) )
1893
1905
}
1894
1906
1895
1907
#[ inline]
0 commit comments