Skip to content

Commit d4e488f

Browse files
Auto merge of #147862 - cjgillot:noinit-box, r=<try>
Remove `box_new` intrinsic
2 parents 6380899 + acd0187 commit d4e488f

File tree

73 files changed

+861
-1248
lines changed

Some content is hidden

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

73 files changed

+861
-1248
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,8 +1533,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
15331533
Rvalue::Use(operand)
15341534
| Rvalue::Repeat(operand, _)
15351535
| Rvalue::UnaryOp(_ /*un_op*/, operand)
1536-
| Rvalue::Cast(_ /*cast_kind*/, operand, _ /*ty*/)
1537-
| Rvalue::ShallowInitBox(operand, _ /*ty*/) => {
1536+
| Rvalue::Cast(_ /*cast_kind*/, operand, _ /*ty*/) => {
15381537
self.consume_operand(location, (operand, span), state)
15391538
}
15401539

compiler/rustc_borrowck/src/polonius/legacy/loan_invalidations.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,9 @@ impl<'a, 'tcx> LoanInvalidationsGenerator<'a, 'tcx> {
297297
Rvalue::Use(operand)
298298
| Rvalue::Repeat(operand, _)
299299
| Rvalue::UnaryOp(_ /*un_op*/, operand)
300-
| Rvalue::Cast(_ /*cast_kind*/, operand, _ /*ty*/)
301-
| Rvalue::ShallowInitBox(operand, _ /*ty*/) => self.consume_operand(location, operand),
300+
| Rvalue::Cast(_ /*cast_kind*/, operand, _ /*ty*/) => {
301+
self.consume_operand(location, operand)
302+
}
302303

303304
&Rvalue::Discriminant(place) => {
304305
self.access_place(

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,17 +1059,6 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
10591059
&Rvalue::NullaryOp(NullOp::ContractChecks, _) => {}
10601060
&Rvalue::NullaryOp(NullOp::UbChecks, _) => {}
10611061

1062-
Rvalue::ShallowInitBox(_operand, ty) => {
1063-
let trait_ref =
1064-
ty::TraitRef::new(tcx, tcx.require_lang_item(LangItem::Sized, span), [*ty]);
1065-
1066-
self.prove_trait_ref(
1067-
trait_ref,
1068-
location.to_locations(),
1069-
ConstraintCategory::SizedBound,
1070-
);
1071-
}
1072-
10731062
Rvalue::Cast(cast_kind, op, ty) => {
10741063
match *cast_kind {
10751064
CastKind::PointerCoercion(PointerCoercion::ReifyFnPointer, coercion_source) => {
@@ -2211,7 +2200,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
22112200
| Rvalue::Ref(..)
22122201
| Rvalue::RawPtr(..)
22132202
| Rvalue::Cast(..)
2214-
| Rvalue::ShallowInitBox(..)
22152203
| Rvalue::BinaryOp(..)
22162204
| Rvalue::NullaryOp(..)
22172205
| Rvalue::CopyForDeref(..)

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -829,13 +829,6 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
829829
fx.bcx.ins().nop();
830830
}
831831
}
832-
Rvalue::ShallowInitBox(ref operand, content_ty) => {
833-
let content_ty = fx.monomorphize(content_ty);
834-
let box_layout = fx.layout_of(Ty::new_box(fx.tcx, content_ty));
835-
let operand = codegen_operand(fx, operand);
836-
let operand = operand.load_scalar(fx);
837-
lval.write_cvalue(fx, CValue::by_val(operand, box_layout));
838-
}
839832
Rvalue::NullaryOp(ref null_op, ty) => {
840833
assert!(lval.layout().ty.is_sized(fx.tcx, fx.typing_env()));
841834
let layout = fx.layout_of(fx.monomorphize(ty));

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -724,15 +724,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
724724
}
725725
}
726726
}
727-
mir::Rvalue::ShallowInitBox(ref operand, content_ty) => {
728-
let operand = self.codegen_operand(bx, operand);
729-
let val = operand.immediate();
730-
731-
let content_ty = self.monomorphize(content_ty);
732-
let box_layout = bx.cx().layout_of(Ty::new_box(bx.tcx(), content_ty));
733-
734-
OperandRef { val: OperandValue::Immediate(val), layout: box_layout }
735-
}
736727
mir::Rvalue::WrapUnsafeBinder(ref operand, binder_ty) => {
737728
let operand = self.codegen_operand(bx, operand);
738729
let binder_ty = self.monomorphize(binder_ty);

compiler/rustc_const_eval/src/check_consts/check.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
653653
| NullOp::ContractChecks,
654654
_,
655655
) => {}
656-
Rvalue::ShallowInitBox(_, _) => {}
657656

658657
Rvalue::UnaryOp(op, operand) => {
659658
let ty = operand.ty(self.body, self.tcx);
@@ -853,7 +852,9 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
853852
}
854853

855854
// This can be called on stable via the `vec!` macro.
856-
if tcx.is_lang_item(callee, LangItem::ExchangeMalloc) {
855+
if tcx.is_lang_item(callee, LangItem::ExchangeMalloc)
856+
|| tcx.is_diagnostic_item(sym::box_new, callee)
857+
{
857858
self.check_op(ops::HeapAllocation);
858859
// Allow this call, skip all the checks below.
859860
return;

compiler/rustc_const_eval/src/check_consts/qualifs.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,7 @@ where
239239
Rvalue::Use(operand)
240240
| Rvalue::Repeat(operand, _)
241241
| Rvalue::UnaryOp(_, operand)
242-
| Rvalue::Cast(_, operand, _)
243-
| Rvalue::ShallowInitBox(operand, _) => in_operand::<Q, _>(cx, in_local, operand),
242+
| Rvalue::Cast(_, operand, _) => in_operand::<Q, _>(cx, in_local, operand),
244243

245244
Rvalue::BinaryOp(_, box (lhs, rhs)) => {
246245
in_operand::<Q, _>(cx, in_local, lhs) || in_operand::<Q, _>(cx, in_local, rhs)

compiler/rustc_const_eval/src/check_consts/resolver.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ where
192192
}
193193

194194
mir::Rvalue::Cast(..)
195-
| mir::Rvalue::ShallowInitBox(..)
196195
| mir::Rvalue::Use(..)
197196
| mir::Rvalue::CopyForDeref(..)
198197
| mir::Rvalue::ThreadLocalRef(..)

compiler/rustc_const_eval/src/interpret/step.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,6 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
255255
self.write_immediate(*val, &dest)?;
256256
}
257257

258-
ShallowInitBox(ref operand, _) => {
259-
let src = self.eval_operand(operand, None)?;
260-
let v = self.read_immediate(&src)?;
261-
self.write_immediate(*v, &dest)?;
262-
}
263-
264258
Cast(cast_kind, ref operand, cast_ty) => {
265259
let src = self.eval_operand(operand, None)?;
266260
let cast_ty =

compiler/rustc_middle/src/mir/pretty.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,10 +1239,6 @@ impl<'tcx> Debug for Rvalue<'tcx> {
12391239
}
12401240
}
12411241

1242-
ShallowInitBox(ref place, ref ty) => {
1243-
with_no_trimmed_paths!(write!(fmt, "ShallowInitBox({place:?}, {ty})"))
1244-
}
1245-
12461242
WrapUnsafeBinder(ref op, ty) => {
12471243
with_no_trimmed_paths!(write!(fmt, "wrap_binder!({op:?}; {ty})"))
12481244
}

0 commit comments

Comments
 (0)