@@ -1313,14 +1313,14 @@ impl<'a> Parser<'a> {
1313
1313
1314
1314
/// Parses asyncness: `async` or nothing.
1315
1315
fn parse_coroutine_kind ( & mut self , case : Case ) -> Option < CoroutineKind > {
1316
- let span = self . token . uninterpolated_span ( ) ;
1316
+ let span = self . token_uninterpolated_span ( ) ;
1317
1317
if self . eat_keyword_case ( exp ! ( Async ) , case) {
1318
1318
// FIXME(gen_blocks): Do we want to unconditionally parse `gen` and then
1319
1319
// error if edition <= 2024, like we do with async and edition <= 2018?
1320
- if self . token . uninterpolated_span ( ) . at_least_rust_2024 ( )
1320
+ if self . token_uninterpolated_span ( ) . at_least_rust_2024 ( )
1321
1321
&& self . eat_keyword_case ( exp ! ( Gen ) , case)
1322
1322
{
1323
- let gen_span = self . prev_token . uninterpolated_span ( ) ;
1323
+ let gen_span = self . prev_token_uninterpolated_span ( ) ;
1324
1324
Some ( CoroutineKind :: AsyncGen {
1325
1325
span : span. to ( gen_span) ,
1326
1326
closure_id : DUMMY_NODE_ID ,
@@ -1333,7 +1333,7 @@ impl<'a> Parser<'a> {
1333
1333
return_impl_trait_id : DUMMY_NODE_ID ,
1334
1334
} )
1335
1335
}
1336
- } else if self . token . uninterpolated_span ( ) . at_least_rust_2024 ( )
1336
+ } else if self . token_uninterpolated_span ( ) . at_least_rust_2024 ( )
1337
1337
&& self . eat_keyword_case ( exp ! ( Gen ) , case)
1338
1338
{
1339
1339
Some ( CoroutineKind :: Gen {
@@ -1349,9 +1349,9 @@ impl<'a> Parser<'a> {
1349
1349
/// Parses fn unsafety: `unsafe`, `safe` or nothing.
1350
1350
fn parse_safety ( & mut self , case : Case ) -> Safety {
1351
1351
if self . eat_keyword_case ( exp ! ( Unsafe ) , case) {
1352
- Safety :: Unsafe ( self . prev_token . uninterpolated_span ( ) )
1352
+ Safety :: Unsafe ( self . prev_token_uninterpolated_span ( ) )
1353
1353
} else if self . eat_keyword_case ( exp ! ( Safe ) , case) {
1354
- Safety :: Safe ( self . prev_token . uninterpolated_span ( ) )
1354
+ Safety :: Safe ( self . prev_token_uninterpolated_span ( ) )
1355
1355
} else {
1356
1356
Safety :: Default
1357
1357
}
@@ -1378,7 +1378,7 @@ impl<'a> Parser<'a> {
1378
1378
. look_ahead ( 1 , |t| * t == token:: OpenDelim ( Delimiter :: Brace ) || t. is_whole_block ( ) )
1379
1379
&& self . eat_keyword_case ( exp ! ( Const ) , case)
1380
1380
{
1381
- Const :: Yes ( self . prev_token . uninterpolated_span ( ) )
1381
+ Const :: Yes ( self . prev_token_uninterpolated_span ( ) )
1382
1382
} else {
1383
1383
Const :: No
1384
1384
}
@@ -1723,15 +1723,34 @@ impl<'a> Parser<'a> {
1723
1723
self . num_bump_calls
1724
1724
}
1725
1725
1726
- pub fn uninterpolated_token_span ( & self ) -> Span {
1726
+ /// For interpolated `self.token`, returns a span of the fragment to which
1727
+ /// the interpolated token refers. For all other tokens this is just a
1728
+ /// regular span. It is particularly important to use this for identifiers
1729
+ /// and lifetimes for which spans affect name resolution and edition
1730
+ /// checks. Note that keywords are also identifiers, so they should use
1731
+ /// this if they keep spans or perform edition checks.
1732
+ pub fn token_uninterpolated_span ( & self ) -> Span {
1727
1733
match & self . token . kind {
1734
+ token:: NtIdent ( ident, _) | token:: NtLifetime ( ident, _) => ident. span ,
1728
1735
token:: Interpolated ( nt) => nt. use_span ( ) ,
1729
1736
token:: OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar ( _) ) ) => {
1730
1737
self . look_ahead ( 1 , |t| t. span )
1731
1738
}
1732
1739
_ => self . token . span ,
1733
1740
}
1734
1741
}
1742
+
1743
+ /// Like `token_uninterpolated_span`, but works on `self.prev_token`.
1744
+ pub fn prev_token_uninterpolated_span ( & self ) -> Span {
1745
+ match & self . prev_token . kind {
1746
+ token:: NtIdent ( ident, _) | token:: NtLifetime ( ident, _) => ident. span ,
1747
+ token:: Interpolated ( nt) => nt. use_span ( ) ,
1748
+ token:: OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar ( _) ) ) => {
1749
+ self . look_ahead ( 0 , |t| t. span )
1750
+ }
1751
+ _ => self . prev_token . span ,
1752
+ }
1753
+ }
1735
1754
}
1736
1755
1737
1756
pub ( crate ) fn make_unclosed_delims_error (
0 commit comments