Skip to content

Commit de50018

Browse files
committed
Remove NtPath.
1 parent 9c34ccc commit de50018

File tree

14 files changed

+38
-50
lines changed

14 files changed

+38
-50
lines changed

compiler/rustc_ast/src/ast_traits.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ impl HasTokens for Nonterminal {
202202
Nonterminal::NtItem(item) => item.tokens(),
203203
Nonterminal::NtStmt(stmt) => stmt.tokens(),
204204
Nonterminal::NtExpr(expr) | Nonterminal::NtLiteral(expr) => expr.tokens(),
205-
Nonterminal::NtPath(path) => path.tokens(),
206205
Nonterminal::NtBlock(block) => block.tokens(),
207206
}
208207
}
@@ -211,7 +210,6 @@ impl HasTokens for Nonterminal {
211210
Nonterminal::NtItem(item) => item.tokens_mut(),
212211
Nonterminal::NtStmt(stmt) => stmt.tokens_mut(),
213212
Nonterminal::NtExpr(expr) | Nonterminal::NtLiteral(expr) => expr.tokens_mut(),
214-
Nonterminal::NtPath(path) => path.tokens_mut(),
215213
Nonterminal::NtBlock(block) => block.tokens_mut(),
216214
}
217215
}

compiler/rustc_ast/src/attr/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -405,14 +405,12 @@ impl MetaItem {
405405
let span = span.with_hi(segments.last().unwrap().ident.span.hi());
406406
Path { span, segments, tokens: None }
407407
}
408-
Some(TokenTree::Token(Token { kind: token::Interpolated(nt), .. }, _)) => match &**nt {
409-
token::Nonterminal::NtPath(path) => (**path).clone(),
410-
_ => return None,
411-
},
412408
Some(TokenTree::Delimited(
413409
_span,
414410
_spacing,
415-
Delimiter::Invisible(InvisibleOrigin::MetaVar(MetaVarKind::Meta { .. })),
411+
Delimiter::Invisible(InvisibleOrigin::MetaVar(
412+
MetaVarKind::Meta { .. } | MetaVarKind::Path,
413+
)),
416414
_stream,
417415
)) => {
418416
// 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
@@ -907,7 +907,6 @@ fn visit_nonterminal<T: MutVisitor>(vis: &mut T, nt: &mut token::Nonterminal) {
907907
}),
908908
token::NtExpr(expr) => vis.visit_expr(expr),
909909
token::NtLiteral(expr) => vis.visit_expr(expr),
910-
token::NtPath(path) => vis.visit_path(path),
911910
}
912911
}
913912

compiler/rustc_ast/src/token.rs

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,7 @@ impl Token {
624624
matches!(&**nt,
625625
NtBlock(..) |
626626
NtExpr(..) |
627-
NtLiteral(..) |
628-
NtPath(..)
627+
NtLiteral(..)
629628
),
630629
OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(
631630
MetaVarKind::Block |
@@ -661,7 +660,6 @@ impl Token {
661660
matches!(&**nt,
662661
| NtExpr(..)
663662
| NtLiteral(..)
664-
| NtPath(..)
665663
),
666664
OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(
667665
MetaVarKind::Expr { .. } |
@@ -690,7 +688,6 @@ impl Token {
690688
Lifetime(..) | // lifetime bound in trait object
691689
Lt | BinOp(Shl) | // associated path
692690
PathSep => true, // global path
693-
Interpolated(ref nt) => matches!(&**nt, NtPath(..)),
694691
OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(
695692
MetaVarKind::Ty { .. } |
696693
MetaVarKind::Path
@@ -849,28 +846,19 @@ impl Token {
849846
self.ident().is_some_and(|(ident, _)| ident.name == name)
850847
}
851848

852-
/// Returns `true` if the token is an interpolated path.
853-
fn is_whole_path(&self) -> bool {
854-
if let Interpolated(nt) = &self.kind
855-
&& let NtPath(..) = &**nt
856-
{
857-
return true;
858-
}
859-
860-
false
861-
}
862-
863849
/// Is this a pre-parsed expression dropped into the token stream
864850
/// (which happens while parsing the result of macro expansion)?
865851
pub fn is_whole_expr(&self) -> bool {
866852
#[allow(irrefutable_let_patterns)] // FIXME: temporary
867853
if let Interpolated(nt) = &self.kind
868-
&& let NtExpr(_) | NtLiteral(_) | NtPath(_) | NtBlock(_) = &**nt
854+
&& let NtExpr(_) | NtLiteral(_) | NtBlock(_) = &**nt
869855
{
870-
return true;
856+
true
857+
} else if matches!(self.is_metavar_seq(), Some(MetaVarKind::Path)) {
858+
true
859+
} else {
860+
false
871861
}
872-
873-
false
874862
}
875863

876864
/// Is the token an interpolated block (`$b:block`)?
@@ -896,7 +884,7 @@ impl Token {
896884
pub fn is_path_start(&self) -> bool {
897885
self == &PathSep
898886
|| self.is_qpath_start()
899-
|| self.is_whole_path()
887+
|| matches!(self.is_metavar_seq(), Some(MetaVarKind::Path))
900888
|| self.is_path_segment_keyword()
901889
|| self.is_ident() && !self.is_reserved_ident()
902890
}
@@ -1079,7 +1067,6 @@ pub enum Nonterminal {
10791067
NtStmt(P<ast::Stmt>),
10801068
NtExpr(P<ast::Expr>),
10811069
NtLiteral(P<ast::Expr>),
1082-
NtPath(P<ast::Path>),
10831070
}
10841071

10851072
#[derive(Debug, Copy, Clone, PartialEq, Eq, Encodable, Decodable, Hash, HashStable_Generic)]
@@ -1172,7 +1159,6 @@ impl Nonterminal {
11721159
NtBlock(block) => block.span,
11731160
NtStmt(stmt) => stmt.span,
11741161
NtExpr(expr) | NtLiteral(expr) => expr.span,
1175-
NtPath(path) => path.span,
11761162
}
11771163
}
11781164

@@ -1183,7 +1169,6 @@ impl Nonterminal {
11831169
NtStmt(..) => "statement",
11841170
NtExpr(..) => "expression",
11851171
NtLiteral(..) => "literal",
1186-
NtPath(..) => "path",
11871172
}
11881173
}
11891174
}
@@ -1206,7 +1191,6 @@ impl fmt::Debug for Nonterminal {
12061191
NtStmt(..) => f.pad("NtStmt(..)"),
12071192
NtExpr(..) => f.pad("NtExpr(..)"),
12081193
NtLiteral(..) => f.pad("NtLiteral(..)"),
1209-
NtPath(..) => f.pad("NtPath(..)"),
12101194
}
12111195
}
12121196
}

compiler/rustc_ast/src/tokenstream.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,6 @@ impl TokenStream {
468468
TokenStream::token_alone(token::Semi, stmt.span)
469469
}
470470
Nonterminal::NtStmt(stmt) => TokenStream::from_ast(stmt),
471-
Nonterminal::NtPath(path) => TokenStream::from_ast(path),
472471
Nonterminal::NtExpr(expr) | Nonterminal::NtLiteral(expr) => TokenStream::from_ast(expr),
473472
}
474473
}

compiler/rustc_expand/src/mbe/transcribe.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@ pub(super) fn transcribe<'a>(
344344
TokenStream::from_ast(attr_item),
345345
)
346346
}
347+
MatchedSingle(ParseNtResult::Path(path)) => {
348+
mk_delimited(path.span, MetaVarKind::Path, TokenStream::from_ast(path))
349+
}
347350
MatchedSingle(ParseNtResult::Vis(vis)) => {
348351
mk_delimited(vis.span, MetaVarKind::Vis, TokenStream::from_ast(vis))
349352
}

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use core::mem;
44
use core::ops::{Bound, ControlFlow};
55

66
use ast::mut_visit::{self, MutVisitor};
7-
use ast::token::IdentIsRaw;
7+
use ast::token::{IdentIsRaw, MetaVarKind};
88
use ast::{CoroutineKind, ForLoopKind, GenBlockKind, MatchKind, Pat, Path, PathSegment, Recovered};
99
use rustc_ast::ptr::P;
1010
use rustc_ast::token::{self, Delimiter, Token, TokenKind};
@@ -1382,25 +1382,25 @@ impl<'a> Parser<'a> {
13821382
fn parse_expr_bottom(&mut self) -> PResult<'a, P<Expr>> {
13831383
maybe_recover_from_interpolated_ty_qpath!(self, true);
13841384

1385+
let span = self.token.span;
13851386
if let token::Interpolated(nt) = &self.token.kind {
13861387
match &**nt {
13871388
token::NtExpr(e) | token::NtLiteral(e) => {
13881389
let e = e.clone();
13891390
self.bump();
13901391
return Ok(e);
13911392
}
1392-
token::NtPath(path) => {
1393-
let path = (**path).clone();
1394-
self.bump();
1395-
return Ok(self.mk_expr(self.prev_token.span, ExprKind::Path(None, path)));
1396-
}
13971393
token::NtBlock(block) => {
13981394
let block = block.clone();
13991395
self.bump();
14001396
return Ok(self.mk_expr(self.prev_token.span, ExprKind::Block(block, None)));
14011397
}
14021398
_ => {}
14031399
};
1400+
} else if let Some(path) = self.eat_metavar_seq(MetaVarKind::Path, |this| {
1401+
this.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))
1402+
}) {
1403+
return Ok(self.mk_expr(span, ExprKind::Path(None, path)));
14041404
}
14051405

14061406
// Outer attributes are already parsed and will be

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,6 +1749,7 @@ pub enum ParseNtResult {
17491749
Pat(P<ast::Pat>, NtPatKind),
17501750
Ty(P<ast::Ty>),
17511751
Meta(P<ast::AttrItem>),
1752+
Path(P<ast::Path>),
17521753
Vis(P<ast::Visibility>),
17531754

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

compiler/rustc_parse/src/parser/nonterminal.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<'a> Parser<'a> {
5151
NtStmt(_)
5252
| NtExpr(_)
5353
| NtLiteral(_) // `true`, `false`
54-
| NtPath(_) => true,
54+
=> true,
5555

5656
NtItem(_) | NtBlock(_) => false,
5757
}
@@ -97,7 +97,7 @@ impl<'a> Parser<'a> {
9797
token::NtLifetime(..) => true,
9898
token::Interpolated(nt) => match &**nt {
9999
NtBlock(_) | NtStmt(_) | NtExpr(_) | NtLiteral(_) => true,
100-
NtItem(_) | NtPath(_) => false,
100+
NtItem(_) => false,
101101
},
102102
token::OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(k))) => match k {
103103
MetaVarKind::Block
@@ -204,7 +204,9 @@ impl<'a> Parser<'a> {
204204
};
205205
}
206206
NonterminalKind::Path => {
207-
NtPath(P(self.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))?))
207+
return Ok(ParseNtResult::Path(P(
208+
self.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))?
209+
)));
208210
}
209211
NonterminalKind::Meta => {
210212
return Ok(ParseNtResult::Meta(P(self.parse_attr_item(ForceCollect::Yes)?)));

compiler/rustc_parse/src/parser/path.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use tracing::debug;
1515

1616
use super::ty::{AllowPlus, RecoverQPath, RecoverReturnSign};
1717
use super::{Parser, Restrictions, TokenType};
18-
use crate::errors::{PathSingleColon, PathTripleColon};
18+
use crate::errors::{self, PathSingleColon, PathTripleColon};
19+
use crate::exp;
1920
use crate::parser::{CommaRecoveryMode, RecoverColon, RecoverComma};
20-
use crate::{errors, exp, maybe_whole};
2121

2222
/// Specifies how to parse a path.
2323
#[derive(Copy, Clone, PartialEq)]
@@ -194,7 +194,11 @@ impl<'a> Parser<'a> {
194194
}
195195
};
196196

197-
maybe_whole!(self, NtPath, |path| reject_generics_if_mod_style(self, path.into_inner()));
197+
if let Some(path) =
198+
self.eat_metavar_seq(MetaVarKind::Path, |this| this.parse_path(PathStyle::Type))
199+
{
200+
return Ok(reject_generics_if_mod_style(self, path));
201+
}
198202

199203
// If we have a `ty` metavar in the form of a path, reparse it directly as a path, instead
200204
// of reparsing it as a `ty` and then extracting the path.

0 commit comments

Comments
 (0)