diff options
| author | James Miller <james@aatch.net> | 2016-04-16 19:45:28 +1200 |
|---|---|---|
| committer | James Miller <james@aatch.net> | 2016-04-28 13:18:51 +1200 |
| commit | 89edd96be86fd65d63f63a208062c8baf86e7d7c (patch) | |
| tree | a61f2553ec431a3d3b594d98ae95c9828b32eee5 | |
| parent | 869172305f66ba11565c90f9276328c479d5b082 (diff) | |
| download | rust-89edd96be86fd65d63f63a208062c8baf86e7d7c.tar.gz rust-89edd96be86fd65d63f63a208062c8baf86e7d7c.zip | |
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.
| -rw-r--r-- | src/librustc_mir/build/expr/as_rvalue.rs | 7 | ||||
| -rw-r--r-- | src/librustc_mir/build/misc.rs | 4 |
2 files changed, 9 insertions, 2 deletions
diff --git a/src/librustc_mir/build/expr/as_rvalue.rs b/src/librustc_mir/build/expr/as_rvalue.rs index b340d933e64..8992381135e 100644 --- a/src/librustc_mir/build/expr/as_rvalue.rs +++ b/src/librustc_mir/build/expr/as_rvalue.rs @@ -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 { .. } | diff --git a/src/librustc_mir/build/misc.rs b/src/librustc_mir/build/misc.rs index 86f15a63193..5daaf37d878 100644 --- a/src/librustc_mir/build/misc.rs +++ b/src/librustc_mir/build/misc.rs @@ -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, |
