Skip to content

Commit a6e24fc

Browse files
committed
initialize the destination in unit statements
Fixes #46159.
1 parent af8c233 commit a6e24fc

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

src/librustc_mir/build/expr/into.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
273273
ExprKind::Break { .. } |
274274
ExprKind::InlineAsm { .. } |
275275
ExprKind::Return {.. } => {
276-
this.stmt_expr(block, expr)
276+
unpack!(block = this.stmt_expr(block, expr));
277+
this.cfg.push_assign_unit(block, source_info, destination);
278+
block.unit()
277279
}
278280

279281
// these are the cases that are more naturally handled by some other mode

src/test/mir-opt/validate_4.rs

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ fn main() {
5454
// Validate(Acquire, [_1: &ReFree(DefId(0/1:9 ~ validate_4[317d]::write_42[0]::{{closure}}[0]), BrEnv) [closure@NodeId(22)], _2: *mut i32]);
5555
// Validate(Release, [_1: &ReFree(DefId(0/1:9 ~ validate_4[317d]::write_42[0]::{{closure}}[0]), BrEnv) [closure@NodeId(22)], _2: *mut i32]);
5656
// (*_2) = const 23i32;
57+
// _0 = ();
5758
// return;
5859
// }
5960
// }

src/test/run-pass/weird-exprs.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// compile-flags: -Z borrowck=compare
1112

1213
use std::cell::Cell;
1314
use std::mem::swap;

0 commit comments

Comments
 (0)