Remove NtPath.

This commit is contained in:
Nicholas Nethercote 2024-04-18 20:09:37 +10:00
parent 7ea59e053b
commit 50076cdeb9
15 changed files with 48 additions and 73 deletions

View file

@ -4,7 +4,7 @@ use core::mem;
use core::ops::{Bound, ControlFlow};
use ast::mut_visit::{self, MutVisitor};
use ast::token::IdentIsRaw;
use ast::token::{IdentIsRaw, MetaVarKind};
use ast::{CoroutineKind, ForLoopKind, GenBlockKind, MatchKind, Pat, Path, PathSegment, Recovered};
use rustc_ast::ptr::P;
use rustc_ast::token::{self, Delimiter, Token, TokenKind};
@ -1382,6 +1382,7 @@ impl<'a> Parser<'a> {
fn parse_expr_bottom(&mut self) -> PResult<'a, P<Expr>> {
maybe_recover_from_interpolated_ty_qpath!(self, true);
let span = self.token.span;
if let token::Interpolated(nt) = &self.token.kind {
match &**nt {
token::NtExpr(e) | token::NtLiteral(e) => {
@ -1389,11 +1390,6 @@ impl<'a> Parser<'a> {
self.bump();
return Ok(e);
}
token::NtPath(path) => {
let path = (**path).clone();
self.bump();
return Ok(self.mk_expr(self.prev_token.span, ExprKind::Path(None, path)));
}
token::NtBlock(block) => {
let block = block.clone();
self.bump();
@ -1401,6 +1397,10 @@ impl<'a> Parser<'a> {
}
_ => {}
};
} else if let Some(path) = self.eat_metavar_seq(MetaVarKind::Path, |this| {
this.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))
}) {
return Ok(self.mk_expr(span, ExprKind::Path(None, path)));
}
// Outer attributes are already parsed and will be

View file

@ -1749,6 +1749,7 @@ pub enum ParseNtResult {
Pat(P<ast::Pat>, NtPatKind),
Ty(P<ast::Ty>),
Meta(P<ast::AttrItem>),
Path(P<ast::Path>),
Vis(P<ast::Visibility>),
/// This variant will eventually be removed, along with `Token::Interpolate`.

View file

@ -51,7 +51,7 @@ impl<'a> Parser<'a> {
NtStmt(_)
| NtExpr(_)
| NtLiteral(_) // `true`, `false`
| NtPath(_) => true,
=> true,
NtItem(_) | NtBlock(_) => false,
}
@ -97,7 +97,7 @@ impl<'a> Parser<'a> {
token::NtLifetime(..) => true,
token::Interpolated(nt) => match &**nt {
NtBlock(_) | NtStmt(_) | NtExpr(_) | NtLiteral(_) => true,
NtItem(_) | NtPath(_) => false,
NtItem(_) => false,
},
token::OpenDelim(Delimiter::Invisible(InvisibleOrigin::MetaVar(k))) => match k {
MetaVarKind::Block
@ -204,7 +204,9 @@ impl<'a> Parser<'a> {
};
}
NonterminalKind::Path => {
NtPath(P(self.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))?))
return Ok(ParseNtResult::Path(P(
self.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))?
)));
}
NonterminalKind::Meta => {
return Ok(ParseNtResult::Meta(P(self.parse_attr_item(ForceCollect::Yes)?)));

View file

@ -15,9 +15,9 @@ use tracing::debug;
use super::ty::{AllowPlus, RecoverQPath, RecoverReturnSign};
use super::{Parser, Restrictions, TokenType};
use crate::errors::{PathSingleColon, PathTripleColon};
use crate::errors::{self, PathSingleColon, PathTripleColon};
use crate::exp;
use crate::parser::{CommaRecoveryMode, RecoverColon, RecoverComma};
use crate::{errors, exp, maybe_whole};
/// Specifies how to parse a path.
#[derive(Copy, Clone, PartialEq)]
@ -194,7 +194,11 @@ impl<'a> Parser<'a> {
}
};
maybe_whole!(self, NtPath, |path| reject_generics_if_mod_style(self, path.into_inner()));
if let Some(path) =
self.eat_metavar_seq(MetaVarKind::Path, |this| this.parse_path(PathStyle::Type))
{
return Ok(reject_generics_if_mod_style(self, path));
}
// If we have a `ty` metavar in the form of a path, reparse it directly as a path, instead
// of reparsing it as a `ty` and then extracting the path.