Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 56d9dbf

Browse files
committed
Remove NtPath.
1 parent 51809b2 commit 56d9dbf

File tree

12 files changed

+42
-48
lines changed

12 files changed

+42
-48
lines changed

compiler/rustc_ast/src/ast_traits.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,12 @@ impl HasTokens for Nonterminal {
232232
fn tokens(&self) -> Option<&LazyAttrTokenStream> {
233233
match self {
234234
Nonterminal::NtExpr(expr) | Nonterminal::NtLiteral(expr) => expr.tokens(),
235-
Nonterminal::NtPath(path) => path.tokens(),
236235
Nonterminal::NtBlock(block) => block.tokens(),
237236
}
238237
}
239238
fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>> {
240239
match self {
241240
Nonterminal::NtExpr(expr) | Nonterminal::NtLiteral(expr) => expr.tokens_mut(),
242-
Nonterminal::NtPath(path) => path.tokens_mut(),
243241
Nonterminal::NtBlock(block) => block.tokens_mut(),
244242
}
245243
}

compiler/rustc_ast/src/attr/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,14 +364,12 @@ impl MetaItem {
364364
let span = span.with_hi(segments.last().unwrap().ident.span.hi());
365365
Path { span, segments, tokens: None }
366366
}
367-
Some(TokenTree::Token(Token { kind: token::Interpolated(nt), .. }, _)) => match &**nt {
368-
token::Nonterminal::NtPath(path) => (**path).clone(),
369-
_ => return None,
370-
},
371367
Some(TokenTree::Delimited(
372368
_span,
373369
_spacing,
374-
Delimiter::Invisible(InvisibleOrigin::MetaVar(NonterminalKind::Meta)),
370+
Delimiter::Invisible(InvisibleOrigin::MetaVar(
371+
NonterminalKind::Meta | NonterminalKind::Path,
372+
)),
375373
_stream,
376374
)) => {
377375
// This path is currently unreachable in the test suite.

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,6 @@ fn visit_nonterminal<T: MutVisitor>(nt: &mut token::Nonterminal, vis: &mut T) {
822822
token::NtBlock(block) => vis.visit_block(block),
823823
token::NtExpr(expr) => vis.visit_expr(expr),
824824
token::NtLiteral(expr) => vis.visit_expr(expr),
825-
token::NtPath(path) => vis.visit_path(path),
826825
}
827826
}
828827

compiler/rustc_ast/src/token.rs

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,7 @@ impl Token {
535535
Pound => true, // expression attributes
536536
Interpolated(ref nt) => matches!(&**nt, NtLiteral(..) |
537537
NtExpr(..) |
538-
NtBlock(..) |
539-
NtPath(..)),
538+
NtBlock(..)),
540539
OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(
541540
NonterminalKind::Block |
542541
NonterminalKind::Expr(_) |
@@ -563,9 +562,7 @@ impl Token {
563562
| DotDot | DotDotDot | DotDotEq // ranges
564563
| Lt | BinOp(Shl) // associated path
565564
| PathSep => true, // global path
566-
Interpolated(ref nt) => matches!(&**nt, NtLiteral(..) |
567-
NtBlock(..) |
568-
NtPath(..)),
565+
Interpolated(ref nt) => matches!(&**nt, NtLiteral(..) | NtBlock(..)),
569566
OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(
570567
NonterminalKind::Block |
571568
NonterminalKind::Pat(_) |
@@ -591,7 +588,6 @@ impl Token {
591588
Lifetime(..) | // lifetime bound in trait object
592589
Lt | BinOp(Shl) | // associated path
593590
PathSep => true, // global path
594-
Interpolated(ref nt) => matches!(&**nt, NtPath(..)),
595591
OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(
596592
NonterminalKind::Ty |
597593
NonterminalKind::Path
@@ -740,29 +736,20 @@ impl Token {
740736
self.ident().is_some_and(|(ident, _)| ident.name == name)
741737
}
742738

743-
/// Returns `true` if the token is an interpolated path.
744-
fn is_whole_path(&self) -> bool {
745-
if let Interpolated(nt) = &self.kind
746-
&& let NtPath(..) = &**nt
747-
{
748-
return true;
749-
}
750-
751-
false
752-
}
753-
754739
/// Would `maybe_whole_expr` in `parser.rs` return `Ok(..)`?
755740
/// That is, is this a pre-parsed expression dropped into the token stream
756741
/// (which happens while parsing the result of macro expansion)?
757742
pub fn is_whole_expr(&self) -> bool {
758743
#[allow(irrefutable_let_patterns)] // njn: temp
759744
if let Interpolated(nt) = &self.kind
760-
&& let NtExpr(_) | NtLiteral(_) | NtPath(_) | NtBlock(_) = &**nt
745+
&& let NtExpr(_) | NtLiteral(_) = &**nt
761746
{
762-
return true;
747+
true
748+
} else if matches!(self.is_metavar_seq(), Some(NonterminalKind::Path)) {
749+
true
750+
} else {
751+
false
763752
}
764-
765-
false
766753
}
767754

768755
/// Is the token an interpolated block (`$b:block`)?
@@ -788,7 +775,7 @@ impl Token {
788775
pub fn is_path_start(&self) -> bool {
789776
self == &PathSep
790777
|| self.is_qpath_start()
791-
|| self.is_whole_path()
778+
|| matches!(self.is_metavar_seq(), Some(NonterminalKind::Path))
792779
|| self.is_path_segment_keyword()
793780
|| self.is_ident() && !self.is_reserved_ident()
794781
}
@@ -962,7 +949,6 @@ pub enum Nonterminal {
962949
NtBlock(P<ast::Block>),
963950
NtExpr(P<ast::Expr>),
964951
NtLiteral(P<ast::Expr>),
965-
NtPath(P<ast::Path>),
966952
}
967953

968954
#[derive(Debug, Copy, Clone, PartialEq, Eq, Encodable, Decodable, Hash, HashStable_Generic)]
@@ -1053,7 +1039,6 @@ impl Nonterminal {
10531039
match self {
10541040
NtBlock(block) => block.span,
10551041
NtExpr(expr) | NtLiteral(expr) => expr.span,
1056-
NtPath(path) => path.span,
10571042
}
10581043
}
10591044

@@ -1062,7 +1047,6 @@ impl Nonterminal {
10621047
NtBlock(..) => "block",
10631048
NtExpr(..) => "expression",
10641049
NtLiteral(..) => "literal",
1065-
NtPath(..) => "path",
10661050
}
10671051
}
10681052
}
@@ -1083,7 +1067,6 @@ impl fmt::Debug for Nonterminal {
10831067
NtBlock(..) => f.pad("NtBlock(..)"),
10841068
NtExpr(..) => f.pad("NtExpr(..)"),
10851069
NtLiteral(..) => f.pad("NtLiteral(..)"),
1086-
NtPath(..) => f.pad("NtPath(..)"),
10871070
}
10881071
}
10891072
}

compiler/rustc_ast/src/tokenstream.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,6 @@ impl TokenStream {
467467
pub fn from_nonterminal_ast(nt: &Nonterminal) -> TokenStream {
468468
match nt {
469469
Nonterminal::NtBlock(block) => TokenStream::from_ast(block),
470-
Nonterminal::NtPath(path) => TokenStream::from_ast(path),
471470
Nonterminal::NtExpr(expr) | Nonterminal::NtLiteral(expr) => TokenStream::from_ast(expr),
472471
}
473472
}

compiler/rustc_expand/src/mbe/transcribe.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,9 @@ pub(super) fn transcribe<'a>(
319319
MatchedSingle(ParseNtResult::Meta(ref meta)) => {
320320
mk_delimited(NonterminalKind::Meta, TokenStream::from_ast(meta))
321321
}
322+
MatchedSingle(ParseNtResult::Path(ref path)) => {
323+
mk_delimited(NonterminalKind::Path, TokenStream::from_ast(path))
324+
}
322325
MatchedSingle(ParseNtResult::Vis(ref vis)) => {
323326
mk_delimited(NonterminalKind::Vis, TokenStream::from_ast(vis))
324327
}

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,28 @@ use tracing::instrument;
4646
/// `token::Interpolated` tokens.
4747
macro_rules! maybe_whole_expr {
4848
($p:expr) => {
49+
let span = $p.token.span;
4950
if let token::Interpolated(nt) = &$p.token.kind {
5051
match &**nt {
5152
token::NtExpr(e) | token::NtLiteral(e) => {
5253
let e = e.clone();
5354
$p.bump();
5455
return Ok(e);
5556
}
56-
token::NtPath(path) => {
57-
let path = (**path).clone();
58-
$p.bump();
59-
return Ok($p.mk_expr($p.prev_token.span, ExprKind::Path(None, path)));
60-
}
6157
token::NtBlock(block) => {
6258
let block = block.clone();
6359
$p.bump();
6460
return Ok($p.mk_expr($p.prev_token.span, ExprKind::Block(block, None)));
6561
}
6662
};
63+
} else if let Some(path) = crate::maybe_reparse_metavar_seq!(
64+
$p,
65+
token::NonterminalKind::Path,
66+
token::NonterminalKind::Path,
67+
super::ParseNtResult::Path(path),
68+
path
69+
) {
70+
return Ok($p.mk_expr(span, ExprKind::Path(None, path.into_inner())));
6771
}
6872
};
6973
}

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,6 +1707,7 @@ pub enum ParseNtResult {
17071707
Pat(P<ast::Pat>, NtPatKind),
17081708
Ty(P<ast::Ty>),
17091709
Meta(P<ast::AttrItem>),
1710+
Path(P<ast::Path>),
17101711
Vis(P<ast::Visibility>),
17111712

17121713
/// This variant will eventually be removed, along with `Token::Interpolate`.

compiler/rustc_parse/src/parser/nonterminal.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl<'a> Parser<'a> {
4848
match nt {
4949
NtExpr(_)
5050
| NtLiteral(_) // `true`, `false`
51-
| NtPath(_) => true,
51+
=> true,
5252

5353
NtBlock(_) => false,
5454
}
@@ -85,7 +85,6 @@ impl<'a> Parser<'a> {
8585
token::NtLifetime(..) => true,
8686
token::Interpolated(nt) => match &**nt {
8787
NtBlock(_) | NtExpr(_) | NtLiteral(_) => true,
88-
NtPath(_) => false,
8988
},
9089
token::OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(k))) => match k {
9190
NonterminalKind::Block
@@ -213,7 +212,9 @@ impl<'a> Parser<'a> {
213212
};
214213
}
215214
NonterminalKind::Path => {
216-
NtPath(P(self.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))?))
215+
return Ok(ParseNtResult::Path(P(
216+
self.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))?
217+
)));
217218
}
218219
NonterminalKind::Meta => {
219220
return Ok(ParseNtResult::Meta(P(self.parse_attr_item(true)?)));

compiler/rustc_parse/src/parser/path.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::ty::{AllowPlus, RecoverQPath, RecoverReturnSign};
22
use super::{ParseNtResult, Parser, Restrictions, TokenType};
33
use crate::errors::PathSingleColon;
44
use crate::parser::{CommaRecoveryMode, RecoverColon, RecoverComma};
5-
use crate::{errors, maybe_whole};
5+
use crate::{errors, maybe_reparse_metavar_seq};
66
use ast::token::IdentIsRaw;
77
use rustc_ast::ptr::P;
88
use rustc_ast::token::{self, Delimiter, NonterminalKind, Token, TokenKind};
@@ -193,7 +193,15 @@ impl<'a> Parser<'a> {
193193
}
194194
};
195195

196-
maybe_whole!(self, NtPath, |path| reject_generics_if_mod_style(self, path.into_inner()));
196+
if let Some(path) = maybe_reparse_metavar_seq!(
197+
self,
198+
NonterminalKind::Path,
199+
NonterminalKind::Path,
200+
ParseNtResult::Path(path),
201+
path
202+
) {
203+
return Ok(reject_generics_if_mod_style(self, path.into_inner()));
204+
}
197205

198206
if let Some(NonterminalKind::Ty) = self.token.is_metavar_seq() {
199207
let mut self2 = self.clone();

0 commit comments

Comments
 (0)