Remove box_syntax from AST and use in tools

This commit is contained in:
clubby789 2023-02-27 13:17:29 +00:00
parent dd7df04e16
commit 0932452fa4
28 changed files with 40 additions and 95 deletions

View file

@ -2300,3 +2300,16 @@ impl HelpUseLatestEdition {
}
}
}
#[derive(Diagnostic)]
#[diag(parse_box_syntax_removed)]
pub struct BoxSyntaxRemoved<'a> {
#[primary_span]
#[suggestion(
code = "Box::new({code})",
applicability = "machine-applicable",
style = "verbose"
)]
pub span: Span,
pub code: &'a str,
}

View file

@ -607,9 +607,6 @@ impl<'a> Parser<'a> {
let operand_expr = this.parse_expr_dot_or_call(Default::default())?;
this.recover_from_prefix_increment(operand_expr, pre_span, starts_stmt)
}
token::Ident(..) if this.token.is_keyword(kw::Box) => {
make_it!(this, attrs, |this, _| this.parse_expr_box(lo))
}
token::Ident(..) if this.may_recover() && this.is_mistaken_not_ident_negation() => {
make_it!(this, attrs, |this, _| this.recover_not_expr(lo))
}
@ -636,13 +633,6 @@ impl<'a> Parser<'a> {
self.parse_expr_unary(lo, UnOp::Not)
}
/// Parse `box expr`.
fn parse_expr_box(&mut self, lo: Span) -> PResult<'a, (Span, ExprKind)> {
let (span, expr) = self.parse_expr_prefix_common(lo)?;
self.sess.gated_spans.gate(sym::box_syntax, span);
Ok((span, ExprKind::Box(expr)))
}
fn is_mistaken_not_ident_negation(&self) -> bool {
let token_cannot_continue_expr = |t: &Token| match t.uninterpolate().kind {
// These tokens can start an expression after `!`, but