Skip to content

Commit 9a0ab9a

Browse files
committed
Remove NtPath.
1 parent ab342f7 commit 9a0ab9a

File tree

14 files changed

+37
-50
lines changed

14 files changed

+37
-50
lines changed

compiler/rustc_ast/src/ast_traits.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,12 @@ impl HasTokens for Nonterminal {
200200
fn tokens(&self) -> Option<&LazyAttrTokenStream> {
201201
match self {
202202
Nonterminal::NtExpr(expr) | Nonterminal::NtLiteral(expr) => expr.tokens(),
203-
Nonterminal::NtPath(path) => path.tokens(),
204203
Nonterminal::NtBlock(block) => block.tokens(),
205204
}
206205
}
207206
fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>> {
208207
match self {
209208
Nonterminal::NtExpr(expr) | Nonterminal::NtLiteral(expr) => expr.tokens_mut(),
210-
Nonterminal::NtPath(path) => path.tokens_mut(),
211209
Nonterminal::NtBlock(block) => block.tokens_mut(),
212210
}
213211
}

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
@@ -895,7 +895,6 @@ fn visit_nonterminal<T: MutVisitor>(vis: &mut T, nt: &mut token::Nonterminal) {
895895
token::NtBlock(block) => vis.visit_block(block),
896896
token::NtExpr(expr) => vis.visit_expr(expr),
897897
token::NtLiteral(expr) => vis.visit_expr(expr),
898-
token::NtPath(path) => vis.visit_path(path),
899898
}
900899
}
901900

compiler/rustc_ast/src/token.rs

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,7 @@ impl Token {
621621
matches!(&**nt,
622622
NtBlock(..) |
623623
NtExpr(..) |
624-
NtLiteral(..) |
625-
NtPath(..)
624+
NtLiteral(..)
626625
),
627626
OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(
628627
MetaVarKind::Block |
@@ -658,7 +657,6 @@ impl Token {
658657
matches!(&**nt,
659658
| NtExpr(..)
660659
| NtLiteral(..)
661-
| NtPath(..)
662660
),
663661
OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(
664662
MetaVarKind::Expr { .. } |
@@ -687,7 +685,6 @@ impl Token {
687685
Lifetime(..) | // lifetime bound in trait object
688686
Lt | BinOp(Shl) | // associated path
689687
PathSep => true, // global path
690-
Interpolated(ref nt) => matches!(&**nt, NtPath(..)),
691688
OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(
692689
MetaVarKind::Ty { .. } |
693690
MetaVarKind::Path
@@ -846,28 +843,19 @@ impl Token {
846843
self.ident().is_some_and(|(ident, _)| ident.name == name)
847844
}
848845

849-
/// Returns `true` if the token is an interpolated path.
850-
fn is_whole_path(&self) -> bool {
851-
if let Interpolated(nt) = &self.kind
852-
&& let NtPath(..) = &**nt
853-
{
854-
return true;
855-
}
856-
857-
false
858-
}
859-
860846
/// Is this a pre-parsed expression dropped into the token stream
861847
/// (which happens while parsing the result of macro expansion)?
862848
pub fn is_whole_expr(&self) -> bool {
863849
#[allow(irrefutable_let_patterns)] // FIXME: temporary
864850
if let Interpolated(nt) = &self.kind
865-
&& let NtExpr(_) | NtLiteral(_) | NtPath(_) | NtBlock(_) = &**nt
851+
&& let NtExpr(_) | NtLiteral(_) | NtBlock(_) = &**nt
866852
{
867-
return true;
853+
true
854+
} else if matches!(self.is_metavar_seq(), Some(MetaVarKind::Path)) {
855+
true
856+
} else {
857+
false
868858
}
869-
870-
false
871859
}
872860

873861
/// Is the token an interpolated block (`$b:block`)?
@@ -893,7 +881,7 @@ impl Token {
893881
pub fn is_path_start(&self) -> bool {
894882
self == &PathSep
895883
|| self.is_qpath_start()
896-
|| self.is_whole_path()
884+
|| matches!(self.is_metavar_seq(), Some(MetaVarKind::Path))
897885
|| self.is_path_segment_keyword()
898886
|| self.is_ident() && !self.is_reserved_ident()
899887
}
@@ -1074,7 +1062,6 @@ pub enum Nonterminal {
10741062
NtBlock(P<ast::Block>),
10751063
NtExpr(P<ast::Expr>),
10761064
NtLiteral(P<ast::Expr>),
1077-
NtPath(P<ast::Path>),
10781065
}
10791066

10801067
#[derive(Debug, Copy, Clone, PartialEq, Eq, Encodable, Decodable, Hash, HashStable_Generic)]
@@ -1165,7 +1152,6 @@ impl Nonterminal {
11651152
match self {
11661153
NtBlock(block) => block.span,
11671154
NtExpr(expr) | NtLiteral(expr) => expr.span,
1168-
NtPath(path) => path.span,
11691155
}
11701156
}
11711157

@@ -1174,7 +1160,6 @@ impl Nonterminal {
11741160
NtBlock(..) => "block",
11751161
NtExpr(..) => "expression",
11761162
NtLiteral(..) => "literal",
1177-
NtPath(..) => "path",
11781163
}
11791164
}
11801165
}
@@ -1195,7 +1180,6 @@ impl fmt::Debug for Nonterminal {
11951180
NtBlock(..) => f.pad("NtBlock(..)"),
11961181
NtExpr(..) => f.pad("NtExpr(..)"),
11971182
NtLiteral(..) => f.pad("NtLiteral(..)"),
1198-
NtPath(..) => f.pad("NtPath(..)"),
11991183
}
12001184
}
12011185
}

compiler/rustc_ast/src/tokenstream.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,6 @@ impl TokenStream {
462462
pub fn from_nonterminal_ast(nt: &Nonterminal) -> TokenStream {
463463
match nt {
464464
Nonterminal::NtBlock(block) => TokenStream::from_ast(block),
465-
Nonterminal::NtPath(path) => TokenStream::from_ast(path),
466465
Nonterminal::NtExpr(expr) | Nonterminal::NtLiteral(expr) => TokenStream::from_ast(expr),
467466
}
468467
}

compiler/rustc_expand/src/mbe/transcribe.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,9 @@ pub(super) fn transcribe<'a>(
353353
MetaVarKind::Meta,
354354
TokenStream::from_ast(meta),
355355
),
356+
MatchedSingle(ParseNtResult::Path(path)) => {
357+
mk_delimited(path.span, MetaVarKind::Path, TokenStream::from_ast(path))
358+
}
356359
MatchedSingle(ParseNtResult::Vis(vis)) => {
357360
mk_delimited(vis.span, MetaVarKind::Vis, TokenStream::from_ast(vis))
358361
}

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,24 +1382,24 @@ 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
};
1399+
} else if let Some(path) = self.eat_metavar_seq(MetaVarKind::Path, |this| {
1400+
this.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))
1401+
}) {
1402+
return Ok(self.mk_expr(span, ExprKind::Path(None, path)));
14031403
}
14041404

14051405
// 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
@@ -1753,6 +1753,7 @@ pub enum ParseNtResult {
17531753
Pat(P<ast::Pat>, NtPatKind),
17541754
Ty(P<ast::Ty>),
17551755
Meta(P<ast::AttrItem>),
1756+
Path(P<ast::Path>),
17561757
Vis(P<ast::Visibility>),
17571758

17581759
/// 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
@@ -50,7 +50,7 @@ impl<'a> Parser<'a> {
5050
match nt {
5151
NtExpr(_)
5252
| NtLiteral(_) // `true`, `false`
53-
| NtPath(_) => true,
53+
=> true,
5454

5555
NtBlock(_) => false,
5656
}
@@ -96,7 +96,6 @@ impl<'a> Parser<'a> {
9696
token::NtLifetime(..) => true,
9797
token::Interpolated(nt) => match &**nt {
9898
NtBlock(_) | NtExpr(_) | NtLiteral(_) => true,
99-
NtPath(_) => false,
10099
},
101100
token::OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(k))) => match k {
102101
MetaVarKind::Block
@@ -203,7 +202,9 @@ impl<'a> Parser<'a> {
203202
};
204203
}
205204
NonterminalKind::Path => {
206-
NtPath(P(self.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))?))
205+
return Ok(ParseNtResult::Path(P(
206+
self.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))?
207+
)));
207208
}
208209
NonterminalKind::Meta => {
209210
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)