Skip to content

Commit 4dc819f

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 69924c8 + 89a9c30 commit 4dc819f

9 files changed

+15
-38
lines changed

tests/fail/function_pointers/execute_memory.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
// Validation makes this fail in the wrong place
22
//@compile-flags: -Zmiri-disable-validation
33

4-
#![feature(box_syntax)]
5-
64
fn main() {
7-
let x = box 42;
5+
let x = Box::new(42);
86
unsafe {
97
let f = std::mem::transmute::<Box<i32>, fn()>(x);
108
f() //~ ERROR: function pointer but it does not point to a function

tests/pass/drop_empty_slice.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
#![feature(box_syntax)]
2-
31
fn main() {
42
// With the nested Vec, this is calling Offset(Unique::empty(), 0) on drop.
53
let args: Vec<Vec<i32>> = Vec::new();
6-
let _val = box args;
4+
let _val = Box::new(args);
75
}

tests/pass/dst-struct.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(box_syntax)]
2-
31
struct Fat<T: ?Sized> {
42
f1: isize,
53
f2: &'static str,
@@ -109,14 +107,14 @@ pub fn main() {
109107
assert_eq!((*f2)[1], 2);
110108

111109
// Nested Box.
112-
let f1: Box<Fat<[isize; 3]>> = box Fat { f1: 5, f2: "some str", ptr: [1, 2, 3] };
110+
let f1: Box<Fat<[isize; 3]>> = Box::new(Fat { f1: 5, f2: "some str", ptr: [1, 2, 3] });
113111
foo(&*f1);
114112
let f2: Box<Fat<[isize]>> = f1;
115113
foo(&*f2);
116114

117115
let f3: Box<Fat<[isize]>> =
118116
Box::<Fat<[_; 3]>>::new(Fat { f1: 5, f2: "some str", ptr: [1, 2, 3] });
119117
foo(&*f3);
120-
let f4: Box<Fat<[isize]>> = box Fat { f1: 5, f2: "some str", ptr: [1, 2, 3] };
118+
let f4: Box<Fat<[isize]>> = Box::new(Fat { f1: 5, f2: "some str", ptr: [1, 2, 3] });
121119
foo(&*f4);
122120
}

tests/pass/heap.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
#![feature(box_syntax)]
2-
31
fn make_box() -> Box<(i16, i16)> {
42
Box::new((1, 2))
53
}
64

7-
fn make_box_syntax() -> Box<(i16, i16)> {
8-
box (1, 2)
9-
}
10-
115
fn allocate_reallocate() {
126
let mut s = String::new();
137

@@ -29,6 +23,5 @@ fn allocate_reallocate() {
2923

3024
fn main() {
3125
assert_eq!(*make_box(), (1, 2));
32-
assert_eq!(*make_box_syntax(), (1, 2));
3326
allocate_reallocate();
3427
}

tests/pass/issues/issue-3794.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(box_syntax)]
2-
31
trait T {
42
fn print(&self);
53
}
@@ -25,7 +23,7 @@ fn print_s(s: &S) {
2523
}
2624

2725
pub fn main() {
28-
let s: Box<S> = box S { s: 5 };
26+
let s: Box<S> = Box::new(S { s: 5 });
2927
print_s(&*s);
3028
let t: Box<dyn T> = s as Box<dyn T>;
3129
print_t(&*t);

tests/pass/move-arg-2-unique.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
#![feature(box_syntax)]
2-
31
fn test(foo: Box<Vec<isize>>) {
42
assert_eq!((*foo)[0], 10);
53
}
64

75
pub fn main() {
8-
let x = box vec![10];
6+
let x = Box::new(vec![10]);
97
// Test forgetting a local by move-in
108
test(x);
119
}

tests/pass/move-arg-3-unique.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
#![feature(box_syntax)]
2-
31
pub fn main() {
4-
let x = box 10;
2+
let x = Box::new(10);
53
let y = x;
64
assert_eq!(*y, 10);
75
}

tests/pass/mpsc.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
#![feature(box_syntax)]
2-
31
use std::sync::mpsc::channel;
42

53
pub fn main() {
64
let (tx, rx) = channel::<Box<_>>();
7-
tx.send(box 100).unwrap();
5+
tx.send(Box::new(100)).unwrap();
86
let v = rx.recv().unwrap();
9-
assert_eq!(v, box 100);
7+
assert_eq!(v, Box::new(100));
108

11-
tx.send(box 101).unwrap();
12-
tx.send(box 102).unwrap();
13-
assert_eq!(rx.recv().unwrap(), box 101);
14-
assert_eq!(rx.recv().unwrap(), box 102);
9+
tx.send(Box::new(101)).unwrap();
10+
tx.send(Box::new(102)).unwrap();
11+
assert_eq!(rx.recv().unwrap(), Box::new(101));
12+
assert_eq!(rx.recv().unwrap(), Box::new(102));
1513
}

tests/pass/regions-lifetime-nonfree-late-bound.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@
1212
// doing region-folding, when really all clients of the region-folding
1313
// case only want to see *free* lifetime variables, not bound ones.
1414

15-
#![feature(box_syntax)]
16-
1715
pub fn main() {
1816
fn explicit() {
1917
fn test<F>(_x: Option<Box<F>>)
2018
where
2119
F: FnMut(Box<dyn for<'a> FnMut(&'a isize)>),
2220
{
2321
}
24-
test(Some(box |_f: Box<dyn for<'a> FnMut(&'a isize)>| {}));
22+
test(Some(Box::new(|_f: Box<dyn for<'a> FnMut(&'a isize)>| {})));
2523
}
2624

2725
// The code below is shorthand for the code above (and more likely
@@ -32,7 +30,7 @@ pub fn main() {
3230
F: FnMut(Box<dyn FnMut(&isize)>),
3331
{
3432
}
35-
test(Some(box |_f: Box<dyn FnMut(&isize)>| {}));
33+
test(Some(Box::new(|_f: Box<dyn FnMut(&isize)>| {})));
3634
}
3735

3836
explicit();

0 commit comments

Comments
 (0)