diff options
| author | clubby789 <jamie@hill-daniel.co.uk> | 2023-02-27 13:17:29 +0000 |
|---|---|---|
| committer | clubby789 <jamie@hill-daniel.co.uk> | 2023-03-12 13:19:46 +0000 |
| commit | 0932452fa40178b6f8b93a2bab3b4ead4e2bb560 (patch) | |
| tree | 640a6f9236a494096b535bffd7bbb30f1f62318e /compiler | |
| parent | dd7df04e168324fc002ab4985b6c7513f08ccf49 (diff) | |
Remove `box_syntax` from AST and use in tools
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_ast/src/ast.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_ast/src/mut_visit.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_ast/src/util/classify.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_ast/src/visit.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_ast_lowering/src/expr.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_ast_passes/src/feature_gate.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_ast_pretty/src/pprust/state/expr.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_builtin_macros/src/assert/context.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_feature/src/active.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_feature/src/removed.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_parse/messages.ftl | 3 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/errors.rs | 13 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/hir_stats.rs | 2 |
14 files changed, 20 insertions, 36 deletions
diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 03c375c4666..6503bf2bab7 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -1230,7 +1230,6 @@ impl Expr { pub fn precedence(&self) -> ExprPrecedence { match self.kind { - ExprKind::Box(_) => ExprPrecedence::Box, ExprKind::Array(_) => ExprPrecedence::Array, ExprKind::ConstBlock(_) => ExprPrecedence::ConstBlock, ExprKind::Call(..) => ExprPrecedence::Call, @@ -1291,8 +1290,7 @@ impl Expr { /// To a first-order approximation, is this a pattern? pub fn is_approximately_pattern(&self) -> bool { match &self.peel_parens().kind { - ExprKind::Box(_) - | ExprKind::Array(_) + ExprKind::Array(_) | ExprKind::Call(_, _) | ExprKind::Tup(_) | ExprKind::Lit(_) @@ -1363,8 +1361,6 @@ pub struct StructExpr { #[derive(Clone, Encodable, Decodable, Debug)] pub enum ExprKind { - /// A `box x` expression. - Box(P<Expr>), /// An array (`[a, b, c, d]`) Array(ThinVec<P<Expr>>), /// Allow anonymous constants from an inline `const` block diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index 6fed0b660e8..45a5a3ecb53 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -1316,7 +1316,6 @@ pub fn noop_visit_expr<T: MutVisitor>( vis: &mut T, ) { match kind { - ExprKind::Box(expr) => vis.visit_expr(expr), ExprKind::Array(exprs) => visit_thin_exprs(exprs, vis), ExprKind::ConstBlock(anon_const) => { vis.visit_anon_const(anon_const); diff --git a/compiler/rustc_ast/src/util/classify.rs b/compiler/rustc_ast/src/util/classify.rs index cdc244c1218..607b77705cf 100644 --- a/compiler/rustc_ast/src/util/classify.rs +++ b/compiler/rustc_ast/src/util/classify.rs @@ -35,7 +35,6 @@ pub fn expr_trailing_brace(mut expr: &ast::Expr) -> Option<&ast::Expr> { | Assign(_, e, _) | AssignOp(_, _, e) | Binary(_, _, e) - | Box(e) | Break(_, Some(e)) | Let(_, e, _) | Range(_, Some(e), _) diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index bdb1879ec20..9a4da6d4396 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -772,7 +772,6 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) { walk_list!(visitor, visit_attribute, expression.attrs.iter()); match &expression.kind { - ExprKind::Box(subexpression) => visitor.visit_expr(subexpression), ExprKind::Array(subexpressions) => { walk_list!(visitor, visit_expr, subexpressions); } diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index ffb30b1b391..4390680c45a 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -70,7 +70,6 @@ impl<'hir> LoweringContext<'_, 'hir> { self.lower_attrs(hir_id, &e.attrs); let kind = match &e.kind { - ExprKind::Box(inner) => hir::ExprKind::Box(self.lower_expr(inner)), ExprKind::Array(exprs) => hir::ExprKind::Array(self.lower_exprs(exprs)), ExprKind::ConstBlock(anon_const) => { let anon_const = self.lower_anon_const(anon_const); diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index 96042ea3078..109f83d4d18 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -395,14 +395,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { fn visit_expr(&mut self, e: &'a ast::Expr) { match e.kind { - ast::ExprKind::Box(_) => { - gate_feature_post!( - &self, - box_syntax, - e.span, - "box expression syntax is experimental; you can call `Box::new` instead" - ); - } ast::ExprKind::Type(..) => { if self.sess.parse_sess.span_diagnostic.err_count() == 0 { // To avoid noise about type ascription in common syntax errors, @@ -613,7 +605,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) { gate_all!(box_patterns, "box pattern syntax is experimental"); gate_all!(exclusive_range_pattern, "exclusive range pattern syntax is experimental"); gate_all!(try_blocks, "`try` blocks are unstable"); - gate_all!(box_syntax, "box expression syntax is experimental; you can call `Box::new` instead"); gate_all!(type_ascription, "type ascription is experimental"); visit::walk_crate(&mut visitor, krate); diff --git a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs index a4d91a95662..e2f63641ffa 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs @@ -296,10 +296,6 @@ impl<'a> State<'a> { self.ibox(INDENT_UNIT); self.ann.pre(self, AnnNode::Expr(expr)); match &expr.kind { - ast::ExprKind::Box(expr) => { - self.word_space("box"); - self.print_expr_maybe_paren(expr, parser::PREC_PREFIX); - } ast::ExprKind::Array(exprs) => { self.print_expr_vec(exprs); } diff --git a/compiler/rustc_builtin_macros/src/assert/context.rs b/compiler/rustc_builtin_macros/src/assert/context.rs index b0b4dda16af..5d8f4db76f9 100644 --- a/compiler/rustc_builtin_macros/src/assert/context.rs +++ b/compiler/rustc_builtin_macros/src/assert/context.rs @@ -290,7 +290,6 @@ impl<'cx, 'a> Context<'cx, 'a> { | ExprKind::Async(_, _, _) | ExprKind::Await(_) | ExprKind::Block(_, _) - | ExprKind::Box(_) | ExprKind::Break(_, _) | ExprKind::Closure(_) | ExprKind::ConstBlock(_) diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 2fa7bceb8bc..c893b34b4ac 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -200,8 +200,6 @@ declare_features! ( (active, auto_traits, "1.50.0", Some(13231), None), /// Allows using `box` in patterns (RFC 469). (active, box_patterns, "1.0.0", Some(29641), None), - /// Allows using the `box $expr` syntax. - (active, box_syntax, "1.0.0", Some(49733), None), /// Allows `#[doc(notable_trait)]`. /// Renamed from `doc_spotlight`. (active, doc_notable_trait, "1.52.0", Some(45040), None), diff --git a/compiler/rustc_feature/src/removed.rs b/compiler/rustc_feature/src/removed.rs index 04d4f6cb14e..48d9fbfa6d2 100644 --- a/compiler/rustc_feature/src/removed.rs +++ b/compiler/rustc_feature/src/removed.rs @@ -52,6 +52,8 @@ declare_features! ( (removed, allow_fail, "1.19.0", Some(46488), None, Some("removed due to no clear use cases")), (removed, await_macro, "1.38.0", Some(50547), None, Some("subsumed by `.await` syntax")), + /// Allows using the `box $expr` syntax. + (removed, box_syntax, "CURRENT_RUSTC_VERSION", Some(49733), None, Some("replaced with `#[rustc_box]`")), /// Allows capturing disjoint fields in a closure/generator (RFC 2229). (removed, capture_disjoint_fields, "1.49.0", Some(53488), None, Some("stabilized in Rust 2021")), /// Allows comparing raw pointers during const eval. diff --git a/compiler/rustc_parse/messages.ftl b/compiler/rustc_parse/messages.ftl index ab7931d74d7..c39ada95a4e 100644 --- a/compiler/rustc_parse/messages.ftl +++ b/compiler/rustc_parse/messages.ftl @@ -731,3 +731,6 @@ parse_unknown_start_of_token = unknown start of token: {$escaped} [one] once more *[other] {$repeats} more times } + +parse_box_syntax_removed = `box_syntax` has been removed + .suggestion = use `Box::new()` instead diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index 63e5bc50513..af0c3026c66 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -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, +} diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index e00eda47c66..27516716286 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -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 diff --git a/compiler/rustc_passes/src/hir_stats.rs b/compiler/rustc_passes/src/hir_stats.rs index 5e2d2d3e5a7..3e0d53029ef 100644 --- a/compiler/rustc_passes/src/hir_stats.rs +++ b/compiler/rustc_passes/src/hir_stats.rs @@ -565,7 +565,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { record_variants!( (self, e, e.kind, Id::None, ast, Expr, ExprKind), [ - Box, Array, ConstBlock, Call, MethodCall, Tup, Binary, Unary, Lit, Cast, Type, Let, + Array, ConstBlock, Call, MethodCall, Tup, Binary, Unary, Lit, Cast, Type, Let, If, While, ForLoop, Loop, Match, Closure, Block, Async, Await, TryBlock, Assign, AssignOp, Field, Index, Range, Underscore, Path, AddrOf, Break, Continue, Ret, InlineAsm, FormatArgs, MacCall, Struct, Repeat, Paren, Try, Yield, Yeet, IncludedBytes, Err |
