remove P
This commit is contained in:
@@ -3,7 +3,6 @@ use std::ops::{Deref, DerefMut};
|
||||
|
||||
use ast::token::IdentIsRaw;
|
||||
use rustc_ast as ast;
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::token::{self, Lit, LitKind, Token, TokenKind};
|
||||
use rustc_ast::util::parser::AssocOp;
|
||||
use rustc_ast::{
|
||||
@@ -50,7 +49,7 @@ use crate::{exp, fluent_generated as fluent};
|
||||
|
||||
/// Creates a placeholder argument.
|
||||
pub(super) fn dummy_arg(ident: Ident, guar: ErrorGuaranteed) -> Param {
|
||||
let pat = P(Pat {
|
||||
let pat = Box::new(Pat {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
kind: PatKind::Ident(BindingMode::NONE, ident, None),
|
||||
span: ident.span,
|
||||
@@ -62,23 +61,23 @@ pub(super) fn dummy_arg(ident: Ident, guar: ErrorGuaranteed) -> Param {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
pat,
|
||||
span: ident.span,
|
||||
ty: P(ty),
|
||||
ty: Box::new(ty),
|
||||
is_placeholder: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) trait RecoverQPath: Sized + 'static {
|
||||
const PATH_STYLE: PathStyle = PathStyle::Expr;
|
||||
fn to_ty(&self) -> Option<P<Ty>>;
|
||||
fn recovered(qself: Option<P<QSelf>>, path: ast::Path) -> Self;
|
||||
fn to_ty(&self) -> Option<Box<Ty>>;
|
||||
fn recovered(qself: Option<Box<QSelf>>, path: ast::Path) -> Self;
|
||||
}
|
||||
|
||||
impl RecoverQPath for Ty {
|
||||
const PATH_STYLE: PathStyle = PathStyle::Type;
|
||||
fn to_ty(&self) -> Option<P<Ty>> {
|
||||
Some(P(self.clone()))
|
||||
fn to_ty(&self) -> Option<Box<Ty>> {
|
||||
Some(Box::new(self.clone()))
|
||||
}
|
||||
fn recovered(qself: Option<P<QSelf>>, path: ast::Path) -> Self {
|
||||
fn recovered(qself: Option<Box<QSelf>>, path: ast::Path) -> Self {
|
||||
Self {
|
||||
span: path.span,
|
||||
kind: TyKind::Path(qself, path),
|
||||
@@ -90,10 +89,10 @@ impl RecoverQPath for Ty {
|
||||
|
||||
impl RecoverQPath for Pat {
|
||||
const PATH_STYLE: PathStyle = PathStyle::Pat;
|
||||
fn to_ty(&self) -> Option<P<Ty>> {
|
||||
fn to_ty(&self) -> Option<Box<Ty>> {
|
||||
self.to_ty()
|
||||
}
|
||||
fn recovered(qself: Option<P<QSelf>>, path: ast::Path) -> Self {
|
||||
fn recovered(qself: Option<Box<QSelf>>, path: ast::Path) -> Self {
|
||||
Self {
|
||||
span: path.span,
|
||||
kind: PatKind::Path(qself, path),
|
||||
@@ -104,10 +103,10 @@ impl RecoverQPath for Pat {
|
||||
}
|
||||
|
||||
impl RecoverQPath for Expr {
|
||||
fn to_ty(&self) -> Option<P<Ty>> {
|
||||
fn to_ty(&self) -> Option<Box<Ty>> {
|
||||
self.to_ty()
|
||||
}
|
||||
fn recovered(qself: Option<P<QSelf>>, path: ast::Path) -> Self {
|
||||
fn recovered(qself: Option<Box<QSelf>>, path: ast::Path) -> Self {
|
||||
Self {
|
||||
span: path.span,
|
||||
kind: ExprKind::Path(qself, path),
|
||||
@@ -977,7 +976,7 @@ impl<'a> Parser<'a> {
|
||||
lo: Span,
|
||||
s: BlockCheckMode,
|
||||
maybe_struct_name: token::Token,
|
||||
) -> Option<PResult<'a, P<Block>>> {
|
||||
) -> Option<PResult<'a, Box<Block>>> {
|
||||
if self.token.is_ident() && self.look_ahead(1, |t| t == &token::Colon) {
|
||||
// We might be having a struct literal where people forgot to include the path:
|
||||
// fn foo() -> Foo {
|
||||
@@ -1042,7 +1041,7 @@ impl<'a> Parser<'a> {
|
||||
token: token::Token,
|
||||
lo: Span,
|
||||
decl_hi: Span,
|
||||
) -> PResult<'a, P<Expr>> {
|
||||
) -> PResult<'a, Box<Expr>> {
|
||||
err.span_label(lo.to(decl_hi), "while parsing the body of this closure");
|
||||
let guar = match before.kind {
|
||||
token::OpenBrace if token.kind != token::OpenBrace => {
|
||||
@@ -1260,7 +1259,7 @@ impl<'a> Parser<'a> {
|
||||
pub(super) fn check_mistyped_turbofish_with_multiple_type_params(
|
||||
&mut self,
|
||||
mut e: Diag<'a>,
|
||||
expr: &mut P<Expr>,
|
||||
expr: &mut Box<Expr>,
|
||||
) -> PResult<'a, ErrorGuaranteed> {
|
||||
if let ExprKind::Binary(binop, _, _) = &expr.kind
|
||||
&& let ast::BinOpKind::Lt = binop.node
|
||||
@@ -1443,7 +1442,7 @@ impl<'a> Parser<'a> {
|
||||
&mut self,
|
||||
inner_op: &Expr,
|
||||
outer_op: &Spanned<AssocOp>,
|
||||
) -> PResult<'a, Option<P<Expr>>> {
|
||||
) -> PResult<'a, Option<Box<Expr>>> {
|
||||
debug_assert!(
|
||||
outer_op.node.is_comparison(),
|
||||
"check_no_chained_comparison: {:?} is not comparison",
|
||||
@@ -1595,7 +1594,7 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
|
||||
/// Swift lets users write `Ty?` to mean `Option<Ty>`. Parse the construct and recover from it.
|
||||
pub(super) fn maybe_recover_from_question_mark(&mut self, ty: P<Ty>) -> P<Ty> {
|
||||
pub(super) fn maybe_recover_from_question_mark(&mut self, ty: Box<Ty>) -> Box<Ty> {
|
||||
if self.token == token::Question {
|
||||
self.bump();
|
||||
let guar = self.dcx().emit_err(QuestionMarkInType {
|
||||
@@ -1690,10 +1689,10 @@ impl<'a> Parser<'a> {
|
||||
|
||||
pub(super) fn recover_from_prefix_increment(
|
||||
&mut self,
|
||||
operand_expr: P<Expr>,
|
||||
operand_expr: Box<Expr>,
|
||||
op_span: Span,
|
||||
start_stmt: bool,
|
||||
) -> PResult<'a, P<Expr>> {
|
||||
) -> PResult<'a, Box<Expr>> {
|
||||
let standalone = if start_stmt { IsStandalone::Standalone } else { IsStandalone::Subexpr };
|
||||
let kind = IncDecRecovery { standalone, op: IncOrDec::Inc, fixity: UnaryFixity::Pre };
|
||||
self.recover_from_inc_dec(operand_expr, kind, op_span)
|
||||
@@ -1701,10 +1700,10 @@ impl<'a> Parser<'a> {
|
||||
|
||||
pub(super) fn recover_from_postfix_increment(
|
||||
&mut self,
|
||||
operand_expr: P<Expr>,
|
||||
operand_expr: Box<Expr>,
|
||||
op_span: Span,
|
||||
start_stmt: bool,
|
||||
) -> PResult<'a, P<Expr>> {
|
||||
) -> PResult<'a, Box<Expr>> {
|
||||
let kind = IncDecRecovery {
|
||||
standalone: if start_stmt { IsStandalone::Standalone } else { IsStandalone::Subexpr },
|
||||
op: IncOrDec::Inc,
|
||||
@@ -1715,10 +1714,10 @@ impl<'a> Parser<'a> {
|
||||
|
||||
pub(super) fn recover_from_postfix_decrement(
|
||||
&mut self,
|
||||
operand_expr: P<Expr>,
|
||||
operand_expr: Box<Expr>,
|
||||
op_span: Span,
|
||||
start_stmt: bool,
|
||||
) -> PResult<'a, P<Expr>> {
|
||||
) -> PResult<'a, Box<Expr>> {
|
||||
let kind = IncDecRecovery {
|
||||
standalone: if start_stmt { IsStandalone::Standalone } else { IsStandalone::Subexpr },
|
||||
op: IncOrDec::Dec,
|
||||
@@ -1729,10 +1728,10 @@ impl<'a> Parser<'a> {
|
||||
|
||||
fn recover_from_inc_dec(
|
||||
&mut self,
|
||||
base: P<Expr>,
|
||||
base: Box<Expr>,
|
||||
kind: IncDecRecovery,
|
||||
op_span: Span,
|
||||
) -> PResult<'a, P<Expr>> {
|
||||
) -> PResult<'a, Box<Expr>> {
|
||||
let mut err = self.dcx().struct_span_err(
|
||||
op_span,
|
||||
format!("Rust has no {} {} operator", kind.fixity, kind.op.name()),
|
||||
@@ -1833,8 +1832,8 @@ impl<'a> Parser<'a> {
|
||||
/// tail, and combines them into a `<Ty>::AssocItem` expression/pattern/type.
|
||||
pub(super) fn maybe_recover_from_bad_qpath<T: RecoverQPath>(
|
||||
&mut self,
|
||||
base: P<T>,
|
||||
) -> PResult<'a, P<T>> {
|
||||
base: Box<T>,
|
||||
) -> PResult<'a, Box<T>> {
|
||||
if !self.may_recover() {
|
||||
return Ok(base);
|
||||
}
|
||||
@@ -1853,8 +1852,8 @@ impl<'a> Parser<'a> {
|
||||
pub(super) fn maybe_recover_from_bad_qpath_stage_2<T: RecoverQPath>(
|
||||
&mut self,
|
||||
ty_span: Span,
|
||||
ty: P<Ty>,
|
||||
) -> PResult<'a, P<T>> {
|
||||
ty: Box<Ty>,
|
||||
) -> PResult<'a, Box<T>> {
|
||||
self.expect(exp!(PathSep))?;
|
||||
|
||||
let mut path = ast::Path { segments: ThinVec::new(), span: DUMMY_SP, tokens: None };
|
||||
@@ -1867,7 +1866,7 @@ impl<'a> Parser<'a> {
|
||||
});
|
||||
|
||||
let path_span = ty_span.shrink_to_hi(); // Use an empty path since `position == 0`.
|
||||
Ok(P(T::recovered(Some(P(QSelf { ty, path_span, position: 0 })), path)))
|
||||
Ok(Box::new(T::recovered(Some(Box::new(QSelf { ty, path_span, position: 0 })), path)))
|
||||
}
|
||||
|
||||
/// This function gets called in places where a semicolon is NOT expected and if there's a
|
||||
@@ -1970,7 +1969,7 @@ impl<'a> Parser<'a> {
|
||||
pub(super) fn recover_incorrect_await_syntax(
|
||||
&mut self,
|
||||
await_sp: Span,
|
||||
) -> PResult<'a, P<Expr>> {
|
||||
) -> PResult<'a, Box<Expr>> {
|
||||
let (hi, expr, is_question) = if self.token == token::Bang {
|
||||
// Handle `await!(<expr>)`.
|
||||
self.recover_await_macro()?
|
||||
@@ -1982,7 +1981,7 @@ impl<'a> Parser<'a> {
|
||||
self.maybe_recover_from_bad_qpath(expr)
|
||||
}
|
||||
|
||||
fn recover_await_macro(&mut self) -> PResult<'a, (Span, P<Expr>, bool)> {
|
||||
fn recover_await_macro(&mut self) -> PResult<'a, (Span, Box<Expr>, bool)> {
|
||||
self.expect(exp!(Bang))?;
|
||||
self.expect(exp!(OpenParen))?;
|
||||
let expr = self.parse_expr()?;
|
||||
@@ -1990,7 +1989,7 @@ impl<'a> Parser<'a> {
|
||||
Ok((self.prev_token.span, expr, false))
|
||||
}
|
||||
|
||||
fn recover_await_prefix(&mut self, await_sp: Span) -> PResult<'a, (Span, P<Expr>, bool)> {
|
||||
fn recover_await_prefix(&mut self, await_sp: Span) -> PResult<'a, (Span, Box<Expr>, bool)> {
|
||||
let is_question = self.eat(exp!(Question)); // Handle `await? <expr>`.
|
||||
let expr = if self.token == token::OpenBrace {
|
||||
// Handle `await { <expr> }`.
|
||||
@@ -2052,7 +2051,7 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn try_macro_suggestion(&mut self) -> PResult<'a, P<Expr>> {
|
||||
pub(super) fn try_macro_suggestion(&mut self) -> PResult<'a, Box<Expr>> {
|
||||
let is_try = self.token.is_keyword(kw::Try);
|
||||
let is_questionmark = self.look_ahead(1, |t| t == &token::Bang); //check for !
|
||||
let is_open = self.look_ahead(2, |t| t == &token::OpenParen); //check for (
|
||||
@@ -2124,7 +2123,7 @@ impl<'a> Parser<'a> {
|
||||
close: ExpTokenPair<'_>,
|
||||
lo: Span,
|
||||
err: Diag<'a>,
|
||||
) -> P<Expr> {
|
||||
) -> Box<Expr> {
|
||||
let guar = err.emit();
|
||||
// Recover from parse error, callers expect the closing delim to be consumed.
|
||||
self.consume_block(open, close, ConsumeClosingDelim::Yes);
|
||||
@@ -2244,7 +2243,7 @@ impl<'a> Parser<'a> {
|
||||
pub(super) fn parameter_without_type(
|
||||
&mut self,
|
||||
err: &mut Diag<'_>,
|
||||
pat: P<ast::Pat>,
|
||||
pat: Box<ast::Pat>,
|
||||
require_name: bool,
|
||||
first_param: bool,
|
||||
) -> Option<Ident> {
|
||||
@@ -2346,7 +2345,7 @@ impl<'a> Parser<'a> {
|
||||
None
|
||||
}
|
||||
|
||||
pub(super) fn recover_arg_parse(&mut self) -> PResult<'a, (P<ast::Pat>, P<ast::Ty>)> {
|
||||
pub(super) fn recover_arg_parse(&mut self) -> PResult<'a, (Box<ast::Pat>, Box<ast::Ty>)> {
|
||||
let pat = self.parse_pat_no_top_alt(Some(Expected::ArgumentName), None)?;
|
||||
self.expect(exp!(Colon))?;
|
||||
let ty = self.parse_ty()?;
|
||||
@@ -2354,8 +2353,12 @@ impl<'a> Parser<'a> {
|
||||
self.dcx().emit_err(PatternMethodParamWithoutBody { span: pat.span });
|
||||
|
||||
// Pretend the pattern is `_`, to avoid duplicate errors from AST validation.
|
||||
let pat =
|
||||
P(Pat { kind: PatKind::Wild, span: pat.span, id: ast::DUMMY_NODE_ID, tokens: None });
|
||||
let pat = Box::new(Pat {
|
||||
kind: PatKind::Wild,
|
||||
span: pat.span,
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
tokens: None,
|
||||
});
|
||||
Ok((pat, ty))
|
||||
}
|
||||
|
||||
@@ -2506,7 +2509,7 @@ impl<'a> Parser<'a> {
|
||||
/// - Single-segment paths (i.e. standalone generic const parameters).
|
||||
/// All other expressions that can be parsed will emit an error suggesting the expression be
|
||||
/// wrapped in braces.
|
||||
pub(super) fn handle_unambiguous_unbraced_const_arg(&mut self) -> PResult<'a, P<Expr>> {
|
||||
pub(super) fn handle_unambiguous_unbraced_const_arg(&mut self) -> PResult<'a, Box<Expr>> {
|
||||
let start = self.token.span;
|
||||
let attrs = self.parse_outer_attributes()?;
|
||||
let (expr, _) =
|
||||
@@ -2688,7 +2691,7 @@ impl<'a> Parser<'a> {
|
||||
pub(crate) fn recover_unbraced_const_arg_that_can_begin_ty(
|
||||
&mut self,
|
||||
mut snapshot: SnapshotParser<'a>,
|
||||
) -> Option<P<ast::Expr>> {
|
||||
) -> Option<Box<ast::Expr>> {
|
||||
match (|| {
|
||||
let attrs = self.parse_outer_attributes()?;
|
||||
snapshot.parse_expr_res(Restrictions::CONST_EXPR, attrs)
|
||||
@@ -2724,9 +2727,9 @@ impl<'a> Parser<'a> {
|
||||
/// `for` loop, `let`, &c. (in contrast to subpatterns within such).
|
||||
pub(crate) fn maybe_recover_colon_colon_in_pat_typo(
|
||||
&mut self,
|
||||
mut first_pat: P<Pat>,
|
||||
mut first_pat: Box<Pat>,
|
||||
expected: Option<Expected>,
|
||||
) -> P<Pat> {
|
||||
) -> Box<Pat> {
|
||||
if token::Colon != self.token.kind {
|
||||
return first_pat;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user