diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2020-07-17 14:09:22 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-17 14:09:22 -0700 |
| commit | 87d01d11e17e497b3ec43559cbeee3ad704603ee (patch) | |
| tree | b63befeb92c5078c4d1bb6be6fb3ca7d98fdfd73 | |
| parent | 105cd4b21eaef2e68227eb5b58c910de574af0cd (diff) | |
| parent | 209991f8b29698f0dba9baa5e31d501bc7931229 (diff) | |
| download | rust-87d01d11e17e497b3ec43559cbeee3ad704603ee.tar.gz rust-87d01d11e17e497b3ec43559cbeee3ad704603ee.zip | |
Rollup merge of #74411 - jonas-schievink:unbreak-mir, r=matthewjasper
Don't assign `()` to `!` MIR locals Implements the fix described in https://github.com/rust-lang/rust/issues/73860#issuecomment-651731893. Fixes https://github.com/rust-lang/rust/issues/73860 r? @matthewjasper
| -rw-r--r-- | src/librustc_mir_build/build/expr/into.rs | 20 | ||||
| -rw-r--r-- | src/test/mir-opt/issue-49232/rustc.main.mir_map.0.mir | 7 |
2 files changed, 11 insertions, 16 deletions
diff --git a/src/librustc_mir_build/build/expr/into.rs b/src/librustc_mir_build/build/expr/into.rs index 0d5bd4c7e61..eaef6bb37fa 100644 --- a/src/librustc_mir_build/build/expr/into.rs +++ b/src/librustc_mir_build/build/expr/into.rs @@ -188,10 +188,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let ptr_ty = ptr.ty; // Create an *internal* temp for the pointer, so that unsafety // checking won't complain about the raw pointer assignment. - let ptr_temp = this.local_decls.push(LocalDecl::with_source_info( - ptr_ty, - source_info, - ).internal()); + let ptr_temp = this + .local_decls + .push(LocalDecl::with_source_info(ptr_ty, source_info).internal()); let ptr_temp = Place::from(ptr_temp); let block = unpack!(this.into(ptr_temp, block, ptr)); this.into(this.hir.tcx().mk_place_deref(ptr_temp), block, val) @@ -224,7 +223,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { Some((destination, success)) }, from_hir_call, - fn_span + fn_span, }, ); success.unit() @@ -387,15 +386,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // These cases don't actually need a destination ExprKind::Assign { .. } | ExprKind::AssignOp { .. } - | ExprKind::Continue { .. } - | ExprKind::Break { .. } - | ExprKind::LlvmInlineAsm { .. } - | ExprKind::Return { .. } => { + | ExprKind::LlvmInlineAsm { .. } => { unpack!(block = this.stmt_expr(block, expr, None)); this.cfg.push_assign_unit(block, source_info, destination, this.hir.tcx()); block.unit() } + ExprKind::Continue { .. } | ExprKind::Break { .. } | ExprKind::Return { .. } => { + unpack!(block = this.stmt_expr(block, expr, None)); + // No assign, as these have type `!`. + block.unit() + } + // Avoid creating a temporary ExprKind::VarRef { .. } | ExprKind::SelfRef diff --git a/src/test/mir-opt/issue-49232/rustc.main.mir_map.0.mir b/src/test/mir-opt/issue-49232/rustc.main.mir_map.0.mir index f65b93a34da..918dc5ec387 100644 --- a/src/test/mir-opt/issue-49232/rustc.main.mir_map.0.mir +++ b/src/test/mir-opt/issue-49232/rustc.main.mir_map.0.mir @@ -79,13 +79,6 @@ fn main() -> () { } bb10: { - _4 = const (); // scope 0 at $DIR/issue-49232.rs:10:25: 10:30 - // ty::Const - // + ty: () - // + val: Value(Scalar(<ZST>)) - // mir::Constant - // + span: $DIR/issue-49232.rs:10:25: 10:30 - // + literal: Const { ty: (), val: Value(Scalar(<ZST>)) } unreachable; // scope 0 at $DIR/issue-49232.rs:10:25: 10:30 } |
