Skip to content

Commit 209991f

Browse files
committedJul 16, 2020
Don't assign () to ! MIR locals
1 parent 7e11379 commit 209991f

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed
 

‎src/librustc_mir_build/build/expr/into.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
188188
let ptr_ty = ptr.ty;
189189
// Create an *internal* temp for the pointer, so that unsafety
190190
// checking won't complain about the raw pointer assignment.
191-
let ptr_temp = this.local_decls.push(LocalDecl::with_source_info(
192-
ptr_ty,
193-
source_info,
194-
).internal());
191+
let ptr_temp = this
192+
.local_decls
193+
.push(LocalDecl::with_source_info(ptr_ty, source_info).internal());
195194
let ptr_temp = Place::from(ptr_temp);
196195
let block = unpack!(this.into(ptr_temp, block, ptr));
197196
this.into(this.hir.tcx().mk_place_deref(ptr_temp), block, val)
@@ -224,7 +223,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
224223
Some((destination, success))
225224
},
226225
from_hir_call,
227-
fn_span
226+
fn_span,
228227
},
229228
);
230229
success.unit()
@@ -387,15 +386,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
387386
// These cases don't actually need a destination
388387
ExprKind::Assign { .. }
389388
| ExprKind::AssignOp { .. }
390-
| ExprKind::Continue { .. }
391-
| ExprKind::Break { .. }
392-
| ExprKind::LlvmInlineAsm { .. }
393-
| ExprKind::Return { .. } => {
389+
| ExprKind::LlvmInlineAsm { .. } => {
394390
unpack!(block = this.stmt_expr(block, expr, None));
395391
this.cfg.push_assign_unit(block, source_info, destination, this.hir.tcx());
396392
block.unit()
397393
}
398394

395+
ExprKind::Continue { .. } | ExprKind::Break { .. } | ExprKind::Return { .. } => {
396+
unpack!(block = this.stmt_expr(block, expr, None));
397+
// No assign, as these have type `!`.
398+
block.unit()
399+
}
400+
399401
// Avoid creating a temporary
400402
ExprKind::VarRef { .. }
401403
| ExprKind::SelfRef

‎src/test/mir-opt/issue-49232/rustc.main.mir_map.0.mir

-7
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,6 @@ fn main() -> () {
7979
}
8080

8181
bb10: {
82-
_4 = const (); // scope 0 at $DIR/issue-49232.rs:10:25: 10:30
83-
// ty::Const
84-
// + ty: ()
85-
// + val: Value(Scalar(<ZST>))
86-
// mir::Constant
87-
// + span: $DIR/issue-49232.rs:10:25: 10:30
88-
// + literal: Const { ty: (), val: Value(Scalar(<ZST>)) }
8982
unreachable; // scope 0 at $DIR/issue-49232.rs:10:25: 10:30
9083
}
9184

0 commit comments

Comments
 (0)
Please sign in to comment.