Skip to content

Commit f1b1ed7

Browse files
committed
Auto merge of #108471 - clubby789:unbox-the-syntax, r=Nilstrieb,est31
Remove `box_syntax` r? `@Nilstrieb` This removes the feature `box_syntax`, which allows the use of `box <expr>` to create a Box, and finalises removing use of the feature from the compiler. `box_patterns` (allowing the use of `box <pat>` in a pattern) is unaffected. It also removes `ast::ExprKind::Box` - the only way to create a 'box' expression now is with the rustc-internal `#[rustc_box]` attribute. As a temporary measure to help users move away, `box <expr>` now parses the inner expression, and emits a `MachineApplicable` lint to replace it with `Box::new` Closes #49733
2 parents d610b0c + 8b186df commit f1b1ed7

File tree

110 files changed

+979
-1054
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+979
-1054
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 1 addition & 5 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -392,14 +392,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
392392

393393
fn visit_expr(&mut self, e: &'a ast::Expr) {
394394
match e.kind {
395-
ast::ExprKind::Box(_) => {
396-
gate_feature_post!(
397-
&self,
398-
box_syntax,
399-
e.span,
400-
"box expression syntax is experimental; you can call `Box::new` instead"
401-
);
402-
}
403395
ast::ExprKind::Type(..) => {
404396
if self.sess.parse_sess.span_diagnostic.err_count() == 0 {
405397
// To avoid noise about type ascription in common syntax errors,
@@ -604,7 +596,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
604596
gate_all!(box_patterns, "box pattern syntax is experimental");
605597
gate_all!(exclusive_range_pattern, "exclusive range pattern syntax is experimental");
606598
gate_all!(try_blocks, "`try` blocks are unstable");
607-
gate_all!(box_syntax, "box expression syntax is experimental; you can call `Box::new` instead");
608599
gate_all!(type_ascription, "type ascription is experimental");
609600

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

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

Lines changed: 0 additions & 4 deletions
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

Lines changed: 0 additions & 1 deletion
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_codegen_cranelift/example/alloc_example.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(start, core_intrinsics, alloc_error_handler, box_syntax)]
1+
#![feature(start, core_intrinsics, alloc_error_handler)]
22
#![no_std]
33

44
extern crate alloc;
@@ -29,7 +29,7 @@ fn alloc_error_handler(_: alloc::alloc::Layout) -> ! {
2929

3030
#[start]
3131
fn main(_argc: isize, _argv: *const *const u8) -> isize {
32-
let world: Box<&str> = box "Hello World!\0";
32+
let world: Box<&str> = Box::new("Hello World!\0");
3333
unsafe {
3434
puts(*world as *const str as *const u8);
3535
}

compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(no_core, lang_items, never_type, linkage, extern_types, thread_local, box_syntax)]
1+
#![feature(no_core, lang_items, never_type, linkage, extern_types, thread_local)]
22
#![no_core]
33
#![allow(dead_code, non_camel_case_types)]
44

@@ -178,7 +178,7 @@ fn main() {
178178
let ptr: *const i8 = hello as *const [u8] as *const i8;
179179
puts(ptr);
180180

181-
let world: Box<&str> = box "World!\0";
181+
let world: Box<&str> = Box::new("World!\0");
182182
puts(*world as *const str as *const i8);
183183
world as Box<dyn SomeTrait>;
184184

@@ -238,10 +238,10 @@ fn main() {
238238
}
239239
}
240240

241-
let _ = box NoisyDrop {
241+
let _ = Box::new(NoisyDrop {
242242
text: "Boxed outer got dropped!\0",
243243
inner: NoisyDropInner,
244-
} as Box<dyn SomeTrait>;
244+
}) as Box<dyn SomeTrait>;
245245

246246
const FUNC_REF: Option<fn()> = Some(main);
247247
match FUNC_REF {

0 commit comments

Comments
 (0)