Skip to content

Commit 4a293a3

Browse files
nikomatsakisKiChjang
authored andcommitted
avoid infinite loop in MIR lowering
1 parent fba9d14 commit 4a293a3

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/librustc_mir/build/expr/into.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,11 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
345345
}
346346

347347
// Avoid creating a temporary
348-
ExprKind::VarRef { .. } | ExprKind::SelfRef | ExprKind::StaticRef { .. } => {
348+
ExprKind::VarRef { .. } |
349+
ExprKind::SelfRef |
350+
ExprKind::StaticRef { .. } |
351+
ExprKind::PlaceTypeAscription { .. } |
352+
ExprKind::ValueTypeAscription { .. } => {
349353
debug_assert!(Category::of(&expr.kind) == Some(Category::Place));
350354

351355
let place = unpack!(block = this.as_place(block, expr));
@@ -391,11 +395,16 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
391395
| ExprKind::Adt { .. }
392396
| ExprKind::Closure { .. }
393397
| ExprKind::Literal { .. }
394-
| ExprKind::Yield { .. }
395-
| ExprKind::PlaceTypeAscription { .. }
396-
| ExprKind::ValueTypeAscription { .. } => {
398+
| ExprKind::Yield { .. } => {
397399
debug_assert!(match Category::of(&expr.kind).unwrap() {
400+
// should be handled above
398401
Category::Rvalue(RvalueFunc::Into) => false,
402+
403+
// must be handled above or else we get an
404+
// infinite loop in the builder; see
405+
// e.g. `ExprKind::VarRef` above
406+
Category::Place => false,
407+
399408
_ => true,
400409
});
401410

0 commit comments

Comments
 (0)