Skip to content

Commit 5fb7210

Browse files
authored
Rollup merge of #72581 - samrat:allow-desugared-break-in-labeled-block, r=davidtwco
Allow unlabeled breaks from desugared `?` in labeled blocks `?` is desugared into a `break` targeting the innermost `try` scope in which it resides. The `break` however will not have a label. https://github.com/rust-lang/rust/blob/master/src/librustc_ast_lowering/expr.rs#L1560 Since the `target` of the `break` is known, the compiler should not complain about an unlabeled jump for `break`s desugared from `?`. Closes #72483
2 parents 401b3ae + 91dcbbb commit 5fb7210

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/librustc_passes/loops.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_middle::hir::map::Map;
99
use rustc_middle::ty::query::Providers;
1010
use rustc_middle::ty::TyCtxt;
1111
use rustc_session::Session;
12+
use rustc_span::hygiene::DesugaringKind;
1213
use rustc_span::Span;
1314

1415
#[derive(Clone, Copy, Debug, PartialEq)]
@@ -203,7 +204,7 @@ impl<'a, 'hir> CheckLoopVisitor<'a, 'hir> {
203204
label: &Destination,
204205
cf_type: &str,
205206
) -> bool {
206-
if self.cx == LabeledBlock {
207+
if !span.is_desugaring(DesugaringKind::QuestionMark) && self.cx == LabeledBlock {
207208
if label.label.is_none() {
208209
struct_span_err!(
209210
self.sess,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// compile-flags: --edition 2018
2+
#![feature(label_break_value, try_blocks)]
3+
4+
// run-pass
5+
fn main() {
6+
let _: Result<(), ()> = try {
7+
'foo: {
8+
Err(())?;
9+
break 'foo;
10+
}
11+
};
12+
}

0 commit comments

Comments
 (0)