Skip to content

Commit f5df1f5

Browse files
authored
Rollup merge of #143583 - folkertdev:loop-match-no-terminator-on-block, r=bjorn3
`loop_match`: fix 'no terminator on block' tracking issue: #132306 fixes #143435 The argument `block` was not properly closed on an error path. r? `@bjorn3`
2 parents 7ed6bd9 + 6d58a88 commit f5df1f5

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

compiler/rustc_mir_build/src/builder/scope.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
936936

937937
valtree
938938
}
939-
Err(ErrorHandled::Reported(..)) => return self.cfg.start_new_block().unit(),
939+
Err(ErrorHandled::Reported(..)) => {
940+
return block.unit();
941+
}
940942
Err(ErrorHandled::TooGeneric(_)) => {
941943
self.tcx.dcx().emit_fatal(ConstContinueBadConst { span: constant.span });
942944
}

tests/ui/loop-match/panic-in-const.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#![allow(incomplete_features)]
2+
#![feature(loop_match)]
3+
#![crate_type = "lib"]
4+
5+
const CONST_THAT_PANICS: u8 = panic!("diverge!");
6+
//~^ ERROR: evaluation panicked: diverge!
7+
8+
fn test(mut state: u8) {
9+
#[loop_match]
10+
loop {
11+
state = 'blk: {
12+
match state {
13+
0 => {
14+
#[const_continue]
15+
break 'blk CONST_THAT_PANICS;
16+
}
17+
18+
_ => unreachable!(),
19+
}
20+
}
21+
}
22+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0080]: evaluation panicked: diverge!
2+
--> $DIR/panic-in-const.rs:5:31
3+
|
4+
LL | const CONST_THAT_PANICS: u8 = panic!("diverge!");
5+
| ^^^^^^^^^^^^^^^^^^ evaluation of `CONST_THAT_PANICS` failed here
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)