Skip to content

Commit

Permalink
Rollup merge of rust-lang#74411 - jonas-schievink:unbreak-mir, r=matt…
Browse files Browse the repository at this point in the history
…hewjasper

Don't assign `()` to `!` MIR locals

Implements the fix described in rust-lang#73860 (comment).

Fixes rust-lang#73860

r? @matthewjasper
  • Loading branch information
Manishearth authored Jul 17, 2020
2 parents 9c46e1b + 209991f commit cab04ec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
20 changes: 11 additions & 9 deletions src/librustc_mir_build/build/expr/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -224,7 +223,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Some((destination, success))
},
from_hir_call,
fn_span
fn_span,
},
);
success.unit()
Expand Down Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions src/test/mir-opt/issue-49232/rustc.main.mir_map.0.mir
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit cab04ec

Please sign in to comment.