Skip to content

Commit ddabe07

Browse files
committed
Auto merge of #92518 - matthiaskrgr:rollup-fl8z4e7, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #90102 (Remove `NullOp::Box`) - #92011 (Use field span in `rustc_macros` when emitting decode call) - #92402 (Suggest while let x = y when encountering while x = y) - #92409 (Couple of libtest cleanups) - #92418 (Fix spacing in pretty printed PatKind::Struct with no fields) - #92444 (Consolidate Result's and Option's methods into fewer impl blocks) Failed merges: - #92483 (Stabilize `result_cloned` and `result_copied`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents b5efe57 + 13e2840 commit ddabe07

File tree

31 files changed

+628
-665
lines changed

31 files changed

+628
-665
lines changed

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2461,7 +2461,11 @@ impl<'a> State<'a> {
24612461
self.print_path(path, true, 0);
24622462
}
24632463
self.nbsp();
2464-
self.word_space("{");
2464+
self.word("{");
2465+
let empty = fields.is_empty() && !etc;
2466+
if !empty {
2467+
self.space();
2468+
}
24652469
self.commasep_cmnt(
24662470
Consistent,
24672471
&fields,
@@ -2482,7 +2486,9 @@ impl<'a> State<'a> {
24822486
}
24832487
self.word("..");
24842488
}
2485-
self.space();
2489+
if !empty {
2490+
self.space();
2491+
}
24862492
self.word("}");
24872493
}
24882494
PatKind::Tuple(ref elts) => {

compiler/rustc_borrowck/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,10 +1394,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13941394

13951395
Rvalue::NullaryOp(_op, _ty) => {
13961396
// nullary ops take no dynamic input; no borrowck effect.
1397-
//
1398-
// FIXME: is above actually true? Do we want to track
1399-
// the fact that uninitialized data can be created via
1400-
// `NullOp::Box`?
14011397
}
14021398

14031399
Rvalue::Aggregate(ref aggregate_kind, ref operands) => {

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -715,30 +715,6 @@ fn codegen_stmt<'tcx>(
715715
let operand = operand.load_scalar(fx);
716716
lval.write_cvalue(fx, CValue::by_val(operand, box_layout));
717717
}
718-
Rvalue::NullaryOp(NullOp::Box, content_ty) => {
719-
let usize_type = fx.clif_type(fx.tcx.types.usize).unwrap();
720-
let content_ty = fx.monomorphize(content_ty);
721-
let layout = fx.layout_of(content_ty);
722-
let llsize = fx.bcx.ins().iconst(usize_type, layout.size.bytes() as i64);
723-
let llalign = fx.bcx.ins().iconst(usize_type, layout.align.abi.bytes() as i64);
724-
let box_layout = fx.layout_of(fx.tcx.mk_box(content_ty));
725-
726-
// Allocate space:
727-
let def_id =
728-
match fx.tcx.lang_items().require(rustc_hir::LangItem::ExchangeMalloc) {
729-
Ok(id) => id,
730-
Err(s) => {
731-
fx.tcx
732-
.sess
733-
.fatal(&format!("allocation of `{}` {}", box_layout.ty, s));
734-
}
735-
};
736-
let instance = ty::Instance::mono(fx.tcx, def_id).polymorphize(fx.tcx);
737-
let func_ref = fx.get_function_ref(instance);
738-
let call = fx.bcx.ins().call(func_ref, &[llsize, llalign]);
739-
let ptr = fx.bcx.inst_results(call)[0];
740-
lval.write_cvalue(fx, CValue::by_val(ptr, box_layout));
741-
}
742718
Rvalue::NullaryOp(null_op, ty) => {
743719
assert!(
744720
lval.layout()
@@ -749,7 +725,6 @@ fn codegen_stmt<'tcx>(
749725
let val = match null_op {
750726
NullOp::SizeOf => layout.size.bytes(),
751727
NullOp::AlignOf => layout.align.abi.bytes(),
752-
NullOp::Box => unreachable!(),
753728
};
754729
let val = CValue::const_val(fx, fx.layout_of(fx.tcx.types.usize), val.into());
755730
lval.write_cvalue(fx, val);

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::traits::*;
88
use crate::MemFlags;
99

1010
use rustc_apfloat::{ieee, Float, Round, Status};
11-
use rustc_hir::lang_items::LangItem;
1211
use rustc_middle::mir;
1312
use rustc_middle::ty::cast::{CastTy, IntTy};
1413
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf};
@@ -486,39 +485,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
486485
)
487486
}
488487

489-
mir::Rvalue::NullaryOp(mir::NullOp::Box, content_ty) => {
490-
let content_ty = self.monomorphize(content_ty);
491-
let content_layout = bx.cx().layout_of(content_ty);
492-
let llsize = bx.cx().const_usize(content_layout.size.bytes());
493-
let llalign = bx.cx().const_usize(content_layout.align.abi.bytes());
494-
let box_layout = bx.cx().layout_of(bx.tcx().mk_box(content_ty));
495-
let llty_ptr = bx.cx().backend_type(box_layout);
496-
497-
// Allocate space:
498-
let def_id = match bx.tcx().lang_items().require(LangItem::ExchangeMalloc) {
499-
Ok(id) => id,
500-
Err(s) => {
501-
bx.cx().sess().fatal(&format!("allocation of `{}` {}", box_layout.ty, s));
502-
}
503-
};
504-
let instance = ty::Instance::mono(bx.tcx(), def_id);
505-
let r = bx.cx().get_fn_addr(instance);
506-
let ty = bx.type_func(&[bx.type_isize(), bx.type_isize()], bx.type_i8p());
507-
let call = bx.call(ty, r, &[llsize, llalign], None);
508-
let val = bx.pointercast(call, llty_ptr);
509-
510-
let operand = OperandRef { val: OperandValue::Immediate(val), layout: box_layout };
511-
(bx, operand)
512-
}
513-
514488
mir::Rvalue::NullaryOp(null_op, ty) => {
515489
let ty = self.monomorphize(ty);
516490
assert!(bx.cx().type_is_sized(ty));
517491
let layout = bx.cx().layout_of(ty);
518492
let val = match null_op {
519493
mir::NullOp::SizeOf => layout.size.bytes(),
520494
mir::NullOp::AlignOf => layout.align.abi.bytes(),
521-
mir::NullOp::Box => unreachable!(),
522495
};
523496
let val = bx.cx().const_usize(val);
524497
let tcx = self.cx.tcx();

compiler/rustc_const_eval/src/const_eval/machine.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -398,13 +398,6 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
398398
Err(ConstEvalErrKind::NeedsRfc("pointer arithmetic or comparison".to_string()).into())
399399
}
400400

401-
fn box_alloc(
402-
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
403-
_dest: &PlaceTy<'tcx>,
404-
) -> InterpResult<'tcx> {
405-
Err(ConstEvalErrKind::NeedsRfc("heap allocations via `box` keyword".to_string()).into())
406-
}
407-
408401
fn before_terminator(ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> {
409402
// The step limit has already been hit in a previous call to `before_terminator`.
410403
if ecx.machine.steps_remaining == 0 {

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ pub enum StackPopCleanup {
156156
/// `ret` stores the block we jump to on a normal return, while `unwind`
157157
/// stores the block used for cleanup during unwinding.
158158
Goto { ret: Option<mir::BasicBlock>, unwind: StackPopUnwind },
159-
/// Just do nothing: Used by Main and for the `box_alloc` hook in miri.
159+
/// Just do nothing: Used by Main and for TLS hooks in miri.
160160
/// `cleanup` says whether locals are deallocated. Static computation
161161
/// wants them leaked to intern what they need (and just throw away
162162
/// the entire `ecx` when it is done).

compiler/rustc_const_eval/src/interpret/machine.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,6 @@ pub trait Machine<'mir, 'tcx>: Sized {
212212
right: &ImmTy<'tcx, Self::PointerTag>,
213213
) -> InterpResult<'tcx, (Scalar<Self::PointerTag>, bool, Ty<'tcx>)>;
214214

215-
/// Heap allocations via the `box` keyword.
216-
fn box_alloc(
217-
ecx: &mut InterpCx<'mir, 'tcx, Self>,
218-
dest: &PlaceTy<'tcx, Self::PointerTag>,
219-
) -> InterpResult<'tcx>;
220-
221215
/// Called to read the specified `local` from the `frame`.
222216
/// Since reading a ZST is not actually accessing memory or locals, this is never invoked
223217
/// for ZST reads.

compiler/rustc_const_eval/src/interpret/step.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
271271
self.write_immediate(place.to_ref(self), &dest)?;
272272
}
273273

274-
NullaryOp(mir::NullOp::Box, _) => {
275-
M::box_alloc(self, &dest)?;
276-
}
277-
278274
NullaryOp(null_op, ty) => {
279275
let ty = self.subst_from_current_frame_and_normalize_erasing_regions(ty)?;
280276
let layout = self.layout_of(ty)?;
@@ -289,7 +285,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
289285
let val = match null_op {
290286
mir::NullOp::SizeOf => layout.size.bytes(),
291287
mir::NullOp::AlignOf => layout.align.abi.bytes(),
292-
mir::NullOp::Box => unreachable!(),
293288
};
294289
self.write_scalar(Scalar::from_machine_usize(val, self), &dest)?;
295290
}

compiler/rustc_const_eval/src/transform/check_consts/check.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
632632
}
633633

634634
Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, _) => {}
635-
Rvalue::NullaryOp(NullOp::Box, _) => self.check_op(ops::HeapAllocation),
636635
Rvalue::ShallowInitBox(_, _) => {}
637636

638637
Rvalue::UnaryOp(_, ref operand) => {

compiler/rustc_const_eval/src/transform/promote_consts.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,6 @@ impl<'tcx> Validator<'_, 'tcx> {
508508
}
509509

510510
Rvalue::NullaryOp(op, _) => match op {
511-
NullOp::Box => return Err(Unpromotable),
512511
NullOp::SizeOf => {}
513512
NullOp::AlignOf => {}
514513
},

0 commit comments

Comments
 (0)