@@ -1313,14 +1313,14 @@ impl<'a> Parser<'a> {
13131313
13141314 /// Parses asyncness: `async` or nothing.
13151315 fn parse_coroutine_kind ( & mut self , case : Case ) -> Option < CoroutineKind > {
1316- let span = self . token . uninterpolated_span ( ) ;
1316+ let span = self . token_uninterpolated_span ( ) ;
13171317 if self . eat_keyword_case ( exp ! ( Async ) , case) {
13181318 // FIXME(gen_blocks): Do we want to unconditionally parse `gen` and then
13191319 // 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 ( )
13211321 && self . eat_keyword_case ( exp ! ( Gen ) , case)
13221322 {
1323- let gen_span = self . prev_token . uninterpolated_span ( ) ;
1323+ let gen_span = self . prev_token_uninterpolated_span ( ) ;
13241324 Some ( CoroutineKind :: AsyncGen {
13251325 span : span. to ( gen_span) ,
13261326 closure_id : DUMMY_NODE_ID ,
@@ -1333,7 +1333,7 @@ impl<'a> Parser<'a> {
13331333 return_impl_trait_id : DUMMY_NODE_ID ,
13341334 } )
13351335 }
1336- } else if self . token . uninterpolated_span ( ) . at_least_rust_2024 ( )
1336+ } else if self . token_uninterpolated_span ( ) . at_least_rust_2024 ( )
13371337 && self . eat_keyword_case ( exp ! ( Gen ) , case)
13381338 {
13391339 Some ( CoroutineKind :: Gen {
@@ -1349,9 +1349,9 @@ impl<'a> Parser<'a> {
13491349 /// Parses fn unsafety: `unsafe`, `safe` or nothing.
13501350 fn parse_safety ( & mut self , case : Case ) -> Safety {
13511351 if self . eat_keyword_case ( exp ! ( Unsafe ) , case) {
1352- Safety :: Unsafe ( self . prev_token . uninterpolated_span ( ) )
1352+ Safety :: Unsafe ( self . prev_token_uninterpolated_span ( ) )
13531353 } 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 ( ) )
13551355 } else {
13561356 Safety :: Default
13571357 }
@@ -1378,7 +1378,7 @@ impl<'a> Parser<'a> {
13781378 . look_ahead ( 1 , |t| * t == token:: OpenDelim ( Delimiter :: Brace ) || t. is_whole_block ( ) )
13791379 && self . eat_keyword_case ( exp ! ( Const ) , case)
13801380 {
1381- Const :: Yes ( self . prev_token . uninterpolated_span ( ) )
1381+ Const :: Yes ( self . prev_token_uninterpolated_span ( ) )
13821382 } else {
13831383 Const :: No
13841384 }
@@ -1723,15 +1723,34 @@ impl<'a> Parser<'a> {
17231723 self . num_bump_calls
17241724 }
17251725
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 {
17271733 match & self . token . kind {
1734+ token:: NtIdent ( ident, _) | token:: NtLifetime ( ident, _) => ident. span ,
17281735 token:: Interpolated ( nt) => nt. use_span ( ) ,
17291736 token:: OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar ( _) ) ) => {
17301737 self . look_ahead ( 1 , |t| t. span )
17311738 }
17321739 _ => self . token . span ,
17331740 }
17341741 }
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+ }
17351754}
17361755
17371756pub ( crate ) fn make_unclosed_delims_error (
0 commit comments