Skip to content

Commit dd7df04

Browse files
committed
Remove uses of box_syntax in rustc and tools
1 parent 24c0b81 commit dd7df04

File tree

80 files changed

+851
-944
lines changed

Some content is hidden

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

80 files changed

+851
-944
lines changed

compiler/rustc_codegen_cranelift/example/alloc_example.rs

+2-2
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

+4-4
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 {

compiler/rustc_codegen_gcc/example/alloc_example.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(start, box_syntax, core_intrinsics, alloc_error_handler, lang_items)]
1+
#![feature(start, core_intrinsics, alloc_error_handler, lang_items)]
22
#![no_std]
33

44
extern crate alloc;
@@ -38,7 +38,7 @@ unsafe extern "C" fn _Unwind_Resume() {
3838

3939
#[start]
4040
fn main(_argc: isize, _argv: *const *const u8) -> isize {
41-
let world: Box<&str> = box "Hello World!\0";
41+
let world: Box<&str> = Box::new("Hello World!\0");
4242
unsafe {
4343
puts(*world as *const str as *const u8);
4444
}

compiler/rustc_codegen_gcc/example/mini_core_hello_world.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Adapted from https://github.com/sunfishcode/mir2cranelift/blob/master/rust-examples/nocore-hello-world.rs
22

33
#![feature(
4-
no_core, unboxed_closures, start, lang_items, box_syntax, never_type, linkage,
4+
no_core, unboxed_closures, start, lang_items, never_type, linkage,
55
extern_types, thread_local
66
)]
77
#![no_core]
@@ -163,7 +163,7 @@ fn main() {
163163
let ptr: *const u8 = hello as *const [u8] as *const u8;
164164
puts(ptr);
165165

166-
let world: Box<&str> = box "World!\0";
166+
let world: Box<&str> = Box::new("World!\0");
167167
puts(*world as *const str as *const u8);
168168
world as Box<dyn SomeTrait>;
169169

@@ -223,10 +223,10 @@ fn main() {
223223
}
224224
}
225225

226-
let _ = box NoisyDrop {
226+
let _ = Box::new(NoisyDrop {
227227
text: "Boxed outer got dropped!\0",
228228
inner: NoisyDropInner,
229-
} as Box<dyn SomeTrait>;
229+
}) as Box<dyn SomeTrait>;
230230

231231
const FUNC_REF: Option<fn()> = Some(main);
232232
#[allow(unreachable_code)]

compiler/rustc_codegen_gcc/example/mod_bench.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(start, box_syntax, core_intrinsics, lang_items)]
1+
#![feature(start, core_intrinsics, lang_items)]
22
#![no_std]
33

44
#[link(name = "c")]

compiler/rustc_error_codes/src/error_codes/E0010.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,5 @@ the heap at runtime, and therefore cannot be done at compile time.
55
Erroneous code example:
66

77
```compile_fail,E0010
8-
#![feature(box_syntax)]
9-
10-
const CON : Box<i32> = box 0;
8+
const CON : Vec<i32> = vec![1, 2, 3];
119
```

compiler/rustc_hir_pretty/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1367,8 +1367,8 @@ impl<'a> State<'a> {
13671367
self.ann.pre(self, AnnNode::Expr(expr));
13681368
match expr.kind {
13691369
hir::ExprKind::Box(expr) => {
1370-
self.word_space("box");
1371-
self.print_expr_maybe_paren(expr, parser::PREC_PREFIX);
1370+
self.word_space("Box::new");
1371+
self.print_call_post(std::slice::from_ref(expr));
13721372
}
13731373
hir::ExprKind::Array(exprs) => {
13741374
self.print_expr_vec(exprs);

compiler/rustc_lint/src/unused.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,6 @@ declare_lint_pass!(UnusedAllocation => [UNUSED_ALLOCATION]);
13711371
impl<'tcx> LateLintPass<'tcx> for UnusedAllocation {
13721372
fn check_expr(&mut self, cx: &LateContext<'_>, e: &hir::Expr<'_>) {
13731373
match e.kind {
1374-
hir::ExprKind::Box(_) => {}
13751374
hir::ExprKind::Call(path_expr, [_])
13761375
if let hir::ExprKind::Path(qpath) = &path_expr.kind
13771376
&& let Some(did) = cx.qpath_res(qpath, path_expr.hir_id).opt_def_id()

compiler/rustc_mir_transform/src/large_enums.rs

+25-20
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,12 @@ impl EnumSizeOpt {
158158
tmp_ty,
159159
),
160160
};
161-
let rval = Rvalue::Use(Operand::Constant(box (constant_vals)));
161+
let rval = Rvalue::Use(Operand::Constant(Box::new(constant_vals)));
162162

163-
let const_assign =
164-
Statement { source_info, kind: StatementKind::Assign(box (place, rval)) };
163+
let const_assign = Statement {
164+
source_info,
165+
kind: StatementKind::Assign(Box::new((place, rval))),
166+
};
165167

166168
let discr_place = Place::from(
167169
local_decls
@@ -170,48 +172,51 @@ impl EnumSizeOpt {
170172

171173
let store_discr = Statement {
172174
source_info,
173-
kind: StatementKind::Assign(box (discr_place, Rvalue::Discriminant(*rhs))),
175+
kind: StatementKind::Assign(Box::new((
176+
discr_place,
177+
Rvalue::Discriminant(*rhs),
178+
))),
174179
};
175180

176181
let discr_cast_place =
177182
Place::from(local_decls.push(LocalDecl::new(tcx.types.usize, span)));
178183

179184
let cast_discr = Statement {
180185
source_info,
181-
kind: StatementKind::Assign(box (
186+
kind: StatementKind::Assign(Box::new((
182187
discr_cast_place,
183188
Rvalue::Cast(
184189
CastKind::IntToInt,
185190
Operand::Copy(discr_place),
186191
tcx.types.usize,
187192
),
188-
)),
193+
))),
189194
};
190195

191196
let size_place =
192197
Place::from(local_decls.push(LocalDecl::new(tcx.types.usize, span)));
193198

194199
let store_size = Statement {
195200
source_info,
196-
kind: StatementKind::Assign(box (
201+
kind: StatementKind::Assign(Box::new((
197202
size_place,
198203
Rvalue::Use(Operand::Copy(Place {
199204
local: size_array_local,
200205
projection: tcx
201206
.mk_place_elems(&[PlaceElem::Index(discr_cast_place.local)]),
202207
})),
203-
)),
208+
))),
204209
};
205210

206211
let dst =
207212
Place::from(local_decls.push(LocalDecl::new(tcx.mk_mut_ptr(ty), span)));
208213

209214
let dst_ptr = Statement {
210215
source_info,
211-
kind: StatementKind::Assign(box (
216+
kind: StatementKind::Assign(Box::new((
212217
dst,
213218
Rvalue::AddressOf(Mutability::Mut, *lhs),
214-
)),
219+
))),
215220
};
216221

217222
let dst_cast_ty = tcx.mk_mut_ptr(tcx.types.u8);
@@ -220,21 +225,21 @@ impl EnumSizeOpt {
220225

221226
let dst_cast = Statement {
222227
source_info,
223-
kind: StatementKind::Assign(box (
228+
kind: StatementKind::Assign(Box::new((
224229
dst_cast_place,
225230
Rvalue::Cast(CastKind::PtrToPtr, Operand::Copy(dst), dst_cast_ty),
226-
)),
231+
))),
227232
};
228233

229234
let src =
230235
Place::from(local_decls.push(LocalDecl::new(tcx.mk_imm_ptr(ty), span)));
231236

232237
let src_ptr = Statement {
233238
source_info,
234-
kind: StatementKind::Assign(box (
239+
kind: StatementKind::Assign(Box::new((
235240
src,
236241
Rvalue::AddressOf(Mutability::Not, *rhs),
237-
)),
242+
))),
238243
};
239244

240245
let src_cast_ty = tcx.mk_imm_ptr(tcx.types.u8);
@@ -243,24 +248,24 @@ impl EnumSizeOpt {
243248

244249
let src_cast = Statement {
245250
source_info,
246-
kind: StatementKind::Assign(box (
251+
kind: StatementKind::Assign(Box::new((
247252
src_cast_place,
248253
Rvalue::Cast(CastKind::PtrToPtr, Operand::Copy(src), src_cast_ty),
249-
)),
254+
))),
250255
};
251256

252257
let deinit_old =
253-
Statement { source_info, kind: StatementKind::Deinit(box dst) };
258+
Statement { source_info, kind: StatementKind::Deinit(Box::new(dst)) };
254259

255260
let copy_bytes = Statement {
256261
source_info,
257-
kind: StatementKind::Intrinsic(
258-
box NonDivergingIntrinsic::CopyNonOverlapping(CopyNonOverlapping {
262+
kind: StatementKind::Intrinsic(Box::new(
263+
NonDivergingIntrinsic::CopyNonOverlapping(CopyNonOverlapping {
259264
src: Operand::Copy(src_cast_place),
260265
dst: Operand::Copy(dst_cast_place),
261266
count: Operand::Copy(size_place),
262267
}),
263-
),
268+
)),
264269
};
265270

266271
let store_dead = Statement {

compiler/rustc_mir_transform/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![allow(rustc::potential_query_instability)]
22
#![feature(box_patterns)]
33
#![feature(drain_filter)]
4-
#![feature(box_syntax)]
54
#![feature(let_chains)]
65
#![feature(map_try_insert)]
76
#![feature(min_specialization)]

src/doc/unstable-book/src/the-unstable-book.md

+19-4
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,31 @@ each one organized by a "feature flag." That is, when using an unstable
55
feature of Rust, you must use a flag, like this:
66

77
```rust
8-
#![feature(box_syntax)]
8+
#![feature(generators, generator_trait)]
9+
10+
use std::ops::{Generator, GeneratorState};
11+
use std::pin::Pin;
912

1013
fn main() {
11-
let five = box 5;
14+
let mut generator = || {
15+
yield 1;
16+
return "foo"
17+
};
18+
19+
match Pin::new(&mut generator).resume(()) {
20+
GeneratorState::Yielded(1) => {}
21+
_ => panic!("unexpected value from resume"),
22+
}
23+
match Pin::new(&mut generator).resume(()) {
24+
GeneratorState::Complete("foo") => {}
25+
_ => panic!("unexpected value from resume"),
26+
}
1227
}
1328
```
1429

15-
The `box_syntax` feature [has a chapter][box] describing how to use it.
30+
The `generators` feature [has a chapter][generators] describing how to use it.
1631

17-
[box]: language-features/box-syntax.md
32+
[generators]: language-features/generators.md
1833

1934
Because this documentation relates to unstable features, we make no guarantees
2035
that what is contained here is accurate or up to date. It's developed on a

src/tools/clippy/tests/ui/boxed_local.rs

+12-23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(box_syntax)]
21
#![feature(lint_reasons)]
32
#![allow(
43
clippy::borrowed_box,
@@ -34,7 +33,7 @@ fn ok_box_trait(boxed_trait: &Box<dyn Z>) {
3433
}
3534

3635
fn warn_call() {
37-
let x = box A;
36+
let x = Box::new(A);
3837
x.foo();
3938
}
4039

@@ -43,41 +42,41 @@ fn warn_arg(x: Box<A>) {
4342
}
4443

4544
fn nowarn_closure_arg() {
46-
let x = Some(box A);
45+
let x = Some(Box::new(A));
4746
x.map_or((), |x| take_ref(&x));
4847
}
4948

5049
fn warn_rename_call() {
51-
let x = box A;
50+
let x = Box::new(A);
5251

5352
let y = x;
5453
y.foo(); // via autoderef
5554
}
5655

5756
fn warn_notuse() {
58-
let bz = box A;
57+
let bz = Box::new(A);
5958
}
6059

6160
fn warn_pass() {
62-
let bz = box A;
61+
let bz = Box::new(A);
6362
take_ref(&bz); // via deref coercion
6463
}
6564

6665
fn nowarn_return() -> Box<A> {
67-
box A // moved out, "escapes"
66+
Box::new(A) // moved out, "escapes"
6867
}
6968

7069
fn nowarn_move() {
71-
let bx = box A;
70+
let bx = Box::new(A);
7271
drop(bx) // moved in, "escapes"
7372
}
7473
fn nowarn_call() {
75-
let bx = box A;
74+
let bx = Box::new(A);
7675
bx.clone(); // method only available to Box, not via autoderef
7776
}
7877

7978
fn nowarn_pass() {
80-
let bx = box A;
79+
let bx = Box::new(A);
8180
take_box(&bx); // fn needs &Box
8281
}
8382

@@ -86,30 +85,20 @@ fn take_ref(x: &A) {}
8685

8786
fn nowarn_ref_take() {
8887
// false positive, should actually warn
89-
let x = box A;
88+
let x = Box::new(A);
9089
let y = &x;
9190
take_box(y);
9291
}
9392

9493
fn nowarn_match() {
95-
let x = box A; // moved into a match
94+
let x = Box::new(A); // moved into a match
9695
match x {
9796
y => drop(y),
9897
}
9998
}
10099

101100
fn warn_match() {
102-
let x = box A;
103-
match &x {
104-
// not moved
105-
y => (),
106-
}
107-
}
108-
109-
fn nowarn_large_array() {
110-
// should not warn, is large array
111-
// and should not be on stack
112-
let x = box [1; 10000];
101+
let x = Box::new(A);
113102
match &x {
114103
// not moved
115104
y => (),

0 commit comments

Comments
 (0)