Skip to content

Commit 89edd96

Browse files
committed
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.
1 parent 8691723 commit 89edd96

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/librustc_mir/build/expr/as_rvalue.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ impl<'a,'tcx> Builder<'a,'tcx> {
189189
block.and(Rvalue::Aggregate(AggregateKind::Adt(adt_def, variant_index, substs),
190190
fields))
191191
}
192+
ExprKind::Assign { .. } |
193+
ExprKind::AssignOp { .. } => {
194+
block = unpack!(this.stmt_expr(block, expr));
195+
block.and(this.unit_rvalue())
196+
}
192197
ExprKind::Literal { .. } |
193198
ExprKind::Block { .. } |
194199
ExprKind::Match { .. } |
@@ -201,8 +206,6 @@ impl<'a,'tcx> Builder<'a,'tcx> {
201206
ExprKind::Index { .. } |
202207
ExprKind::VarRef { .. } |
203208
ExprKind::SelfRef |
204-
ExprKind::Assign { .. } |
205-
ExprKind::AssignOp { .. } |
206209
ExprKind::Break { .. } |
207210
ExprKind::Continue { .. } |
208211
ExprKind::Return { .. } |

src/librustc_mir/build/misc.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ impl<'a,'tcx> Builder<'a,'tcx> {
4646
Operand::Constant(constant)
4747
}
4848

49+
pub fn unit_rvalue(&mut self) -> Rvalue<'tcx> {
50+
Rvalue::Aggregate(AggregateKind::Tuple, vec![])
51+
}
52+
4953
pub fn push_usize(&mut self,
5054
block: BasicBlock,
5155
scope_id: ScopeId,

0 commit comments

Comments
 (0)