Fix translation of Assign/AssignOp as rvalues

In code like `let x = y = z;`, `y = z` goes through `as_rvalue`, which
didn't handle it. Now it translates the assignment and produces `()`
directly.
This commit is contained in:
James Miller 2016-04-16 19:45:28 +12:00
parent 869172305f
commit 89edd96be8
2 changed files with 9 additions and 2 deletions

View File

@ -189,6 +189,11 @@ impl<'a,'tcx> Builder<'a,'tcx> {
block.and(Rvalue::Aggregate(AggregateKind::Adt(adt_def, variant_index, substs),
fields))
}
ExprKind::Assign { .. } |
ExprKind::AssignOp { .. } => {
block = unpack!(this.stmt_expr(block, expr));
block.and(this.unit_rvalue())
}
ExprKind::Literal { .. } |
ExprKind::Block { .. } |
ExprKind::Match { .. } |
@ -201,8 +206,6 @@ impl<'a,'tcx> Builder<'a,'tcx> {
ExprKind::Index { .. } |
ExprKind::VarRef { .. } |
ExprKind::SelfRef |
ExprKind::Assign { .. } |
ExprKind::AssignOp { .. } |
ExprKind::Break { .. } |
ExprKind::Continue { .. } |
ExprKind::Return { .. } |

View File

@ -46,6 +46,10 @@ impl<'a,'tcx> Builder<'a,'tcx> {
Operand::Constant(constant)
}
pub fn unit_rvalue(&mut self) -> Rvalue<'tcx> {
Rvalue::Aggregate(AggregateKind::Tuple, vec![])
}
pub fn push_usize(&mut self,
block: BasicBlock,
scope_id: ScopeId,