Skip to content

Commit 593b86d

Browse files
committed
Remove box syntax from rustc_mir
1 parent 6f1c60f commit 593b86d

19 files changed

+117
-99
lines changed

compiler/rustc_mir/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Rust MIR: a lowered representation of Rust.
1111
#![cfg_attr(bootstrap, feature(bindings_after_at))]
1212
#![feature(bool_to_option)]
1313
#![feature(box_patterns)]
14-
#![feature(box_syntax)]
1514
#![feature(crate_visibility_modifier)]
1615
#![feature(decl_macro)]
1716
#![feature(exact_size_is_empty)]

compiler/rustc_mir/src/shim.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>)
174174
0,
175175
Statement {
176176
source_info,
177-
kind: StatementKind::Retag(RetagKind::Raw, box (dropee_ptr)),
177+
kind: StatementKind::Retag(RetagKind::Raw, Box::new(dropee_ptr)),
178178
},
179179
);
180180
}
@@ -388,10 +388,10 @@ impl CloneShimBuilder<'tcx> {
388388

389389
fn copy_shim(&mut self) {
390390
let rcvr = self.tcx.mk_place_deref(Place::from(Local::new(1 + 0)));
391-
let ret_statement = self.make_statement(StatementKind::Assign(box (
391+
let ret_statement = self.make_statement(StatementKind::Assign(Box::new((
392392
Place::return_place(),
393393
Rvalue::Use(Operand::Copy(rcvr)),
394-
)));
394+
))));
395395
self.block(vec![ret_statement], TerminatorKind::Return, false);
396396
}
397397

@@ -418,22 +418,22 @@ impl CloneShimBuilder<'tcx> {
418418

419419
// `func == Clone::clone(&ty) -> ty`
420420
let func_ty = tcx.mk_fn_def(self.def_id, substs);
421-
let func = Operand::Constant(box Constant {
421+
let func = Operand::Constant(Box::new(Constant {
422422
span: self.span,
423423
user_ty: None,
424424
literal: ty::Const::zero_sized(tcx, func_ty).into(),
425-
});
425+
}));
426426

427427
let ref_loc = self.make_place(
428428
Mutability::Not,
429429
tcx.mk_ref(tcx.lifetimes.re_erased, ty::TypeAndMut { ty, mutbl: hir::Mutability::Not }),
430430
);
431431

432432
// `let ref_loc: &ty = &src;`
433-
let statement = self.make_statement(StatementKind::Assign(box (
433+
let statement = self.make_statement(StatementKind::Assign(Box::new((
434434
ref_loc,
435435
Rvalue::Ref(tcx.lifetimes.re_erased, BorrowKind::Shared, src),
436-
)));
436+
))));
437437

438438
// `let loc = Clone::clone(ref_loc);`
439439
self.block(
@@ -461,10 +461,10 @@ impl CloneShimBuilder<'tcx> {
461461
let tcx = self.tcx;
462462

463463
let cond = self.make_place(Mutability::Mut, tcx.types.bool);
464-
let compute_cond = self.make_statement(StatementKind::Assign(box (
464+
let compute_cond = self.make_statement(StatementKind::Assign(Box::new((
465465
cond,
466-
Rvalue::BinaryOp(BinOp::Ne, box (Operand::Copy(end), Operand::Copy(beg))),
467-
)));
466+
Rvalue::BinaryOp(BinOp::Ne, Box::new((Operand::Copy(end), Operand::Copy(beg)))),
467+
))));
468468

469469
// `if end != beg { goto loop_body; } else { goto loop_end; }`
470470
self.block(
@@ -475,11 +475,11 @@ impl CloneShimBuilder<'tcx> {
475475
}
476476

477477
fn make_usize(&self, value: u64) -> Box<Constant<'tcx>> {
478-
box Constant {
478+
Box::new(Constant {
479479
span: self.span,
480480
user_ty: None,
481481
literal: ty::Const::from_usize(self.tcx, value).into(),
482-
}
482+
})
483483
}
484484

485485
fn array_shim(
@@ -500,18 +500,18 @@ impl CloneShimBuilder<'tcx> {
500500
// `let end = len;`
501501
// `goto #1;`
502502
let inits = vec![
503-
self.make_statement(StatementKind::Assign(box (
503+
self.make_statement(StatementKind::Assign(Box::new((
504504
Place::from(beg),
505505
Rvalue::Use(Operand::Constant(self.make_usize(0))),
506-
))),
507-
self.make_statement(StatementKind::Assign(box (
506+
)))),
507+
self.make_statement(StatementKind::Assign(Box::new((
508508
end,
509-
Rvalue::Use(Operand::Constant(box Constant {
509+
Rvalue::Use(Operand::Constant(Box::new(Constant {
510510
span: self.span,
511511
user_ty: None,
512512
literal: len.into(),
513-
})),
514-
))),
513+
}))),
514+
)))),
515515
];
516516
self.block(inits, TerminatorKind::Goto { target: BasicBlock::new(1) }, false);
517517

@@ -532,13 +532,13 @@ impl CloneShimBuilder<'tcx> {
532532
// BB #3
533533
// `beg = beg + 1;`
534534
// `goto #1`;
535-
let statements = vec![self.make_statement(StatementKind::Assign(box (
535+
let statements = vec![self.make_statement(StatementKind::Assign(Box::new((
536536
Place::from(beg),
537537
Rvalue::BinaryOp(
538538
BinOp::Add,
539-
box (Operand::Copy(Place::from(beg)), Operand::Constant(self.make_usize(1))),
539+
Box::new((Operand::Copy(Place::from(beg)), Operand::Constant(self.make_usize(1)))),
540540
),
541-
)))];
541+
))))];
542542
self.block(statements, TerminatorKind::Goto { target: BasicBlock::new(1) }, false);
543543

544544
// BB #4
@@ -551,10 +551,10 @@ impl CloneShimBuilder<'tcx> {
551551
// goto #6;
552552
let end = beg;
553553
let beg = self.local_decls.push(LocalDecl::new(tcx.types.usize, span));
554-
let init = self.make_statement(StatementKind::Assign(box (
554+
let init = self.make_statement(StatementKind::Assign(Box::new((
555555
Place::from(beg),
556556
Rvalue::Use(Operand::Constant(self.make_usize(0))),
557-
)));
557+
))));
558558
self.block(vec![init], TerminatorKind::Goto { target: BasicBlock::new(6) }, true);
559559

560560
// BB #6 (cleanup): loop {
@@ -585,13 +585,13 @@ impl CloneShimBuilder<'tcx> {
585585
// BB #8 (cleanup)
586586
// `beg = beg + 1;`
587587
// `goto #6;`
588-
let statement = self.make_statement(StatementKind::Assign(box (
588+
let statement = self.make_statement(StatementKind::Assign(Box::new((
589589
Place::from(beg),
590590
Rvalue::BinaryOp(
591591
BinOp::Add,
592-
box (Operand::Copy(Place::from(beg)), Operand::Constant(self.make_usize(1))),
592+
Box::new((Operand::Copy(Place::from(beg)), Operand::Constant(self.make_usize(1)))),
593593
),
594-
)));
594+
))));
595595
self.block(vec![statement], TerminatorKind::Goto { target: BasicBlock::new(6) }, true);
596596

597597
// BB #9 (resume)
@@ -748,10 +748,10 @@ fn build_call_shim<'tcx>(
748748
let borrow_kind = BorrowKind::Mut { allow_two_phase_borrow: false };
749749
statements.push(Statement {
750750
source_info,
751-
kind: StatementKind::Assign(box (
751+
kind: StatementKind::Assign(Box::new((
752752
Place::from(ref_rcvr),
753753
Rvalue::Ref(tcx.lifetimes.re_erased, borrow_kind, rcvr_place()),
754-
)),
754+
))),
755755
});
756756
Operand::Move(Place::from(ref_rcvr))
757757
}
@@ -765,11 +765,11 @@ fn build_call_shim<'tcx>(
765765
CallKind::Direct(def_id) => {
766766
let ty = tcx.type_of(def_id);
767767
(
768-
Operand::Constant(box Constant {
768+
Operand::Constant(Box::new(Constant {
769769
span,
770770
user_ty: None,
771771
literal: ty::Const::zero_sized(tcx, ty).into(),
772-
}),
772+
})),
773773
rcvr.into_iter().collect::<Vec<_>>(),
774774
)
775775
}

compiler/rustc_mir/src/transform/add_retag.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl<'tcx> MirPass<'tcx> for AddRetag {
105105
0..0,
106106
places.map(|place| Statement {
107107
source_info,
108-
kind: StatementKind::Retag(RetagKind::FnEntry, box (place)),
108+
kind: StatementKind::Retag(RetagKind::FnEntry, Box::new(place)),
109109
}),
110110
);
111111
}
@@ -137,7 +137,7 @@ impl<'tcx> MirPass<'tcx> for AddRetag {
137137
0,
138138
Statement {
139139
source_info,
140-
kind: StatementKind::Retag(RetagKind::Default, box (dest_place)),
140+
kind: StatementKind::Retag(RetagKind::Default, Box::new(dest_place)),
141141
},
142142
);
143143
}
@@ -175,7 +175,10 @@ impl<'tcx> MirPass<'tcx> for AddRetag {
175175
let source_info = block_data.statements[i].source_info;
176176
block_data.statements.insert(
177177
i + 1,
178-
Statement { source_info, kind: StatementKind::Retag(retag_kind, box (place)) },
178+
Statement {
179+
source_info,
180+
kind: StatementKind::Retag(retag_kind, Box::new(place)),
181+
},
179182
);
180183
}
181184
}

compiler/rustc_mir/src/transform/coverage/graph.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -491,15 +491,19 @@ fn bcb_filtered_successors<'a, 'tcx>(
491491
term_kind: &'tcx TerminatorKind<'tcx>,
492492
) -> Box<dyn Iterator<Item = &'a BasicBlock> + 'a> {
493493
let mut successors = term_kind.successors();
494-
box match &term_kind {
495-
// SwitchInt successors are never unwind, and all of them should be traversed.
496-
TerminatorKind::SwitchInt { .. } => successors,
497-
// For all other kinds, return only the first successor, if any, and ignore unwinds.
498-
// NOTE: `chain(&[])` is required to coerce the `option::iter` (from
499-
// `next().into_iter()`) into the `mir::Successors` aliased type.
500-
_ => successors.next().into_iter().chain(&[]),
501-
}
502-
.filter(move |&&successor| body[successor].terminator().kind != TerminatorKind::Unreachable)
494+
Box::new(
495+
match &term_kind {
496+
// SwitchInt successors are never unwind, and all of them should be traversed.
497+
TerminatorKind::SwitchInt { .. } => successors,
498+
// For all other kinds, return only the first successor, if any, and ignore unwinds.
499+
// NOTE: `chain(&[])` is required to coerce the `option::iter` (from
500+
// `next().into_iter()`) into the `mir::Successors` aliased type.
501+
_ => successors.next().into_iter().chain(&[]),
502+
}
503+
.filter(move |&&successor| {
504+
body[successor].terminator().kind != TerminatorKind::Unreachable
505+
}),
506+
)
503507
}
504508

505509
/// Maintains separate worklists for each loop in the BasicCoverageBlock CFG, plus one for the

compiler/rustc_mir/src/transform/coverage/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,10 +478,10 @@ fn inject_statement(
478478
let source_info = data.terminator().source_info;
479479
let statement = Statement {
480480
source_info,
481-
kind: StatementKind::Coverage(box Coverage {
481+
kind: StatementKind::Coverage(Box::new(Coverage {
482482
kind: counter_kind,
483483
code_region: some_code_region,
484-
}),
484+
})),
485485
};
486486
data.statements.insert(0, statement);
487487
}
@@ -495,7 +495,7 @@ fn inject_intermediate_expression(mir_body: &mut mir::Body<'tcx>, expression: Co
495495
let source_info = data.terminator().source_info;
496496
let statement = Statement {
497497
source_info,
498-
kind: StatementKind::Coverage(box Coverage { kind: expression, code_region: None }),
498+
kind: StatementKind::Coverage(Box::new(Coverage { kind: expression, code_region: None })),
499499
};
500500
data.statements.push(statement);
501501
}

compiler/rustc_mir/src/transform/coverage/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ const TEMP_BLOCK: BasicBlock = BasicBlock::MAX;
4444

4545
fn dummy_ty() -> &'static TyS<'static> {
4646
thread_local! {
47-
static DUMMY_TYS: &'static TyS<'static> = Box::leak(box TyS::make_for_test(
47+
static DUMMY_TYS: &'static TyS<'static> = Box::leak(Box::new(TyS::make_for_test(
4848
ty::Bool,
4949
TypeFlags::empty(),
5050
DebruijnIndex::from_usize(0),
51-
));
51+
)));
5252
}
5353

5454
&DUMMY_TYS.with(|tys| *tys)

compiler/rustc_mir/src/transform/early_otherwise_branch.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {
9696
opt_to_apply.infos[0].first_switch_info.discr_used_in_switch;
9797
let not_equal_rvalue = Rvalue::BinaryOp(
9898
not_equal,
99-
box (
99+
Box::new((
100100
Operand::Copy(Place::from(second_discriminant_temp)),
101101
Operand::Copy(first_descriminant_place),
102-
),
102+
)),
103103
);
104104
patch.add_statement(
105105
end_of_block_location,
106-
StatementKind::Assign(box (Place::from(not_equal_temp), not_equal_rvalue)),
106+
StatementKind::Assign(Box::new((Place::from(not_equal_temp), not_equal_rvalue))),
107107
);
108108

109109
let new_targets = opt_to_apply

compiler/rustc_mir/src/transform/elaborate_drops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
409409
assert!(!data.is_cleanup, "DropAndReplace in unwind path not supported");
410410

411411
let assign = Statement {
412-
kind: StatementKind::Assign(box (place, Rvalue::Use(value.clone()))),
412+
kind: StatementKind::Assign(Box::new((place, Rvalue::Use(value.clone())))),
413413
source_info: terminator.source_info,
414414
};
415415

compiler/rustc_mir/src/transform/generator.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ impl TransformVisitor<'tcx> {
274274
Statement {
275275
source_info,
276276
kind: StatementKind::SetDiscriminant {
277-
place: box self_place,
277+
place: Box::new(self_place),
278278
variant_index: state_disc,
279279
},
280280
}
@@ -289,7 +289,7 @@ impl TransformVisitor<'tcx> {
289289
let self_place = Place::from(SELF_ARG);
290290
let assign = Statement {
291291
source_info: SourceInfo::outermost(body.span),
292-
kind: StatementKind::Assign(box (temp, Rvalue::Discriminant(self_place))),
292+
kind: StatementKind::Assign(Box::new((temp, Rvalue::Discriminant(self_place)))),
293293
};
294294
(assign, temp)
295295
}
@@ -954,7 +954,7 @@ fn create_generator_drop_shim<'tcx>(
954954
0,
955955
Statement {
956956
source_info,
957-
kind: StatementKind::Retag(RetagKind::Raw, box Place::from(SELF_ARG)),
957+
kind: StatementKind::Retag(RetagKind::Raw, Box::new(Place::from(SELF_ARG))),
958958
},
959959
)
960960
}
@@ -984,11 +984,11 @@ fn insert_panic_block<'tcx>(
984984
) -> BasicBlock {
985985
let assert_block = BasicBlock::new(body.basic_blocks().len());
986986
let term = TerminatorKind::Assert {
987-
cond: Operand::Constant(box Constant {
987+
cond: Operand::Constant(Box::new(Constant {
988988
span: body.span,
989989
user_ty: None,
990990
literal: ty::Const::from_bool(tcx, false).into(),
991-
}),
991+
})),
992992
expected: true,
993993
msg: message,
994994
target: assert_block,
@@ -1207,10 +1207,10 @@ fn create_cases<'tcx>(
12071207
let resume_arg = Local::new(2); // 0 = return, 1 = self
12081208
statements.push(Statement {
12091209
source_info,
1210-
kind: StatementKind::Assign(box (
1210+
kind: StatementKind::Assign(Box::new((
12111211
point.resume_arg,
12121212
Rvalue::Use(Operand::Move(resume_arg.into())),
1213-
)),
1213+
))),
12141214
});
12151215
}
12161216

@@ -1287,10 +1287,10 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
12871287
0,
12881288
Statement {
12891289
source_info,
1290-
kind: StatementKind::Assign(box (
1290+
kind: StatementKind::Assign(Box::new((
12911291
new_resume_local.into(),
12921292
Rvalue::Use(Operand::Move(resume_local.into())),
1293-
)),
1293+
))),
12941294
},
12951295
);
12961296

compiler/rustc_mir/src/transform/inline.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ impl Inliner<'tcx> {
520520
let temp = Place::from(self.new_call_temp(caller_body, &callsite, dest_ty));
521521
caller_body[callsite.block].statements.push(Statement {
522522
source_info: callsite.source_info,
523-
kind: StatementKind::Assign(box (temp, dest)),
523+
kind: StatementKind::Assign(Box::new((temp, dest))),
524524
});
525525
self.tcx.mk_place_deref(temp)
526526
} else {
@@ -729,7 +729,7 @@ impl Inliner<'tcx> {
729729
let local = self.new_call_temp(caller_body, callsite, arg_ty);
730730
caller_body[callsite.block].statements.push(Statement {
731731
source_info: callsite.source_info,
732-
kind: StatementKind::Assign(box (Place::from(local), Rvalue::Use(arg))),
732+
kind: StatementKind::Assign(Box::new((Place::from(local), Rvalue::Use(arg)))),
733733
});
734734
local
735735
}

compiler/rustc_mir/src/transform/instcombine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl<'tcx, 'a> InstCombineContext<'tcx, 'a> {
124124

125125
let constant =
126126
Constant { span: source_info.span, literal: len.into(), user_ty: None };
127-
*rvalue = Rvalue::Use(Operand::Constant(box constant));
127+
*rvalue = Rvalue::Use(Operand::Constant(Box::new(constant)));
128128
}
129129
}
130130
}

0 commit comments

Comments
 (0)