Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit dbcc0a7

Browse files
committed
Remove NtPath.
1 parent d4b8ef3 commit dbcc0a7

File tree

12 files changed

+42
-48
lines changed

12 files changed

+42
-48
lines changed

compiler/rustc_ast/src/ast_traits.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,12 @@ impl HasTokens for Nonterminal {
232232
fn tokens(&self) -> Option<&LazyAttrTokenStream> {
233233
match self {
234234
Nonterminal::NtExpr(expr) | Nonterminal::NtLiteral(expr) => expr.tokens(),
235-
Nonterminal::NtPath(path) => path.tokens(),
236235
Nonterminal::NtBlock(block) => block.tokens(),
237236
}
238237
}
239238
fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>> {
240239
match self {
241240
Nonterminal::NtExpr(expr) | Nonterminal::NtLiteral(expr) => expr.tokens_mut(),
242-
Nonterminal::NtPath(path) => path.tokens_mut(),
243241
Nonterminal::NtBlock(block) => block.tokens_mut(),
244242
}
245243
}

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(NonterminalKind::Meta)),
370+
Delimiter::Invisible(InvisibleOrigin::MetaVar(
371+
NonterminalKind::Meta | NonterminalKind::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
@@ -822,7 +822,6 @@ fn visit_nonterminal<T: MutVisitor>(nt: &mut token::Nonterminal, vis: &mut T) {
822822
token::NtBlock(block) => vis.visit_block(block),
823823
token::NtExpr(expr) => vis.visit_expr(expr),
824824
token::NtLiteral(expr) => vis.visit_expr(expr),
825-
token::NtPath(path) => vis.visit_path(path),
826825
}
827826
}
828827

compiler/rustc_ast/src/token.rs

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,7 @@ impl Token {
533533
Pound => true, // expression attributes
534534
Interpolated(ref nt) => matches!(&**nt, NtLiteral(..) |
535535
NtExpr(..) |
536-
NtBlock(..) |
537-
NtPath(..)),
536+
NtBlock(..)),
538537
OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(
539538
NonterminalKind::Block |
540539
NonterminalKind::Expr |
@@ -562,9 +561,7 @@ impl Token {
562561
| DotDot | DotDotDot | DotDotEq // ranges
563562
| Lt | BinOp(Shl) // associated path
564563
| PathSep => true, // global path
565-
Interpolated(ref nt) => matches!(&**nt, NtLiteral(..) |
566-
NtBlock(..) |
567-
NtPath(..)),
564+
Interpolated(ref nt) => matches!(&**nt, NtLiteral(..) | NtBlock(..)),
568565
OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(
569566
NonterminalKind::Block |
570567
NonterminalKind::PatParam { .. } |
@@ -591,7 +588,6 @@ impl Token {
591588
Lifetime(..) | // lifetime bound in trait object
592589
Lt | BinOp(Shl) | // associated path
593590
PathSep => true, // global path
594-
Interpolated(ref nt) => matches!(&**nt, NtPath(..)),
595591
OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(
596592
NonterminalKind::Ty |
597593
NonterminalKind::Path
@@ -742,29 +738,20 @@ impl Token {
742738
self.ident().is_some_and(|(ident, _)| ident.name == name)
743739
}
744740

745-
/// Returns `true` if the token is an interpolated path.
746-
fn is_whole_path(&self) -> bool {
747-
if let Interpolated(nt) = &self.kind
748-
&& let NtPath(..) = &**nt
749-
{
750-
return true;
751-
}
752-
753-
false
754-
}
755-
756741
/// Would `maybe_whole_expr` in `parser.rs` return `Ok(..)`?
757742
/// That is, is this a pre-parsed expression dropped into the token stream
758743
/// (which happens while parsing the result of macro expansion)?
759744
pub fn is_whole_expr(&self) -> bool {
760745
#[allow(irrefutable_let_patterns)] // njn: temp
761746
if let Interpolated(nt) = &self.kind
762-
&& let NtExpr(_) | NtLiteral(_) | NtPath(_) | NtBlock(_) = &**nt
747+
&& let NtExpr(_) | NtLiteral(_) = &**nt
763748
{
764-
return true;
749+
true
750+
} else if matches!(self.is_metavar_seq(), Some(NonterminalKind::Path)) {
751+
true
752+
} else {
753+
false
765754
}
766-
767-
false
768755
}
769756

770757
/// Is the token an interpolated block (`$b:block`)?
@@ -790,7 +777,7 @@ impl Token {
790777
pub fn is_path_start(&self) -> bool {
791778
self == &PathSep
792779
|| self.is_qpath_start()
793-
|| self.is_whole_path()
780+
|| matches!(self.is_metavar_seq(), Some(NonterminalKind::Path))
794781
|| self.is_path_segment_keyword()
795782
|| self.is_ident() && !self.is_reserved_ident()
796783
}
@@ -943,7 +930,6 @@ pub enum Nonterminal {
943930
NtBlock(P<ast::Block>),
944931
NtExpr(P<ast::Expr>),
945932
NtLiteral(P<ast::Expr>),
946-
NtPath(P<ast::Path>),
947933
}
948934

949935
#[derive(Debug, Copy, Clone, PartialEq, Eq, Encodable, Decodable, Hash, HashStable_Generic)]
@@ -1042,7 +1028,6 @@ impl Nonterminal {
10421028
match self {
10431029
NtBlock(block) => block.span,
10441030
NtExpr(expr) | NtLiteral(expr) => expr.span,
1045-
NtPath(path) => path.span,
10461031
}
10471032
}
10481033

@@ -1051,7 +1036,6 @@ impl Nonterminal {
10511036
NtBlock(..) => "block",
10521037
NtExpr(..) => "expression",
10531038
NtLiteral(..) => "literal",
1054-
NtPath(..) => "path",
10551039
}
10561040
}
10571041
}
@@ -1072,7 +1056,6 @@ impl fmt::Debug for Nonterminal {
10721056
NtBlock(..) => f.pad("NtBlock(..)"),
10731057
NtExpr(..) => f.pad("NtExpr(..)"),
10741058
NtLiteral(..) => f.pad("NtLiteral(..)"),
1075-
NtPath(..) => f.pad("NtPath(..)"),
10761059
}
10771060
}
10781061
}

compiler/rustc_ast/src/tokenstream.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,6 @@ impl TokenStream {
467467
pub fn from_nonterminal_ast(nt: &Nonterminal) -> TokenStream {
468468
match nt {
469469
Nonterminal::NtBlock(block) => TokenStream::from_ast(block),
470-
Nonterminal::NtPath(path) => TokenStream::from_ast(path),
471470
Nonterminal::NtExpr(expr) | Nonterminal::NtLiteral(expr) => TokenStream::from_ast(expr),
472471
}
473472
}

compiler/rustc_expand/src/mbe/transcribe.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,9 @@ pub(super) fn transcribe<'a>(
322322
MatchedSingle(ParseNtResult::Meta(ref meta)) => {
323323
mk_delimited(NonterminalKind::Meta, TokenStream::from_ast(meta))
324324
}
325+
MatchedSingle(ParseNtResult::Path(ref path)) => {
326+
mk_delimited(NonterminalKind::Path, TokenStream::from_ast(path))
327+
}
325328
MatchedSingle(ParseNtResult::Vis(ref vis)) => {
326329
mk_delimited(NonterminalKind::Vis, TokenStream::from_ast(vis))
327330
}

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,28 @@ use tracing::instrument;
4646
/// `token::Interpolated` tokens.
4747
macro_rules! maybe_whole_expr {
4848
($p:expr) => {
49+
let span = $p.token.span;
4950
if let token::Interpolated(nt) = &$p.token.kind {
5051
match &**nt {
5152
token::NtExpr(e) | token::NtLiteral(e) => {
5253
let e = e.clone();
5354
$p.bump();
5455
return Ok(e);
5556
}
56-
token::NtPath(path) => {
57-
let path = (**path).clone();
58-
$p.bump();
59-
return Ok($p.mk_expr($p.prev_token.span, ExprKind::Path(None, path)));
60-
}
6157
token::NtBlock(block) => {
6258
let block = block.clone();
6359
$p.bump();
6460
return Ok($p.mk_expr($p.prev_token.span, ExprKind::Block(block, None)));
6561
}
6662
};
63+
} else if let Some(path) = crate::maybe_reparse_metavar_seq!(
64+
$p,
65+
token::NonterminalKind::Path,
66+
token::NonterminalKind::Path,
67+
super::ParseNtResult::Path(path),
68+
path
69+
) {
70+
return Ok($p.mk_expr(span, ExprKind::Path(None, path.into_inner())));
6771
}
6872
};
6973
}

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,6 +1707,7 @@ pub enum ParseNtResult {
17071707
PatWithOr(P<ast::Pat>),
17081708
Ty(P<ast::Ty>),
17091709
Meta(P<ast::AttrItem>),
1710+
Path(P<ast::Path>),
17101711
Vis(P<ast::Visibility>),
17111712

17121713
/// 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
@@ -49,7 +49,7 @@ impl<'a> Parser<'a> {
4949
match nt {
5050
NtExpr(_)
5151
| NtLiteral(_) // `true`, `false`
52-
| NtPath(_) => true,
52+
=> true,
5353

5454
NtBlock(_) => false,
5555
}
@@ -86,7 +86,6 @@ impl<'a> Parser<'a> {
8686
token::NtLifetime(..) => true,
8787
token::Interpolated(nt) => match &**nt {
8888
NtBlock(_) | NtExpr(_) | NtLiteral(_) => true,
89-
NtPath(_) => false,
9089
},
9190
token::OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(k))) => match k {
9291
NonterminalKind::Block
@@ -223,7 +222,9 @@ impl<'a> Parser<'a> {
223222
};
224223
}
225224
NonterminalKind::Path => {
226-
NtPath(P(self.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))?))
225+
return Ok(ParseNtResult::Path(P(
226+
self.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))?
227+
)));
227228
}
228229
NonterminalKind::Meta => {
229230
return Ok(ParseNtResult::Meta(P(self.parse_attr_item(true)?)));

compiler/rustc_parse/src/parser/path.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::ty::{AllowPlus, RecoverQPath, RecoverReturnSign};
22
use super::{ParseNtResult, Parser, Restrictions, TokenType};
33
use crate::errors::PathSingleColon;
44
use crate::parser::{CommaRecoveryMode, RecoverColon, RecoverComma};
5-
use crate::{errors, maybe_whole};
5+
use crate::{errors, maybe_reparse_metavar_seq};
66
use ast::token::IdentIsRaw;
77
use rustc_ast::ptr::P;
88
use rustc_ast::token::{self, Delimiter, NonterminalKind, Token, TokenKind};
@@ -193,7 +193,15 @@ impl<'a> Parser<'a> {
193193
}
194194
};
195195

196-
maybe_whole!(self, NtPath, |path| reject_generics_if_mod_style(self, path.into_inner()));
196+
if let Some(path) = maybe_reparse_metavar_seq!(
197+
self,
198+
NonterminalKind::Path,
199+
NonterminalKind::Path,
200+
ParseNtResult::Path(path),
201+
path
202+
) {
203+
return Ok(reject_generics_if_mod_style(self, path.into_inner()));
204+
}
197205

198206
if let Some(NonterminalKind::Ty) = self.token.is_metavar_seq() {
199207
let mut self2 = self.clone();

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

0 commit comments

Comments
 (0)