about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorlengyijun <sjtu5140809011@gmail.com>2023-09-20 21:05:36 +0800
committeryanglsh <yanglsh@shanghaitech.edu.cn>2024-12-28 09:58:06 -0700
commite582fcd75dda451c68c266d91d538f010f4a9b9f (patch)
tree693c154fdc35282241762a34db06a79546a17536 /tests
parent998c7801260007b8e36fe8749f3c90b25b3e4df3 (diff)
downloadrust-e582fcd75dda451c68c266d91d538f010f4a9b9f.tar.gz
rust-e582fcd75dda451c68c266d91d538f010f4a9b9f.zip
[`needless_continue`]: lint if the last stmt in for/while/loop is `continue`, recursively
fixes: #4077
Diffstat (limited to 'tests')
-rw-r--r--tests/missing-test-files.rs2
-rw-r--r--tests/ui/needless_continue.rs39
-rw-r--r--tests/ui/needless_continue.stderr38
3 files changed, 71 insertions, 8 deletions
diff --git a/tests/missing-test-files.rs b/tests/missing-test-files.rs
index a8225d037e8..64eba5e0888 100644
--- a/tests/missing-test-files.rs
+++ b/tests/missing-test-files.rs
@@ -59,7 +59,7 @@ fn explore_directory(dir: &Path) -> Vec<String> {
                             missing_files.push(path.to_str().unwrap().to_string());
                         }
                     },
-                    _ => continue,
+                    _ => {},
                 };
             }
         }
diff --git a/tests/ui/needless_continue.rs b/tests/ui/needless_continue.rs
index b6d8a8f61ae..bc7233f3ba5 100644
--- a/tests/ui/needless_continue.rs
+++ b/tests/ui/needless_continue.rs
@@ -87,6 +87,14 @@ fn simple_loop4() {
     }
 }
 
+fn simple_loop5() {
+    loop {
+        println!("bleh");
+        { continue }
+        //~^ ERROR: this `continue` expression is redundant
+    }
+}
+
 mod issue_2329 {
     fn condition() -> bool {
         unimplemented!()
@@ -168,3 +176,34 @@ fn issue_13641() {
         }
     }
 }
+
+mod issue_4077 {
+    fn main() {
+        'outer: loop {
+            'inner: loop {
+                do_something();
+                if some_expr() {
+                    println!("bar-7");
+                    continue 'outer;
+                } else if !some_expr() {
+                    println!("bar-8");
+                    continue 'inner;
+                } else {
+                    println!("bar-9");
+                    continue 'inner;
+                }
+            }
+        }
+    }
+
+    // The contents of these functions are irrelevant, the purpose of this file is
+    // shown in main.
+
+    fn do_something() {
+        std::process::exit(0);
+    }
+
+    fn some_expr() -> bool {
+        true
+    }
+}
diff --git a/tests/ui/needless_continue.stderr b/tests/ui/needless_continue.stderr
index 0741ba69248..4ab443108b0 100644
--- a/tests/ui/needless_continue.stderr
+++ b/tests/ui/needless_continue.stderr
@@ -63,7 +63,7 @@ error: this `continue` expression is redundant
   --> tests/ui/needless_continue.rs:60:9
    |
 LL |         continue;
-   |         ^^^^^^^^^
+   |         ^^^^^^^^
    |
    = help: consider dropping the `continue` expression
 
@@ -71,7 +71,7 @@ error: this `continue` expression is redundant
   --> tests/ui/needless_continue.rs:68:9
    |
 LL |         continue;
-   |         ^^^^^^^^^
+   |         ^^^^^^^^
    |
    = help: consider dropping the `continue` expression
 
@@ -91,8 +91,16 @@ LL |         continue
    |
    = help: consider dropping the `continue` expression
 
+error: this `continue` expression is redundant
+  --> tests/ui/needless_continue.rs:93:11
+   |
+LL |         { continue }
+   |           ^^^^^^^^
+   |
+   = help: consider dropping the `continue` expression
+
 error: this `else` block is redundant
-  --> tests/ui/needless_continue.rs:136:24
+  --> tests/ui/needless_continue.rs:144:24
    |
 LL |                   } else {
    |  ________________________^
@@ -117,7 +125,7 @@ LL | |                 }
                            }
 
 error: there is no need for an explicit `else` block for this `if` expression
-  --> tests/ui/needless_continue.rs:143:17
+  --> tests/ui/needless_continue.rs:151:17
    |
 LL | /                 if condition() {
 LL | |
@@ -137,12 +145,28 @@ LL | |                 }
                            }
 
 error: this `continue` expression is redundant
-  --> tests/ui/needless_continue.rs:166:13
+  --> tests/ui/needless_continue.rs:174:13
    |
 LL |             continue 'b;
-   |             ^^^^^^^^^^^^
+   |             ^^^^^^^^^^^
+   |
+   = help: consider dropping the `continue` expression
+
+error: this `continue` expression is redundant
+  --> tests/ui/needless_continue.rs:190:21
+   |
+LL |                     continue 'inner;
+   |                     ^^^^^^^^^^^^^^^
+   |
+   = help: consider dropping the `continue` expression
+
+error: this `continue` expression is redundant
+  --> tests/ui/needless_continue.rs:193:21
+   |
+LL |                     continue 'inner;
+   |                     ^^^^^^^^^^^^^^^
    |
    = help: consider dropping the `continue` expression
 
-error: aborting due to 9 previous errors
+error: aborting due to 12 previous errors