Skip to content

Commit 36bf31d

Browse files
committed
fix #[loop_match] on diverging loop
this generated invalid MIR before
1 parent adcb3d3 commit 36bf31d

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

compiler/rustc_mir_build/src/builder/expr/into.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
345345
expr_span,
346346
|this| {
347347
this.lower_match_arms(
348-
destination,
348+
state_place,
349349
scrutinee_place_builder,
350350
scrutinee_span,
351351
arms,

tests/ui/loop-match/diverges.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//@ build-pass
2+
//@ compile-flags: -Zvalidate-mir
3+
#![allow(incomplete_features)]
4+
#![feature(loop_match)]
5+
#![crate_type = "lib"]
6+
7+
// Test that a #[loop_match] without an explicit break from the loop generates valid MIR.
8+
9+
fn break_to_block_unit() -> u8 {
10+
let mut state = 0;
11+
#[loop_match]
12+
loop {
13+
state = 'blk: {
14+
match state {
15+
_ => 'b: {
16+
break 'b 2;
17+
}
18+
}
19+
}
20+
}
21+
}
22+
23+
fn break_to_block_value() -> u8 {
24+
let mut state = 0u8;
25+
#[loop_match]
26+
'a: loop {
27+
state = 'blk: {
28+
match state {
29+
_ => break 'blk state,
30+
}
31+
}
32+
}
33+
}
34+
35+
fn infinite_a(mut state: u8) {
36+
#[loop_match]
37+
loop {
38+
state = 'blk: {
39+
match state {
40+
a => a,
41+
}
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)