about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authoryanglsh <yanglsh@shanghaitech.edu.cn>2025-07-27 18:06:59 +0800
committeryanglsh <yanglsh@shanghaitech.edu.cn>2025-08-25 06:32:34 +0800
commit40ff07622e5122aecc2cc03a61152782bc2a0568 (patch)
treea02157d4a9872863a8da122c521bd3fae0e62572 /tests
parent03978193a5900c0d4767891eee408a54aaf1915c (diff)
downloadrust-40ff07622e5122aecc2cc03a61152782bc2a0568.tar.gz
rust-40ff07622e5122aecc2cc03a61152782bc2a0568.zip
fix: `never_loop` forget to remove break in nested loop
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/never_loop.rs24
-rw-r--r--tests/ui/never_loop.stderr97
-rw-r--r--tests/ui/never_loop_fixable.fixed2
-rw-r--r--tests/ui/never_loop_fixable.rs2
4 files changed, 122 insertions, 3 deletions
diff --git a/tests/ui/never_loop.rs b/tests/ui/never_loop.rs
index 48d4b8ad151..01db64a446c 100644
--- a/tests/ui/never_loop.rs
+++ b/tests/ui/never_loop.rs
@@ -498,3 +498,27 @@ fn issue15059() {
         ()
     }
 }
+
+fn issue15350() {
+    'bar: for _ in 0..100 {
+        //~^ never_loop
+        loop {
+            //~^ never_loop
+            println!("This will still run");
+            break 'bar;
+        }
+    }
+
+    'foo: for _ in 0..100 {
+        //~^ never_loop
+        loop {
+            //~^ never_loop
+            println!("This will still run");
+            loop {
+                //~^ never_loop
+                println!("This will still run");
+                break 'foo;
+            }
+        }
+    }
+}
diff --git a/tests/ui/never_loop.stderr b/tests/ui/never_loop.stderr
index 54b463266a3..4fda06cff4a 100644
--- a/tests/ui/never_loop.stderr
+++ b/tests/ui/never_loop.stderr
@@ -193,6 +193,19 @@ LL | |         return;
 LL | |     }
    | |_____^
    |
+help: this code is unreachable. Consider moving the reachable parts out
+  --> tests/ui/never_loop.rs:436:9
+   |
+LL | /         loop {
+LL | |
+LL | |             break 'outer;
+LL | |         }
+   | |_________^
+help: this code is unreachable. Consider moving the reachable parts out
+  --> tests/ui/never_loop.rs:440:9
+   |
+LL |         return;
+   |         ^^^^^^^
 help: if you need the first element of the iterator, try writing
    |
 LL -     'outer: for v in 0..10 {
@@ -297,5 +310,87 @@ LL ~
 LL ~         
    |
 
-error: aborting due to 24 previous errors
+error: this loop never actually loops
+  --> tests/ui/never_loop.rs:503:5
+   |
+LL | /     'bar: for _ in 0..100 {
+LL | |
+LL | |         loop {
+...  |
+LL | |     }
+   | |_____^
+   |
+help: this code is unreachable. Consider moving the reachable parts out
+  --> tests/ui/never_loop.rs:505:9
+   |
+LL | /         loop {
+LL | |
+LL | |             println!("This will still run");
+LL | |             break 'bar;
+LL | |         }
+   | |_________^
+help: if you need the first element of the iterator, try writing
+   |
+LL -     'bar: for _ in 0..100 {
+LL +     if let Some(_) = (0..100).next() {
+   |
+
+error: this loop never actually loops
+  --> tests/ui/never_loop.rs:505:9
+   |
+LL | /         loop {
+LL | |
+LL | |             println!("This will still run");
+LL | |             break 'bar;
+LL | |         }
+   | |_________^
+
+error: this loop never actually loops
+  --> tests/ui/never_loop.rs:512:5
+   |
+LL | /     'foo: for _ in 0..100 {
+LL | |
+LL | |         loop {
+...  |
+LL | |     }
+   | |_____^
+   |
+help: this code is unreachable. Consider moving the reachable parts out
+  --> tests/ui/never_loop.rs:514:9
+   |
+LL | /         loop {
+LL | |
+LL | |             println!("This will still run");
+LL | |             loop {
+...  |
+LL | |         }
+   | |_________^
+help: if you need the first element of the iterator, try writing
+   |
+LL -     'foo: for _ in 0..100 {
+LL +     if let Some(_) = (0..100).next() {
+   |
+
+error: this loop never actually loops
+  --> tests/ui/never_loop.rs:514:9
+   |
+LL | /         loop {
+LL | |
+LL | |             println!("This will still run");
+LL | |             loop {
+...  |
+LL | |         }
+   | |_________^
+
+error: this loop never actually loops
+  --> tests/ui/never_loop.rs:517:13
+   |
+LL | /             loop {
+LL | |
+LL | |                 println!("This will still run");
+LL | |                 break 'foo;
+LL | |             }
+   | |_____________^
+
+error: aborting due to 29 previous errors
 
diff --git a/tests/ui/never_loop_fixable.fixed b/tests/ui/never_loop_fixable.fixed
index 5bc9ff1bb4d..00c2af93a28 100644
--- a/tests/ui/never_loop_fixable.fixed
+++ b/tests/ui/never_loop_fixable.fixed
@@ -1,4 +1,4 @@
-#![allow(clippy::iter_next_slice, clippy::needless_return)]
+#![allow(clippy::iter_next_slice, clippy::needless_return, clippy::redundant_pattern_matching)]
 
 fn no_break_or_continue_loop() {
     if let Some(i) = [1, 2, 3].iter().next() {
diff --git a/tests/ui/never_loop_fixable.rs b/tests/ui/never_loop_fixable.rs
index 9782bc107e9..de85599f094 100644
--- a/tests/ui/never_loop_fixable.rs
+++ b/tests/ui/never_loop_fixable.rs
@@ -1,4 +1,4 @@
-#![allow(clippy::iter_next_slice, clippy::needless_return)]
+#![allow(clippy::iter_next_slice, clippy::needless_return, clippy::redundant_pattern_matching)]
 
 fn no_break_or_continue_loop() {
     for i in [1, 2, 3].iter() {