unit rvalue: use constant ()
instead of tuple
This commit is contained in:
parent
c58c532744
commit
db83fdc46c
@ -835,7 +835,11 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
|
|||||||
if self.keep_original {
|
if self.keep_original {
|
||||||
rhs.clone()
|
rhs.clone()
|
||||||
} else {
|
} 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)
|
mem::replace(rhs, unit)
|
||||||
},
|
},
|
||||||
statement.source_info,
|
statement.source_info,
|
||||||
|
@ -187,7 +187,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
if destination_ty.is_unit() {
|
if destination_ty.is_unit() {
|
||||||
// We only want to assign an implicit `()` as the return value of the block if the
|
// 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.)
|
// 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
|
// Finally, we pop all the let scopes before exiting out from the scope of block
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use crate::build::CFG;
|
use crate::build::CFG;
|
||||||
use rustc_middle::mir::*;
|
use rustc_middle::mir::*;
|
||||||
|
use rustc_middle::ty::{self, TyCtxt};
|
||||||
|
|
||||||
impl<'tcx> CFG<'tcx> {
|
impl<'tcx> CFG<'tcx> {
|
||||||
crate fn block_data(&self, blk: BasicBlock) -> &BasicBlockData<'tcx> {
|
crate fn block_data(&self, blk: BasicBlock) -> &BasicBlockData<'tcx> {
|
||||||
@ -58,12 +59,17 @@ impl<'tcx> CFG<'tcx> {
|
|||||||
block: BasicBlock,
|
block: BasicBlock,
|
||||||
source_info: SourceInfo,
|
source_info: SourceInfo,
|
||||||
place: Place<'tcx>,
|
place: Place<'tcx>,
|
||||||
|
tcx: TyCtxt<'tcx>,
|
||||||
) {
|
) {
|
||||||
self.push_assign(
|
self.push_assign(
|
||||||
block,
|
block,
|
||||||
source_info,
|
source_info,
|
||||||
place,
|
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),
|
||||||
|
})),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,7 +225,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
ExprKind::Assign { .. } | ExprKind::AssignOp { .. } => {
|
ExprKind::Assign { .. } | ExprKind::AssignOp { .. } => {
|
||||||
block = unpack!(this.stmt_expr(block, expr, None));
|
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::Yield { .. }
|
||||||
| ExprKind::Literal { .. }
|
| ExprKind::Literal { .. }
|
||||||
|
@ -331,7 +331,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
| ExprKind::LlvmInlineAsm { .. }
|
| ExprKind::LlvmInlineAsm { .. }
|
||||||
| ExprKind::Return { .. } => {
|
| ExprKind::Return { .. } => {
|
||||||
unpack!(block = this.stmt_expr(block, expr, None));
|
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()
|
block.unit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,10 +32,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
Operand::Constant(constant)
|
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
|
// Returns a zero literal operand for the appropriate type, works for
|
||||||
// bool, char and integers.
|
// bool, char and integers.
|
||||||
crate fn zero_literal(&mut self, span: Span, ty: Ty<'tcx>) -> Operand<'tcx> {
|
crate fn zero_literal(&mut self, span: Span, ty: Ty<'tcx>) -> Operand<'tcx> {
|
||||||
|
@ -523,7 +523,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
unpack!(block = self.into(destination, block, value));
|
unpack!(block = self.into(destination, block, value));
|
||||||
self.block_context.pop();
|
self.block_context.pop();
|
||||||
} else {
|
} else {
|
||||||
self.cfg.push_assign_unit(block, source_info, destination)
|
self.cfg.push_assign_unit(block, source_info, destination, self.hir.tcx())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
assert!(value.is_none(), "`return` and `break` should have a destination");
|
assert!(value.is_none(), "`return` and `break` should have a destination");
|
||||||
|
Loading…
Reference in New Issue
Block a user