diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index 9579fe1f405..71c2e3bf060 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -835,7 +835,11 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { if self.keep_original { rhs.clone() } else { - let unit = Rvalue::Aggregate(box AggregateKind::Tuple, vec![]); + let unit = Rvalue::Use(Operand::Constant(box Constant { + span: statement.source_info.span, + user_ty: None, + literal: ty::Const::zero_sized(self.tcx, self.tcx.types.unit), + })); mem::replace(rhs, unit) }, statement.source_info, diff --git a/src/librustc_mir_build/build/block.rs b/src/librustc_mir_build/build/block.rs index 8c41554bc85..4e8d5e04a63 100644 --- a/src/librustc_mir_build/build/block.rs +++ b/src/librustc_mir_build/build/block.rs @@ -187,7 +187,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { if destination_ty.is_unit() { // We only want to assign an implicit `()` as the return value of the block if the // block does not diverge. (Otherwise, we may try to assign a unit to a `!`-type.) - this.cfg.push_assign_unit(block, source_info, destination); + this.cfg.push_assign_unit(block, source_info, destination, this.hir.tcx()); } } // Finally, we pop all the let scopes before exiting out from the scope of block diff --git a/src/librustc_mir_build/build/cfg.rs b/src/librustc_mir_build/build/cfg.rs index f5828c4ac1f..42e2b242d77 100644 --- a/src/librustc_mir_build/build/cfg.rs +++ b/src/librustc_mir_build/build/cfg.rs @@ -2,6 +2,7 @@ use crate::build::CFG; use rustc_middle::mir::*; +use rustc_middle::ty::{self, TyCtxt}; impl<'tcx> CFG<'tcx> { crate fn block_data(&self, blk: BasicBlock) -> &BasicBlockData<'tcx> { @@ -58,12 +59,17 @@ impl<'tcx> CFG<'tcx> { block: BasicBlock, source_info: SourceInfo, place: Place<'tcx>, + tcx: TyCtxt<'tcx>, ) { self.push_assign( block, source_info, place, - Rvalue::Aggregate(box AggregateKind::Tuple, vec![]), + Rvalue::Use(Operand::Constant(box Constant { + span: source_info.span, + user_ty: None, + literal: ty::Const::zero_sized(tcx, tcx.types.unit), + })), ); } diff --git a/src/librustc_mir_build/build/expr/as_rvalue.rs b/src/librustc_mir_build/build/expr/as_rvalue.rs index 20ef763e90c..b6f46aab416 100644 --- a/src/librustc_mir_build/build/expr/as_rvalue.rs +++ b/src/librustc_mir_build/build/expr/as_rvalue.rs @@ -225,7 +225,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } ExprKind::Assign { .. } | ExprKind::AssignOp { .. } => { block = unpack!(this.stmt_expr(block, expr, None)); - block.and(this.unit_rvalue()) + block.and(Rvalue::Use(Operand::Constant(box Constant { + span: expr_span, + user_ty: None, + literal: ty::Const::zero_sized(this.hir.tcx(), this.hir.tcx().types.unit), + }))) } ExprKind::Yield { .. } | ExprKind::Literal { .. } diff --git a/src/librustc_mir_build/build/expr/into.rs b/src/librustc_mir_build/build/expr/into.rs index 6b93755e9da..cd5bb738aed 100644 --- a/src/librustc_mir_build/build/expr/into.rs +++ b/src/librustc_mir_build/build/expr/into.rs @@ -331,7 +331,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { | ExprKind::LlvmInlineAsm { .. } | ExprKind::Return { .. } => { unpack!(block = this.stmt_expr(block, expr, None)); - this.cfg.push_assign_unit(block, source_info, destination); + this.cfg.push_assign_unit(block, source_info, destination, this.hir.tcx()); block.unit() } diff --git a/src/librustc_mir_build/build/misc.rs b/src/librustc_mir_build/build/misc.rs index 8f98dd9b70e..578b862b905 100644 --- a/src/librustc_mir_build/build/misc.rs +++ b/src/librustc_mir_build/build/misc.rs @@ -32,10 +32,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { Operand::Constant(constant) } - crate fn unit_rvalue(&mut self) -> Rvalue<'tcx> { - Rvalue::Aggregate(box AggregateKind::Tuple, vec![]) - } - // Returns a zero literal operand for the appropriate type, works for // bool, char and integers. crate fn zero_literal(&mut self, span: Span, ty: Ty<'tcx>) -> Operand<'tcx> { diff --git a/src/librustc_mir_build/build/scope.rs b/src/librustc_mir_build/build/scope.rs index 3689e5cb9d8..d88cbf94513 100644 --- a/src/librustc_mir_build/build/scope.rs +++ b/src/librustc_mir_build/build/scope.rs @@ -523,7 +523,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { unpack!(block = self.into(destination, block, value)); self.block_context.pop(); } else { - self.cfg.push_assign_unit(block, source_info, destination) + self.cfg.push_assign_unit(block, source_info, destination, self.hir.tcx()) } } else { assert!(value.is_none(), "`return` and `break` should have a destination");