@@ -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
}
@@ -1716,15 +1716,34 @@ impl<'a> Parser<'a> {
1716
1716
self . num_bump_calls
1717
1717
}
1718
1718
1719
- pub fn uninterpolated_token_span ( & self ) -> Span {
1719
+ /// For interpolated `self.token`, returns a span of the fragment to which
1720
+ /// the interpolated token refers. For all other tokens this is just a
1721
+ /// regular span. It is particularly important to use this for identifiers
1722
+ /// and lifetimes for which spans affect name resolution and edition
1723
+ /// checks. Note that keywords are also identifiers, so they should use
1724
+ /// this if they keep spans or perform edition checks.
1725
+ pub fn token_uninterpolated_span ( & self ) -> Span {
1720
1726
match & self . token . kind {
1727
+ token:: NtIdent ( ident, _) | token:: NtLifetime ( ident, _) => ident. span ,
1721
1728
token:: Interpolated ( nt) => nt. use_span ( ) ,
1722
1729
token:: OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar ( _) ) ) => {
1723
1730
self . look_ahead ( 1 , |t| t. span )
1724
1731
}
1725
1732
_ => self . token . span ,
1726
1733
}
1727
1734
}
1735
+
1736
+ /// Like `token_uninterpolated_span`, but works on `self.prev_token`.
1737
+ pub fn prev_token_uninterpolated_span ( & self ) -> Span {
1738
+ match & self . prev_token . kind {
1739
+ token:: NtIdent ( ident, _) | token:: NtLifetime ( ident, _) => ident. span ,
1740
+ token:: Interpolated ( nt) => nt. use_span ( ) ,
1741
+ token:: OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar ( _) ) ) => {
1742
+ self . look_ahead ( 0 , |t| t. span )
1743
+ }
1744
+ _ => self . prev_token . span ,
1745
+ }
1746
+ }
1728
1747
}
1729
1748
1730
1749
pub ( crate ) fn make_unclosed_delims_error (
0 commit comments