Skip to content

Commit 3fe0b3d

Browse files
committed
not lint break with label and unsafe block
1 parent a18bd8a commit 3fe0b3d

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
@@ -1859,13 +1859,15 @@ impl<'a> Parser<'a> {
18591859
let mut expr = self.parse_expr_opt()?;
18601860
if let Some(expr) = &mut expr {
18611861
if label.is_some()
1862-
&& matches!(
1863-
expr.kind,
1862+
&& match &expr.kind {
18641863
ExprKind::While(_, _, None)
1865-
| ExprKind::ForLoop { label: None, .. }
1866-
| ExprKind::Loop(_, None, _)
1867-
| ExprKind::Block(_, None)
1868-
)
1864+
| ExprKind::ForLoop { label: None, .. }
1865+
| ExprKind::Loop(_, None, _) => true,
1866+
ExprKind::Block(block, None) => {
1867+
matches!(block.rules, BlockCheckMode::Default)
1868+
}
1869+
_ => false,
1870+
}
18691871
{
18701872
self.psess.buffer_lint(
18711873
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)