Skip to content

Commit 010b8ec

Browse files
committed
Remove NtPath.
1 parent 6ea7de7 commit 010b8ec

File tree

14 files changed

+43
-50
lines changed

14 files changed

+43
-50
lines changed

compiler/rustc_ast/src/ast_traits.rs

-2
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

+3-5
Original file line numberDiff line numberDiff line change
@@ -346,14 +346,12 @@ impl MetaItem {
346346
let span = span.with_hi(segments.last().unwrap().ident.span.hi());
347347
Path { span, segments, tokens: None }
348348
}
349-
Some(TokenTree::Token(Token { kind: token::Interpolated(nt), .. }, _)) => match &**nt {
350-
token::Nonterminal::NtPath(path) => (**path).clone(),
351-
_ => return None,
352-
},
353349
Some(TokenTree::Delimited(
354350
_span,
355351
_spacing,
356-
Delimiter::Invisible(InvisibleOrigin::MetaVar(NonterminalKind::Meta)),
352+
Delimiter::Invisible(InvisibleOrigin::MetaVar(
353+
NonterminalKind::Meta | NonterminalKind::Path,
354+
)),
357355
_stream,
358356
)) => {
359357
// This path is currently unreachable in the test suite.

compiler/rustc_ast/src/mut_visit.rs

-1
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,6 @@ fn visit_nonterminal<T: MutVisitor>(nt: &mut token::Nonterminal, vis: &mut T) {
825825
token::NtBlock(block) => vis.visit_block(block),
826826
token::NtExpr(expr) => vis.visit_expr(expr),
827827
token::NtLiteral(expr) => vis.visit_expr(expr),
828-
token::NtPath(path) => vis.visit_path(path),
829828
}
830829
}
831830

compiler/rustc_ast/src/token.rs

+9-26
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,7 @@ impl Token {
532532
Pound => true, // expression attributes
533533
Interpolated(ref nt) => matches!(&**nt, NtLiteral(..) |
534534
NtExpr(..) |
535-
NtBlock(..) |
536-
NtPath(..)),
535+
NtBlock(..)),
537536
OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(
538537
NonterminalKind::Block |
539538
NonterminalKind::Expr |
@@ -560,9 +559,7 @@ impl Token {
560559
| DotDot | DotDotDot | DotDotEq // ranges
561560
| Lt | BinOp(Shl) // associated path
562561
| PathSep => true, // global path
563-
Interpolated(ref nt) => matches!(&**nt, NtLiteral(..) |
564-
NtBlock(..) |
565-
NtPath(..)),
562+
Interpolated(ref nt) => matches!(&**nt, NtLiteral(..) | NtBlock(..)),
566563
OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(
567564
NonterminalKind::Block |
568565
NonterminalKind::PatParam { .. } |
@@ -589,7 +586,6 @@ impl Token {
589586
Lifetime(..) | // lifetime bound in trait object
590587
Lt | BinOp(Shl) | // associated path
591588
PathSep => true, // global path
592-
Interpolated(ref nt) => matches!(&**nt, NtPath(..)),
593589
OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(
594590
NonterminalKind::Ty |
595591
NonterminalKind::Path
@@ -721,29 +717,20 @@ impl Token {
721717
self.ident().is_some_and(|(ident, _)| ident.name == name)
722718
}
723719

724-
/// Returns `true` if the token is an interpolated path.
725-
fn is_whole_path(&self) -> bool {
726-
if let Interpolated(nt) = &self.kind
727-
&& let NtPath(..) = &**nt
728-
{
729-
return true;
730-
}
731-
732-
false
733-
}
734-
735720
/// Would `maybe_whole_expr` in `parser.rs` return `Ok(..)`?
736721
/// That is, is this a pre-parsed expression dropped into the token stream
737722
/// (which happens while parsing the result of macro expansion)?
738723
pub fn is_whole_expr(&self) -> bool {
739724
#[allow(irrefutable_let_patterns)] // njn: temp
740725
if let Interpolated(nt) = &self.kind
741-
&& let NtExpr(_) | NtLiteral(_) | NtPath(_) | NtBlock(_) = &**nt
726+
&& let NtExpr(_) | NtLiteral(_) = &**nt
742727
{
743-
return true;
728+
true
729+
} else if matches!(self.is_metavar_seq(), Some(NonterminalKind::Path)) {
730+
true
731+
} else {
732+
false
744733
}
745-
746-
false
747734
}
748735

749736
/// Is the token an interpolated block (`$b:block`)?
@@ -769,7 +756,7 @@ impl Token {
769756
pub fn is_path_start(&self) -> bool {
770757
self == &PathSep
771758
|| self.is_qpath_start()
772-
|| self.is_whole_path()
759+
|| matches!(self.is_metavar_seq(), Some(NonterminalKind::Path))
773760
|| self.is_path_segment_keyword()
774761
|| self.is_ident() && !self.is_reserved_ident()
775762
}
@@ -922,7 +909,6 @@ pub enum Nonterminal {
922909
NtBlock(P<ast::Block>),
923910
NtExpr(P<ast::Expr>),
924911
NtLiteral(P<ast::Expr>),
925-
NtPath(P<ast::Path>),
926912
}
927913

928914
#[derive(Debug, Copy, Clone, PartialEq, Eq, Encodable, Decodable, Hash, HashStable_Generic)]
@@ -1008,7 +994,6 @@ impl Nonterminal {
1008994
match self {
1009995
NtBlock(block) => block.span,
1010996
NtExpr(expr) | NtLiteral(expr) => expr.span,
1011-
NtPath(path) => path.span,
1012997
}
1013998
}
1014999

@@ -1017,7 +1002,6 @@ impl Nonterminal {
10171002
NtBlock(..) => "block",
10181003
NtExpr(..) => "expression",
10191004
NtLiteral(..) => "literal",
1020-
NtPath(..) => "path",
10211005
}
10221006
}
10231007
}
@@ -1038,7 +1022,6 @@ impl fmt::Debug for Nonterminal {
10381022
NtBlock(..) => f.pad("NtBlock(..)"),
10391023
NtExpr(..) => f.pad("NtExpr(..)"),
10401024
NtLiteral(..) => f.pad("NtLiteral(..)"),
1041-
NtPath(..) => f.pad("NtPath(..)"),
10421025
}
10431026
}
10441027
}

compiler/rustc_ast/src/tokenstream.rs

-1
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,6 @@ impl TokenStream {
477477
pub fn from_nonterminal_ast(nt: &Nonterminal) -> TokenStream {
478478
match nt {
479479
Nonterminal::NtBlock(block) => TokenStream::from_ast(block),
480-
Nonterminal::NtPath(path) => TokenStream::from_ast(path),
481480
Nonterminal::NtExpr(expr) | Nonterminal::NtLiteral(expr) => TokenStream::from_ast(expr),
482481
}
483482
}

compiler/rustc_ast_pretty/src/pprust/state.rs

-1
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,6 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
854854
fn nonterminal_to_string(&self, nt: &Nonterminal) -> String {
855855
match nt {
856856
token::NtExpr(e) => self.expr_to_string(e),
857-
token::NtPath(e) => self.path_to_string(e),
858857
token::NtBlock(e) => self.block_to_string(e),
859858
token::NtLiteral(e) => self.expr_to_string(e),
860859
}

compiler/rustc_expand/src/mbe/transcribe.rs

+3
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ pub(super) fn transcribe<'a>(
309309
MatchedSingle(ParseNtResult::Meta(ref meta)) => {
310310
mk_delimited(NonterminalKind::Meta, TokenStream::from_ast(meta))
311311
}
312+
MatchedSingle(ParseNtResult::Path(ref path)) => {
313+
mk_delimited(NonterminalKind::Path, TokenStream::from_ast(path))
314+
}
312315
MatchedSingle(ParseNtResult::Vis(ref vis)) => {
313316
mk_delimited(NonterminalKind::Vis, TokenStream::from_ast(vis))
314317
}

compiler/rustc_parse/src/parser/expr.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,28 @@ use thin_vec::{thin_vec, ThinVec};
4444
/// `token::Interpolated` tokens.
4545
macro_rules! maybe_whole_expr {
4646
($p:expr) => {
47+
let span = $p.token.span;
4748
if let token::Interpolated(nt) = &$p.token.kind {
4849
match &**nt {
4950
token::NtExpr(e) | token::NtLiteral(e) => {
5051
let e = e.clone();
5152
$p.bump();
5253
return Ok(e);
5354
}
54-
token::NtPath(path) => {
55-
let path = (**path).clone();
56-
$p.bump();
57-
return Ok($p.mk_expr($p.prev_token.span, ExprKind::Path(None, path)));
58-
}
5955
token::NtBlock(block) => {
6056
let block = block.clone();
6157
$p.bump();
6258
return Ok($p.mk_expr($p.prev_token.span, ExprKind::Block(block, None)));
6359
}
6460
};
61+
} else if let Some(path) = crate::maybe_reparse_metavar_seq!(
62+
$p,
63+
token::NonterminalKind::Path,
64+
token::NonterminalKind::Path,
65+
super::ParseNtResult::Path(path),
66+
path
67+
) {
68+
return Ok($p.mk_expr(span, ExprKind::Path(None, path.into_inner())));
6569
}
6670
};
6771
}

compiler/rustc_parse/src/parser/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1719,6 +1719,7 @@ pub enum ParseNtResult {
17191719
PatWithOr(P<ast::Pat>),
17201720
Ty(P<ast::Ty>),
17211721
Meta(P<ast::AttrItem>),
1722+
Path(P<ast::Path>),
17221723
Vis(P<ast::Visibility>),
17231724

17241725
/// This variant will eventually be removed, along with `Token::Interpolate`.

compiler/rustc_parse/src/parser/nonterminal.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl<'a> Parser<'a> {
4848
match nt {
4949
NtExpr(_)
5050
| NtLiteral(_) // `true`, `false`
51-
| NtPath(_) => true,
51+
=> true,
5252

5353
NtBlock(_) => false,
5454
}
@@ -80,7 +80,6 @@ impl<'a> Parser<'a> {
8080
token::NtLifetime(..) => true,
8181
token::Interpolated(nt) => match &**nt {
8282
NtBlock(_) | NtExpr(_) | NtLiteral(_) => true,
83-
NtPath(_) => false,
8483
},
8584
token::OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(k))) => match k {
8685
NonterminalKind::Block
@@ -213,7 +212,9 @@ impl<'a> Parser<'a> {
213212
};
214213
}
215214
NonterminalKind::Path => {
216-
NtPath(P(self.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))?))
215+
return Ok(ParseNtResult::Path(P(
216+
self.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))?
217+
)));
217218
}
218219
NonterminalKind::Meta => {
219220
return Ok(ParseNtResult::Meta(P(self.parse_attr_item(true)?)));

compiler/rustc_parse/src/parser/path.rs

+10-2
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

+1-1
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

+2-2
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/stringify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ fn test_path() {
631631
c1!(path, [ crate::thing ], "crate::thing");
632632
c1!(path, [ Self::thing ], "Self::thing");
633633
c1!(path, [ Self<'static> ], "Self<'static>");
634-
c2!(path, [ Self::<'static> ], "Self<'static>", "Self::<'static>");
634+
c1!(path, [ Self::<'static> ], "Self::<'static>");
635635
c1!(path, [ Self() ], "Self()");
636636
c1!(path, [ Self() -> () ], "Self() -> ()");
637637
}

0 commit comments

Comments
 (0)