Skip to content

Commit 8540c76

Browse files
committed
Remove NtPath.
1 parent 8c7b344 commit 8540c76

File tree

14 files changed

+36
-50
lines changed

14 files changed

+36
-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
@@ -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(MetaVarKind::Meta)),
370+
Delimiter::Invisible(InvisibleOrigin::MetaVar(
371+
MetaVarKind::Meta | MetaVarKind::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
@@ -799,7 +799,6 @@ fn visit_nonterminal<T: MutVisitor>(vis: &mut T, nt: &mut token::Nonterminal) {
799799
token::NtBlock(block) => vis.visit_block(block),
800800
token::NtExpr(expr) => vis.visit_expr(expr),
801801
token::NtLiteral(expr) => vis.visit_expr(expr),
802-
token::NtPath(path) => vis.visit_path(path),
803802
}
804803
}
805804

compiler/rustc_ast/src/token.rs

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,7 @@ impl Token {
620620
matches!(&**nt,
621621
NtBlock(..) |
622622
NtExpr(..) |
623-
NtLiteral(..) |
624-
NtPath(..)
623+
NtLiteral(..)
625624
),
626625
OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(
627626
MetaVarKind::Block |
@@ -657,7 +656,6 @@ impl Token {
657656
matches!(&**nt,
658657
| NtExpr(..)
659658
| NtLiteral(..)
660-
| NtPath(..)
661659
),
662660
OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(
663661
MetaVarKind::Expr { .. } |
@@ -686,7 +684,6 @@ impl Token {
686684
Lifetime(..) | // lifetime bound in trait object
687685
Lt | BinOp(Shl) | // associated path
688686
PathSep => true, // global path
689-
Interpolated(ref nt) => matches!(&**nt, NtPath(..)),
690687
OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(
691688
MetaVarKind::Ty |
692689
MetaVarKind::Path
@@ -845,28 +842,19 @@ impl Token {
845842
self.ident().is_some_and(|(ident, _)| ident.name == name)
846843
}
847844

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

872860
/// Is the token an interpolated block (`$b:block`)?
@@ -892,7 +880,7 @@ impl Token {
892880
pub fn is_path_start(&self) -> bool {
893881
self == &PathSep
894882
|| self.is_qpath_start()
895-
|| self.is_whole_path()
883+
|| matches!(self.is_metavar_seq(), Some(MetaVarKind::Path))
896884
|| self.is_path_segment_keyword()
897885
|| self.is_ident() && !self.is_reserved_ident()
898886
}
@@ -1066,7 +1054,6 @@ pub enum Nonterminal {
10661054
NtBlock(P<ast::Block>),
10671055
NtExpr(P<ast::Expr>),
10681056
NtLiteral(P<ast::Expr>),
1069-
NtPath(P<ast::Path>),
10701057
}
10711058

10721059
#[derive(Debug, Copy, Clone, PartialEq, Eq, Encodable, Decodable, Hash, HashStable_Generic)]
@@ -1157,7 +1144,6 @@ impl Nonterminal {
11571144
match self {
11581145
NtBlock(block) => block.span,
11591146
NtExpr(expr) | NtLiteral(expr) => expr.span,
1160-
NtPath(path) => path.span,
11611147
}
11621148
}
11631149

@@ -1166,7 +1152,6 @@ impl Nonterminal {
11661152
NtBlock(..) => "block",
11671153
NtExpr(..) => "expression",
11681154
NtLiteral(..) => "literal",
1169-
NtPath(..) => "path",
11701155
}
11711156
}
11721157
}
@@ -1187,7 +1172,6 @@ impl fmt::Debug for Nonterminal {
11871172
NtBlock(..) => f.pad("NtBlock(..)"),
11881173
NtExpr(..) => f.pad("NtExpr(..)"),
11891174
NtLiteral(..) => f.pad("NtLiteral(..)"),
1190-
NtPath(..) => f.pad("NtPath(..)"),
11911175
}
11921176
}
11931177
}

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
@@ -339,6 +339,9 @@ pub(super) fn transcribe<'a>(
339339
MatchedSingle(ParseNtResult::Meta(meta)) => {
340340
mk_delimited(MetaVarKind::Meta, TokenStream::from_ast(meta))
341341
}
342+
MatchedSingle(ParseNtResult::Path(path)) => {
343+
mk_delimited(MetaVarKind::Path, TokenStream::from_ast(path))
344+
}
342345
MatchedSingle(ParseNtResult::Vis(vis)) => {
343346
mk_delimited(MetaVarKind::Vis, TokenStream::from_ast(vis))
344347
}

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::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
@@ -1771,6 +1771,7 @@ pub enum ParseNtResult {
17711771
Pat(P<ast::Pat>, NtPatKind),
17721772
Ty(P<ast::Ty>),
17731773
Meta(P<ast::AttrItem>),
1774+
Path(P<ast::Path>),
17741775
Vis(P<ast::Visibility>),
17751776

17761777
/// 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: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ use tracing::debug;
1616

1717
use super::ty::{AllowPlus, RecoverQPath, RecoverReturnSign};
1818
use super::{Parser, Restrictions, TokenType};
19-
use crate::errors::{PathSingleColon, PathTripleColon};
19+
use crate::errors::{self, PathSingleColon, PathTripleColon};
2020
use crate::parser::{CommaRecoveryMode, RecoverColon, RecoverComma};
21-
use crate::{errors, maybe_whole};
2221

2322
/// Specifies how to parse a path.
2423
#[derive(Copy, Clone, PartialEq)]
@@ -196,7 +195,11 @@ impl<'a> Parser<'a> {
196195
}
197196
};
198197

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

201204
if let Some(MetaVarKind::Ty) = self.token.is_metavar_seq() {
202205
let mut snapshot = self.create_snapshot_for_diagnostic();

tests/ui/imports/import-prefix-macro-2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mod a {
88
}
99

1010
macro_rules! import {
11-
($p: path) => (use ::$p {S, Z}); //~ERROR expected identifier, found `a::b::c`
11+
($p: path) => (use ::$p {S, Z}); //~ERROR expected identifier, found metavariable
1212
}
1313

1414
import! { a::b::c }

tests/ui/imports/import-prefix-macro-2.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: expected identifier, found `a::b::c`
1+
error: expected identifier, found metavariable
22
--> $DIR/import-prefix-macro-2.rs:11:26
33
|
44
LL | ($p: path) => (use ::$p {S, Z});
5-
| ^^ expected identifier
5+
| ^^ expected identifier, found metavariable
66
...
77
LL | import! { a::b::c }
88
| ------------------- in this macro invocation

tests/ui/macros/nonterminal-matching.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ macro_rules! foo {
3131
(tt $x:tt) => { bar!(tt $x); };
3232
(expr $x:expr) => { bar!(expr $x); }; //~ ERROR: no rules expected expression `3`
3333
(literal $x:literal) => { bar!(literal $x); }; //~ ERROR: no rules expected literal `4`
34-
(path $x:path) => { bar!(path $x); }; //~ ERROR: no rules expected path `a::b::c`
34+
(path $x:path) => { bar!(path $x); }; //~ ERROR: no rules expected `path` metavariable
3535
(stmt $x:stmt) => { bar!(stmt $x); }; //~ ERROR: no rules expected `stmt` metavariable
3636
}
3737

tests/ui/macros/nonterminal-matching.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ LL | (literal 4) => {};
6767
= help: try using `:tt` instead in the macro definition
6868
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
6969

70-
error: no rules expected path `a::b::c`
70+
error: no rules expected `path` metavariable
7171
--> $DIR/nonterminal-matching.rs:34:35
7272
|
7373
LL | (path $x:path) => { bar!(path $x); };

0 commit comments

Comments
 (0)