Skip to content

Commit 0932452

Browse files
committed
Remove box_syntax from AST and use in tools
1 parent dd7df04 commit 0932452

File tree

28 files changed

+40
-95
lines changed

28 files changed

+40
-95
lines changed

compiler/rustc_ast/src/ast.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,6 @@ impl Expr {
12301230

12311231
pub fn precedence(&self) -> ExprPrecedence {
12321232
match self.kind {
1233-
ExprKind::Box(_) => ExprPrecedence::Box,
12341233
ExprKind::Array(_) => ExprPrecedence::Array,
12351234
ExprKind::ConstBlock(_) => ExprPrecedence::ConstBlock,
12361235
ExprKind::Call(..) => ExprPrecedence::Call,
@@ -1291,8 +1290,7 @@ impl Expr {
12911290
/// To a first-order approximation, is this a pattern?
12921291
pub fn is_approximately_pattern(&self) -> bool {
12931292
match &self.peel_parens().kind {
1294-
ExprKind::Box(_)
1295-
| ExprKind::Array(_)
1293+
ExprKind::Array(_)
12961294
| ExprKind::Call(_, _)
12971295
| ExprKind::Tup(_)
12981296
| ExprKind::Lit(_)
@@ -1363,8 +1361,6 @@ pub struct StructExpr {
13631361

13641362
#[derive(Clone, Encodable, Decodable, Debug)]
13651363
pub enum ExprKind {
1366-
/// A `box x` expression.
1367-
Box(P<Expr>),
13681364
/// An array (`[a, b, c, d]`)
13691365
Array(ThinVec<P<Expr>>),
13701366
/// Allow anonymous constants from an inline `const` block

compiler/rustc_ast/src/mut_visit.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,6 @@ pub fn noop_visit_expr<T: MutVisitor>(
13161316
vis: &mut T,
13171317
) {
13181318
match kind {
1319-
ExprKind::Box(expr) => vis.visit_expr(expr),
13201319
ExprKind::Array(exprs) => visit_thin_exprs(exprs, vis),
13211320
ExprKind::ConstBlock(anon_const) => {
13221321
vis.visit_anon_const(anon_const);

compiler/rustc_ast/src/util/classify.rs

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ pub fn expr_trailing_brace(mut expr: &ast::Expr) -> Option<&ast::Expr> {
3535
| Assign(_, e, _)
3636
| AssignOp(_, _, e)
3737
| Binary(_, _, e)
38-
| Box(e)
3938
| Break(_, Some(e))
4039
| Let(_, e, _)
4140
| Range(_, Some(e), _)

compiler/rustc_ast/src/visit.rs

-1
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,6 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
772772
walk_list!(visitor, visit_attribute, expression.attrs.iter());
773773

774774
match &expression.kind {
775-
ExprKind::Box(subexpression) => visitor.visit_expr(subexpression),
776775
ExprKind::Array(subexpressions) => {
777776
walk_list!(visitor, visit_expr, subexpressions);
778777
}

compiler/rustc_ast_lowering/src/expr.rs

-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
7070
self.lower_attrs(hir_id, &e.attrs);
7171

7272
let kind = match &e.kind {
73-
ExprKind::Box(inner) => hir::ExprKind::Box(self.lower_expr(inner)),
7473
ExprKind::Array(exprs) => hir::ExprKind::Array(self.lower_exprs(exprs)),
7574
ExprKind::ConstBlock(anon_const) => {
7675
let anon_const = self.lower_anon_const(anon_const);

compiler/rustc_ast_passes/src/feature_gate.rs

-9
Original file line numberDiff line numberDiff line change
@@ -395,14 +395,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
395395

396396
fn visit_expr(&mut self, e: &'a ast::Expr) {
397397
match e.kind {
398-
ast::ExprKind::Box(_) => {
399-
gate_feature_post!(
400-
&self,
401-
box_syntax,
402-
e.span,
403-
"box expression syntax is experimental; you can call `Box::new` instead"
404-
);
405-
}
406398
ast::ExprKind::Type(..) => {
407399
if self.sess.parse_sess.span_diagnostic.err_count() == 0 {
408400
// To avoid noise about type ascription in common syntax errors,
@@ -613,7 +605,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
613605
gate_all!(box_patterns, "box pattern syntax is experimental");
614606
gate_all!(exclusive_range_pattern, "exclusive range pattern syntax is experimental");
615607
gate_all!(try_blocks, "`try` blocks are unstable");
616-
gate_all!(box_syntax, "box expression syntax is experimental; you can call `Box::new` instead");
617608
gate_all!(type_ascription, "type ascription is experimental");
618609

619610
visit::walk_crate(&mut visitor, krate);

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

-4
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,6 @@ impl<'a> State<'a> {
296296
self.ibox(INDENT_UNIT);
297297
self.ann.pre(self, AnnNode::Expr(expr));
298298
match &expr.kind {
299-
ast::ExprKind::Box(expr) => {
300-
self.word_space("box");
301-
self.print_expr_maybe_paren(expr, parser::PREC_PREFIX);
302-
}
303299
ast::ExprKind::Array(exprs) => {
304300
self.print_expr_vec(exprs);
305301
}

compiler/rustc_builtin_macros/src/assert/context.rs

-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ impl<'cx, 'a> Context<'cx, 'a> {
290290
| ExprKind::Async(_, _, _)
291291
| ExprKind::Await(_)
292292
| ExprKind::Block(_, _)
293-
| ExprKind::Box(_)
294293
| ExprKind::Break(_, _)
295294
| ExprKind::Closure(_)
296295
| ExprKind::ConstBlock(_)

compiler/rustc_feature/src/active.rs

-2
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,6 @@ declare_features! (
200200
(active, auto_traits, "1.50.0", Some(13231), None),
201201
/// Allows using `box` in patterns (RFC 469).
202202
(active, box_patterns, "1.0.0", Some(29641), None),
203-
/// Allows using the `box $expr` syntax.
204-
(active, box_syntax, "1.0.0", Some(49733), None),
205203
/// Allows `#[doc(notable_trait)]`.
206204
/// Renamed from `doc_spotlight`.
207205
(active, doc_notable_trait, "1.52.0", Some(45040), None),

compiler/rustc_feature/src/removed.rs

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ declare_features! (
5252
(removed, allow_fail, "1.19.0", Some(46488), None, Some("removed due to no clear use cases")),
5353
(removed, await_macro, "1.38.0", Some(50547), None,
5454
Some("subsumed by `.await` syntax")),
55+
/// Allows using the `box $expr` syntax.
56+
(removed, box_syntax, "CURRENT_RUSTC_VERSION", Some(49733), None, Some("replaced with `#[rustc_box]`")),
5557
/// Allows capturing disjoint fields in a closure/generator (RFC 2229).
5658
(removed, capture_disjoint_fields, "1.49.0", Some(53488), None, Some("stabilized in Rust 2021")),
5759
/// Allows comparing raw pointers during const eval.

compiler/rustc_parse/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -731,3 +731,6 @@ parse_unknown_start_of_token = unknown start of token: {$escaped}
731731
[one] once more
732732
*[other] {$repeats} more times
733733
}
734+
735+
parse_box_syntax_removed = `box_syntax` has been removed
736+
.suggestion = use `Box::new()` instead

compiler/rustc_parse/src/errors.rs

+13
Original file line numberDiff line numberDiff line change
@@ -2300,3 +2300,16 @@ impl HelpUseLatestEdition {
23002300
}
23012301
}
23022302
}
2303+
2304+
#[derive(Diagnostic)]
2305+
#[diag(parse_box_syntax_removed)]
2306+
pub struct BoxSyntaxRemoved<'a> {
2307+
#[primary_span]
2308+
#[suggestion(
2309+
code = "Box::new({code})",
2310+
applicability = "machine-applicable",
2311+
style = "verbose"
2312+
)]
2313+
pub span: Span,
2314+
pub code: &'a str,
2315+
}

compiler/rustc_parse/src/parser/expr.rs

-10
Original file line numberDiff line numberDiff line change
@@ -607,9 +607,6 @@ impl<'a> Parser<'a> {
607607
let operand_expr = this.parse_expr_dot_or_call(Default::default())?;
608608
this.recover_from_prefix_increment(operand_expr, pre_span, starts_stmt)
609609
}
610-
token::Ident(..) if this.token.is_keyword(kw::Box) => {
611-
make_it!(this, attrs, |this, _| this.parse_expr_box(lo))
612-
}
613610
token::Ident(..) if this.may_recover() && this.is_mistaken_not_ident_negation() => {
614611
make_it!(this, attrs, |this, _| this.recover_not_expr(lo))
615612
}
@@ -636,13 +633,6 @@ impl<'a> Parser<'a> {
636633
self.parse_expr_unary(lo, UnOp::Not)
637634
}
638635

639-
/// Parse `box expr`.
640-
fn parse_expr_box(&mut self, lo: Span) -> PResult<'a, (Span, ExprKind)> {
641-
let (span, expr) = self.parse_expr_prefix_common(lo)?;
642-
self.sess.gated_spans.gate(sym::box_syntax, span);
643-
Ok((span, ExprKind::Box(expr)))
644-
}
645-
646636
fn is_mistaken_not_ident_negation(&self) -> bool {
647637
let token_cannot_continue_expr = |t: &Token| match t.uninterpolate().kind {
648638
// These tokens can start an expression after `!`, but

compiler/rustc_passes/src/hir_stats.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
565565
record_variants!(
566566
(self, e, e.kind, Id::None, ast, Expr, ExprKind),
567567
[
568-
Box, Array, ConstBlock, Call, MethodCall, Tup, Binary, Unary, Lit, Cast, Type, Let,
568+
Array, ConstBlock, Call, MethodCall, Tup, Binary, Unary, Lit, Cast, Type, Let,
569569
If, While, ForLoop, Loop, Match, Closure, Block, Async, Await, TryBlock, Assign,
570570
AssignOp, Field, Index, Range, Underscore, Path, AddrOf, Break, Continue, Ret,
571571
InlineAsm, FormatArgs, MacCall, Struct, Repeat, Paren, Try, Yield, Yeet, IncludedBytes, Err

src/doc/unstable-book/src/language-features/box-patterns.md

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ The tracking issue for this feature is: [#29641]
44

55
[#29641]: https://github.com/rust-lang/rust/issues/29641
66

7-
See also [`box_syntax`](box-syntax.md)
8-
97
------------------------
108

119
Box patterns let you match on `Box<T>`s:

src/tools/clippy/clippy_lints/src/suspicious_operation_groupings.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,7 @@ fn ident_difference_expr_with_base_location(
596596
| (MethodCall(_), MethodCall(_))
597597
| (Call(_, _), Call(_, _))
598598
| (ConstBlock(_), ConstBlock(_))
599-
| (Array(_), Array(_))
600-
| (Box(_), Box(_)) => {
599+
| (Array(_), Array(_)) => {
601600
// keep going
602601
},
603602
_ => {

src/tools/clippy/clippy_utils/src/ast_utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool {
143143
(Paren(l), _) => eq_expr(l, r),
144144
(_, Paren(r)) => eq_expr(l, r),
145145
(Err, Err) => true,
146-
(Box(l), Box(r)) | (Try(l), Try(r)) | (Await(l), Await(r)) => eq_expr(l, r),
146+
(Try(l), Try(r)) | (Await(l), Await(r)) => eq_expr(l, r),
147147
(Array(l), Array(r)) => over(l, r, |l, r| eq_expr(l, r)),
148148
(Tup(l), Tup(r)) => over(l, r, |l, r| eq_expr(l, r)),
149149
(Repeat(le, ls), Repeat(re, rs)) => eq_expr(le, re) && eq_expr(&ls.value, &rs.value),

src/tools/clippy/clippy_utils/src/sugg.rs

-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ impl<'a> Sugg<'a> {
188188
match expr.kind {
189189
_ if expr.span.ctxt() != ctxt => Sugg::NonParen(snippet_with_context(cx, expr.span, ctxt, default, app).0),
190190
ast::ExprKind::AddrOf(..)
191-
| ast::ExprKind::Box(..)
192191
| ast::ExprKind::Closure { .. }
193192
| ast::ExprKind::If(..)
194193
| ast::ExprKind::Let(..)

src/tools/rustfmt/src/closures.rs

-2
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ fn rewrite_closure_expr(
195195
| ast::ExprKind::Struct(..) => true,
196196

197197
ast::ExprKind::AddrOf(_, _, ref expr)
198-
| ast::ExprKind::Box(ref expr)
199198
| ast::ExprKind::Try(ref expr)
200199
| ast::ExprKind::Unary(_, ref expr)
201200
| ast::ExprKind::Cast(ref expr, _) => allow_multi_line(expr),
@@ -441,7 +440,6 @@ fn is_block_closure_forced_inner(expr: &ast::Expr, version: Version) -> bool {
441440
ast::ExprKind::If(..) | ast::ExprKind::While(..) | ast::ExprKind::ForLoop(..) => true,
442441
ast::ExprKind::Loop(..) if version == Version::Two => true,
443442
ast::ExprKind::AddrOf(_, _, ref expr)
444-
| ast::ExprKind::Box(ref expr)
445443
| ast::ExprKind::Try(ref expr)
446444
| ast::ExprKind::Unary(_, ref expr)
447445
| ast::ExprKind::Cast(ref expr, _) => is_block_closure_forced_inner(expr, version),

src/tools/rustfmt/src/expr.rs

-5
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ pub(crate) fn format_expr(
236236
ast::ExprKind::Yeet(Some(ref expr)) => {
237237
rewrite_unary_prefix(context, "do yeet ", &**expr, shape)
238238
}
239-
ast::ExprKind::Box(ref expr) => rewrite_unary_prefix(context, "box ", &**expr, shape),
240239
ast::ExprKind::AddrOf(borrow_kind, mutability, ref expr) => {
241240
rewrite_expr_addrof(context, borrow_kind, mutability, expr, shape)
242241
}
@@ -1299,7 +1298,6 @@ pub(crate) fn is_simple_expr(expr: &ast::Expr) -> bool {
12991298
ast::ExprKind::Lit(..) => true,
13001299
ast::ExprKind::Path(ref qself, ref path) => qself.is_none() && path.segments.len() <= 1,
13011300
ast::ExprKind::AddrOf(_, _, ref expr)
1302-
| ast::ExprKind::Box(ref expr)
13031301
| ast::ExprKind::Cast(ref expr, _)
13041302
| ast::ExprKind::Field(ref expr, _)
13051303
| ast::ExprKind::Try(ref expr)
@@ -1361,7 +1359,6 @@ pub(crate) fn can_be_overflowed_expr(
13611359

13621360
// Handle unary-like expressions
13631361
ast::ExprKind::AddrOf(_, _, ref expr)
1364-
| ast::ExprKind::Box(ref expr)
13651362
| ast::ExprKind::Try(ref expr)
13661363
| ast::ExprKind::Unary(_, ref expr)
13671364
| ast::ExprKind::Cast(ref expr, _) => can_be_overflowed_expr(context, expr, args_len),
@@ -1373,7 +1370,6 @@ pub(crate) fn is_nested_call(expr: &ast::Expr) -> bool {
13731370
match expr.kind {
13741371
ast::ExprKind::Call(..) | ast::ExprKind::MacCall(..) => true,
13751372
ast::ExprKind::AddrOf(_, _, ref expr)
1376-
| ast::ExprKind::Box(ref expr)
13771373
| ast::ExprKind::Try(ref expr)
13781374
| ast::ExprKind::Unary(_, ref expr)
13791375
| ast::ExprKind::Cast(ref expr, _) => is_nested_call(expr),
@@ -2133,7 +2129,6 @@ pub(crate) fn is_method_call(expr: &ast::Expr) -> bool {
21332129
match expr.kind {
21342130
ast::ExprKind::MethodCall(..) => true,
21352131
ast::ExprKind::AddrOf(_, _, ref expr)
2136-
| ast::ExprKind::Box(ref expr)
21372132
| ast::ExprKind::Cast(ref expr, _)
21382133
| ast::ExprKind::Try(ref expr)
21392134
| ast::ExprKind::Unary(_, ref expr) => is_method_call(expr),

src/tools/rustfmt/src/matches.rs

-1
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,6 @@ fn can_flatten_block_around_this(body: &ast::Expr) -> bool {
592592
| ast::ExprKind::Struct(..)
593593
| ast::ExprKind::Tup(..) => true,
594594
ast::ExprKind::AddrOf(_, _, ref expr)
595-
| ast::ExprKind::Box(ref expr)
596595
| ast::ExprKind::Try(ref expr)
597596
| ast::ExprKind::Unary(_, ref expr)
598597
| ast::ExprKind::Index(ref expr, _)

src/tools/rustfmt/src/utils.rs

-1
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,6 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr
492492
| ast::ExprKind::Assign(..)
493493
| ast::ExprKind::AssignOp(..)
494494
| ast::ExprKind::Await(..)
495-
| ast::ExprKind::Box(..)
496495
| ast::ExprKind::Break(..)
497496
| ast::ExprKind::Cast(..)
498497
| ast::ExprKind::Continue(..)

tests/ui/feature-gates/feature-gate-box-expr.rs

-14
This file was deleted.

tests/ui/feature-gates/feature-gate-box-expr.stderr

-12
This file was deleted.

tests/ui/feature-gates/feature-gate-box_syntax.rs

-6
This file was deleted.

tests/ui/feature-gates/feature-gate-box_syntax.stderr

-12
This file was deleted.

tests/ui/parser/removed-syntax-box.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
fn main() {
2+
struct T {
3+
a: u8,
4+
b: u8,
5+
}
6+
let _ = box () //~ ERROR expected expression, found reserved keyword `box`
7+
let _ = box 1;
8+
let _ = box T { a: 12, b: 18 };
9+
let _ = box [5; 30];
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: expected expression, found reserved keyword `box`
2+
--> $DIR/removed-syntax-box.rs:6:13
3+
|
4+
LL | let _ = box ()
5+
| ^^^ expected expression
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)