summary refs log tree commit diff
diff options
context:
space:
mode:
authorChris Denton <chris@chrisdenton.dev>2025-04-19 14:01:36 +0000
committerGitHub <noreply@github.com>2025-04-19 14:01:36 +0000
commitdb98b72e34c82e18c96b76e166acda95f4b0e43c (patch)
tree184d38d26a4af24b67f3696dbafc41adca3fe195
parenta7c39b68616668a45f0afd62849a1da7c8ad2516 (diff)
parent3fe0b3d4d04dd86cbe22770217f3b42a8856d382 (diff)
downloadrust-db98b72e34c82e18c96b76e166acda95f4b0e43c.tar.gz
rust-db98b72e34c82e18c96b76e166acda95f4b0e43c.zip
Rollup merge of #137454 - mu001999-contrib:fix-137414, r=wesleywiser
not lint break with label and unsafe block

fixes #137414

we can't label unsafe blocks, so that we can do not lint them
-rw-r--r--compiler/rustc_parse/src/parser/expr.rs14
-rw-r--r--tests/ui/lint/break-with-label-and-unsafe-block.rs11
2 files changed, 19 insertions, 6 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs
index df44b3cc23c..71cc814cb50 100644
--- a/compiler/rustc_parse/src/parser/expr.rs
+++ b/compiler/rustc_parse/src/parser/expr.rs
@@ -1884,13 +1884,15 @@ impl<'a> Parser<'a> {
             let mut expr = self.parse_expr_opt()?;
             if let Some(expr) = &mut expr {
                 if label.is_some()
-                    && matches!(
-                        expr.kind,
+                    && match &expr.kind {
                         ExprKind::While(_, _, None)
-                            | ExprKind::ForLoop { label: None, .. }
-                            | ExprKind::Loop(_, None, _)
-                            | ExprKind::Block(_, None)
-                    )
+                        | ExprKind::ForLoop { label: None, .. }
+                        | ExprKind::Loop(_, None, _) => true,
+                        ExprKind::Block(block, None) => {
+                            matches!(block.rules, BlockCheckMode::Default)
+                        }
+                        _ => false,
+                    }
                 {
                     self.psess.buffer_lint(
                         BREAK_WITH_LABEL_AND_LOOP,
diff --git a/tests/ui/lint/break-with-label-and-unsafe-block.rs b/tests/ui/lint/break-with-label-and-unsafe-block.rs
new file mode 100644
index 00000000000..a76a5761475
--- /dev/null
+++ b/tests/ui/lint/break-with-label-and-unsafe-block.rs
@@ -0,0 +1,11 @@
+//@ check-pass
+
+#![deny(break_with_label_and_loop)]
+
+unsafe fn foo() -> i32 { 42 }
+
+fn main () {
+    'label: loop {
+        break 'label unsafe { foo() }
+    };
+}