@@ -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 }
@@ -1716,15 +1716,34 @@ impl<'a> Parser<'a> {
17161716 self . num_bump_calls
17171717 }
17181718
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 {
17201726 match & self . token . kind {
1727+ token:: NtIdent ( ident, _) | token:: NtLifetime ( ident, _) => ident. span ,
17211728 token:: Interpolated ( nt) => nt. use_span ( ) ,
17221729 token:: OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar ( _) ) ) => {
17231730 self . look_ahead ( 1 , |t| t. span )
17241731 }
17251732 _ => self . token . span ,
17261733 }
17271734 }
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+ }
17281747}
17291748
17301749pub ( crate ) fn make_unclosed_delims_error (
0 commit comments