Skip to content

Commit 5caaeba

Browse files
committed
Remove NtPath.
1 parent d34f2b4 commit 5caaeba

File tree

15 files changed

+49
-74
lines changed

15 files changed

+49
-74
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: 6 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,17 @@ 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 {
858+
matches!(self.is_metavar_seq(), Some(MetaVarKind::Path))
871859
}
872-
873-
false
874860
}
875861

876862
/// Is the token an interpolated block (`$b:block`)?
@@ -896,7 +882,7 @@ impl Token {
896882
pub fn is_path_start(&self) -> bool {
897883
self == &PathSep
898884
|| self.is_qpath_start()
899-
|| self.is_whole_path()
885+
|| matches!(self.is_metavar_seq(), Some(MetaVarKind::Path))
900886
|| self.is_path_segment_keyword()
901887
|| self.is_ident() && !self.is_reserved_ident()
902888
}
@@ -1079,7 +1065,6 @@ pub enum Nonterminal {
10791065
NtStmt(P<ast::Stmt>),
10801066
NtExpr(P<ast::Expr>),
10811067
NtLiteral(P<ast::Expr>),
1082-
NtPath(P<ast::Path>),
10831068
}
10841069

10851070
#[derive(Debug, Copy, Clone, PartialEq, Eq, Encodable, Decodable, Hash, HashStable_Generic)]
@@ -1172,7 +1157,6 @@ impl Nonterminal {
11721157
NtBlock(block) => block.span,
11731158
NtStmt(stmt) => stmt.span,
11741159
NtExpr(expr) | NtLiteral(expr) => expr.span,
1175-
NtPath(path) => path.span,
11761160
}
11771161
}
11781162

@@ -1183,7 +1167,6 @@ impl Nonterminal {
11831167
NtStmt(..) => "statement",
11841168
NtExpr(..) => "expression",
11851169
NtLiteral(..) => "literal",
1186-
NtPath(..) => "path",
11871170
}
11881171
}
11891172
}
@@ -1206,7 +1189,6 @@ impl fmt::Debug for Nonterminal {
12061189
NtStmt(..) => f.pad("NtStmt(..)"),
12071190
NtExpr(..) => f.pad("NtExpr(..)"),
12081191
NtLiteral(..) => f.pad("NtLiteral(..)"),
1209-
NtPath(..) => f.pad("NtPath(..)"),
12101192
}
12111193
}
12121194
}

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_attr_parsing/src/parser.rs

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -474,32 +474,21 @@ impl<'a> MetaItemListParserContext<'a> {
474474

475475
// or a path.
476476
let path =
477-
if let Some(TokenTree::Token(Token { kind: token::Interpolated(nt), span, .. }, _)) =
477+
if let Some(TokenTree::Token(Token { kind: token::Interpolated(_), span, .. }, _)) =
478478
self.inside_delimiters.peek()
479479
{
480-
match &**nt {
481-
// an already interpolated path from a macro expansion is a path, no need to parse
482-
// one from tokens
483-
token::Nonterminal::NtPath(path) => {
484-
self.inside_delimiters.next();
485-
486-
AttrPath::from_ast(path)
487-
}
488-
_ => {
489-
self.inside_delimiters.next();
490-
// we go into this path if an expr ended up in an attribute that
491-
// expansion did not turn into a literal. Say, `#[repr(align(macro!()))]`
492-
// where the macro didn't expand to a literal. An error is already given
493-
// for this at this point, and then we do continue. This makes this path
494-
// reachable...
495-
let e = self.dcx.span_delayed_bug(
496-
*span,
497-
"expr in place where literal is expected (builtin attr parsing)",
498-
);
499-
500-
return Some(MetaItemOrLitParser::Err(*span, e));
501-
}
502-
}
480+
self.inside_delimiters.next();
481+
// We go into this path if an expr ended up in an attribute that
482+
// expansion did not turn into a literal. Say, `#[repr(align(macro!()))]`
483+
// where the macro didn't expand to a literal. An error is already given
484+
// for this at this point, and then we do continue. This makes this path
485+
// reachable...
486+
let e = self.dcx.span_delayed_bug(
487+
*span,
488+
"expr in place where literal is expected (builtin attr parsing)",
489+
);
490+
491+
return Some(MetaItemOrLitParser::Err(*span, e));
503492
} else {
504493
self.next_path()?
505494
};

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)?)));

0 commit comments

Comments
 (0)