Skip to content

Commit aef4577

Browse files
committed
Auto merge of rust-lang#89030 - nbdd0121:box2, r=jonas-schievink
Introduce `Rvalue::ShallowInitBox` Polished version of rust-lang#88700. Implements MCP rust-lang/compiler-team#460, and should allow rust-lang#43596 to go forward. In short, creating an empty box is split from a nullary-op `NullOp::Box` into two steps, first a call to `exchange_malloc`, then a `Rvalue::ShallowInitBox` which transmutes `*mut u8` to a shallow-initialized `Box<T>`. This allows the `exchange_malloc` call to unwind. Details can be found in the MCP. `NullOp::Box` is not yet removed, purely to make reverting easier in case anything goes wrong as the result of this PR. If revert is needed a reversion of "Use Rvalue::ShallowInitBox for box expression" commit followed by a test bless should be sufficient. Experiments in rust-lang#88700 showed a very slight compile-time perf regression due to (supposedly) slightly more time spent in LLVM. We could omit unwind edge generation (in non-`oom=panic` case) in box expression MIR construction to restore perf; but I don't think it's necessary since runtime perf isn't affected and perf difference is rather small.
2 parents e0b68ae + fc8edf1 commit aef4577

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

clippy_utils/src/qualify_min_const_fn.rs

+1
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ fn check_rvalue(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId, rvalue: &Rv
194194
},
195195
Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, _) => Ok(()),
196196
Rvalue::NullaryOp(NullOp::Box, _) => Err((span, "heap allocations are not allowed in const fn".into())),
197+
Rvalue::ShallowInitBox(_, _) => Ok(()),
197198
Rvalue::UnaryOp(_, operand) => {
198199
let ty = operand.ty(body, tcx);
199200
if ty.is_integral() || ty.is_bool() {

0 commit comments

Comments
 (0)