Skip to content

Commit 1517eb7

Browse files
nnethercotecompiler-errors
authored andcommitted
Remove NtPath.
1 parent 353ccf5 commit 1517eb7

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
@@ -803,7 +803,6 @@ fn visit_nonterminal<T: MutVisitor>(vis: &mut T, nt: &mut token::Nonterminal) {
803803
token::NtBlock(block) => vis.visit_block(block),
804804
token::NtExpr(expr) => vis.visit_expr(expr),
805805
token::NtLiteral(expr) => vis.visit_expr(expr),
806-
token::NtPath(path) => vis.visit_path(path),
807806
}
808807
}
809808

compiler/rustc_ast/src/token.rs

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -614,8 +614,7 @@ impl Token {
614614
matches!(&**nt,
615615
NtBlock(..) |
616616
NtExpr(..) |
617-
NtLiteral(..) |
618-
NtPath(..)
617+
NtLiteral(..)
619618
),
620619
OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(
621620
MetaVarKind::Block |
@@ -651,7 +650,6 @@ impl Token {
651650
matches!(&**nt,
652651
| NtExpr(..)
653652
| NtLiteral(..)
654-
| NtPath(..)
655653
),
656654
OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(
657655
MetaVarKind::Expr { .. } |
@@ -680,7 +678,6 @@ impl Token {
680678
Lifetime(..) | // lifetime bound in trait object
681679
Lt | BinOp(Shl) | // associated path
682680
PathSep => true, // global path
683-
Interpolated(ref nt) => matches!(&**nt, NtPath(..)),
684681
OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(
685682
MetaVarKind::Ty |
686683
MetaVarKind::Path
@@ -839,28 +836,19 @@ impl Token {
839836
self.ident().is_some_and(|(ident, _)| ident.name == name)
840837
}
841838

842-
/// Returns `true` if the token is an interpolated path.
843-
fn is_whole_path(&self) -> bool {
844-
if let Interpolated(nt) = &self.kind
845-
&& let NtPath(..) = &**nt
846-
{
847-
return true;
848-
}
849-
850-
false
851-
}
852-
853839
/// Is this a pre-parsed expression dropped into the token stream
854840
/// (which happens while parsing the result of macro expansion)?
855841
pub fn is_whole_expr(&self) -> bool {
856842
#[allow(irrefutable_let_patterns)] // FIXME: temporary
857843
if let Interpolated(nt) = &self.kind
858-
&& let NtExpr(_) | NtLiteral(_) | NtPath(_) | NtBlock(_) = &**nt
844+
&& let NtExpr(_) | NtLiteral(_) | NtBlock(_) = &**nt
859845
{
860-
return true;
846+
true
847+
} else if matches!(self.is_metavar_seq(), Some(MetaVarKind::Path)) {
848+
true
849+
} else {
850+
false
861851
}
862-
863-
false
864852
}
865853

866854
/// Is the token an interpolated block (`$b:block`)?
@@ -886,7 +874,7 @@ impl Token {
886874
pub fn is_path_start(&self) -> bool {
887875
self == &PathSep
888876
|| self.is_qpath_start()
889-
|| self.is_whole_path()
877+
|| matches!(self.is_metavar_seq(), Some(MetaVarKind::Path))
890878
|| self.is_path_segment_keyword()
891879
|| self.is_ident() && !self.is_reserved_ident()
892880
}
@@ -1060,7 +1048,6 @@ pub enum Nonterminal {
10601048
NtBlock(P<ast::Block>),
10611049
NtExpr(P<ast::Expr>),
10621050
NtLiteral(P<ast::Expr>),
1063-
NtPath(P<ast::Path>),
10641051
}
10651052

10661053
#[derive(Debug, Copy, Clone, PartialEq, Eq, Encodable, Decodable, Hash, HashStable_Generic)]
@@ -1151,7 +1138,6 @@ impl Nonterminal {
11511138
match self {
11521139
NtBlock(block) => block.span,
11531140
NtExpr(expr) | NtLiteral(expr) => expr.span,
1154-
NtPath(path) => path.span,
11551141
}
11561142
}
11571143

@@ -1160,7 +1146,6 @@ impl Nonterminal {
11601146
NtBlock(..) => "block",
11611147
NtExpr(..) => "expression",
11621148
NtLiteral(..) => "literal",
1163-
NtPath(..) => "path",
11641149
}
11651150
}
11661151
}
@@ -1181,7 +1166,6 @@ impl fmt::Debug for Nonterminal {
11811166
NtBlock(..) => f.pad("NtBlock(..)"),
11821167
NtExpr(..) => f.pad("NtExpr(..)"),
11831168
NtLiteral(..) => f.pad("NtLiteral(..)"),
1184-
NtPath(..) => f.pad("NtPath(..)"),
11851169
}
11861170
}
11871171
}

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
@@ -324,6 +324,9 @@ pub(super) fn transcribe<'a>(
324324
MatchedSingle(ParseNtResult::Meta(meta)) => {
325325
mk_delimited(MetaVarKind::Meta, TokenStream::from_ast(meta))
326326
}
327+
MatchedSingle(ParseNtResult::Path(path)) => {
328+
mk_delimited(MetaVarKind::Path, TokenStream::from_ast(path))
329+
}
327330
MatchedSingle(ParseNtResult::Vis(vis)) => {
328331
mk_delimited(MetaVarKind::Vis, TokenStream::from_ast(vis))
329332
}

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};
@@ -1385,24 +1385,24 @@ impl<'a> Parser<'a> {
13851385
fn parse_expr_bottom(&mut self) -> PResult<'a, P<Expr>> {
13861386
maybe_recover_from_interpolated_ty_qpath!(self, true);
13871387

1388+
let span = self.token.span;
13881389
if let token::Interpolated(nt) = &self.token.kind {
13891390
match &**nt {
13901391
token::NtExpr(e) | token::NtLiteral(e) => {
13911392
let e = e.clone();
13921393
self.bump();
13931394
return Ok(e);
13941395
}
1395-
token::NtPath(path) => {
1396-
let path = (**path).clone();
1397-
self.bump();
1398-
return Ok(self.mk_expr(self.prev_token.span, ExprKind::Path(None, path)));
1399-
}
14001396
token::NtBlock(block) => {
14011397
let block = block.clone();
14021398
self.bump();
14031399
return Ok(self.mk_expr(self.prev_token.span, ExprKind::Block(block, None)));
14041400
}
14051401
};
1402+
} else if let Some(path) = self.eat_metavar_seq(MetaVarKind::Path, |this| {
1403+
this.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))
1404+
}) {
1405+
return Ok(self.mk_expr(span, ExprKind::Path(None, path)));
14061406
}
14071407

14081408
// 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
@@ -1755,6 +1755,7 @@ pub enum ParseNtResult {
17551755
Pat(P<ast::Pat>, NtPatKind),
17561756
Ty(P<ast::Ty>),
17571757
Meta(P<ast::AttrItem>),
1758+
Path(P<ast::Path>),
17581759
Vis(P<ast::Visibility>),
17591760

17601761
/// 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;
19+
use crate::errors::{self, PathSingleColon};
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)]
@@ -195,7 +194,11 @@ impl<'a> Parser<'a> {
195194
}
196195
};
197196

198-
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+
}
199202

200203
if let Some(MetaVarKind::Ty) = self.token.is_metavar_seq() {
201204
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)