Skip to content

Commit ad10d18

Browse files
authored
Rollup merge of rust-lang#137454 - mu001999-contrib:fix-137414, r=wesleywiser
not lint break with label and unsafe block fixes rust-lang#137414 we can't label unsafe blocks, so that we can do not lint them
2 parents 191df20 + 3fe0b3d commit ad10d18

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

Diff for: compiler/rustc_parse/src/parser/expr.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -1884,13 +1884,15 @@ impl<'a> Parser<'a> {
18841884
let mut expr = self.parse_expr_opt()?;
18851885
if let Some(expr) = &mut expr {
18861886
if label.is_some()
1887-
&& matches!(
1888-
expr.kind,
1887+
&& match &expr.kind {
18891888
ExprKind::While(_, _, None)
1890-
| ExprKind::ForLoop { label: None, .. }
1891-
| ExprKind::Loop(_, None, _)
1892-
| ExprKind::Block(_, None)
1893-
)
1889+
| ExprKind::ForLoop { label: None, .. }
1890+
| ExprKind::Loop(_, None, _) => true,
1891+
ExprKind::Block(block, None) => {
1892+
matches!(block.rules, BlockCheckMode::Default)
1893+
}
1894+
_ => false,
1895+
}
18941896
{
18951897
self.psess.buffer_lint(
18961898
BREAK_WITH_LABEL_AND_LOOP,

Diff for: tests/ui/lint/break-with-label-and-unsafe-block.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@ check-pass
2+
3+
#![deny(break_with_label_and_loop)]
4+
5+
unsafe fn foo() -> i32 { 42 }
6+
7+
fn main () {
8+
'label: loop {
9+
break 'label unsafe { foo() }
10+
};
11+
}

0 commit comments

Comments
 (0)