From 4a293a3990a0c1bf170d31d1d9bcbc79cef8a5b8 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 24 Sep 2018 17:53:28 -0400 Subject: [PATCH] avoid infinite loop in MIR lowering --- src/librustc_mir/build/expr/into.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/librustc_mir/build/expr/into.rs b/src/librustc_mir/build/expr/into.rs index c05719ce95a..9ea3805fdc6 100644 --- a/src/librustc_mir/build/expr/into.rs +++ b/src/librustc_mir/build/expr/into.rs @@ -345,7 +345,11 @@ pub fn into_expr( } // Avoid creating a temporary - ExprKind::VarRef { .. } | ExprKind::SelfRef | ExprKind::StaticRef { .. } => { + ExprKind::VarRef { .. } | + ExprKind::SelfRef | + ExprKind::StaticRef { .. } | + ExprKind::PlaceTypeAscription { .. } | + ExprKind::ValueTypeAscription { .. } => { debug_assert!(Category::of(&expr.kind) == Some(Category::Place)); let place = unpack!(block = this.as_place(block, expr)); @@ -391,11 +395,16 @@ pub fn into_expr( | ExprKind::Adt { .. } | ExprKind::Closure { .. } | ExprKind::Literal { .. } - | ExprKind::Yield { .. } - | ExprKind::PlaceTypeAscription { .. } - | ExprKind::ValueTypeAscription { .. } => { + | ExprKind::Yield { .. } => { debug_assert!(match Category::of(&expr.kind).unwrap() { + // should be handled above Category::Rvalue(RvalueFunc::Into) => false, + + // must be handled above or else we get an + // infinite loop in the builder; see + // e.g. `ExprKind::VarRef` above + Category::Place => false, + _ => true, }); -- 2.44.0