about summary refs log tree commit diff
diff options
context:
space:
mode:
authorF3real <stefan92ff@yandex.com>2021-07-22 22:21:34 +0200
committerF3real <stefan92ff@yandex.com>2021-07-22 22:23:59 +0200
commitc3452f3bd261e029b361c94ba8ed3bb909fde5fb (patch)
treea4c05c58f97c0dd89ad7e4e9dfbfb479bf2e2475
parent9d6127cdb0bead8f3a19440e9029edc9bf2e9a25 (diff)
downloadrust-c3452f3bd261e029b361c94ba8ed3bb909fde5fb.tar.gz
rust-c3452f3bd261e029b361c94ba8ed3bb909fde5fb.zip
Lint on continue expression without semi-colon
-rw-r--r--clippy_lints/src/needless_continue.rs3
-rw-r--r--tests/ui/needless_continue.rs15
-rw-r--r--tests/ui/needless_continue.stderr22
3 files changed, 36 insertions, 4 deletions
diff --git a/clippy_lints/src/needless_continue.rs b/clippy_lints/src/needless_continue.rs
index 0c2b382b3d2..a1f224e7d3a 100644
--- a/clippy_lints/src/needless_continue.rs
+++ b/clippy_lints/src/needless_continue.rs
@@ -371,7 +371,8 @@ fn check_and_warn<'a>(cx: &EarlyContext<'_>, expr: &'a ast::Expr) {
     if_chain! {
         if let ast::ExprKind::Loop(loop_block, ..) = &expr.kind;
         if !loop_block.stmts.is_empty();
-        if let ast::StmtKind::Semi(ref statement) = loop_block.stmts.last().unwrap().kind;
+        if let ast::StmtKind::Expr(ref statement)
+        | ast::StmtKind::Semi(ref statement) = loop_block.stmts.last().unwrap().kind;
         if let ast::ExprKind::Continue(_) = statement.kind;
         then {
             span_lint_and_help(
diff --git a/tests/ui/needless_continue.rs b/tests/ui/needless_continue.rs
index 443a21f0268..83ee27f4887 100644
--- a/tests/ui/needless_continue.rs
+++ b/tests/ui/needless_continue.rs
@@ -64,6 +64,21 @@ fn simple_loop2() {
     }
 }
 
+#[rustfmt::skip]
+fn simple_loop3() {
+    loop {
+        continue // should lint here
+    }
+}
+
+#[rustfmt::skip]
+fn simple_loop4() {
+    loop {
+        println!("bleh");
+        continue // should lint here
+    }
+}
+
 mod issue_2329 {
     fn condition() -> bool {
         unimplemented!()
diff --git a/tests/ui/needless_continue.stderr b/tests/ui/needless_continue.stderr
index 8042b740c73..22b86f25e8f 100644
--- a/tests/ui/needless_continue.stderr
+++ b/tests/ui/needless_continue.stderr
@@ -70,8 +70,24 @@ LL |         continue; // should lint here
    |
    = help: consider dropping the `continue` expression
 
+error: this `continue` expression is redundant
+  --> $DIR/needless_continue.rs:70:9
+   |
+LL |         continue // should lint here
+   |         ^^^^^^^^
+   |
+   = help: consider dropping the `continue` expression
+
+error: this `continue` expression is redundant
+  --> $DIR/needless_continue.rs:78:9
+   |
+LL |         continue // should lint here
+   |         ^^^^^^^^
+   |
+   = help: consider dropping the `continue` expression
+
 error: this `else` block is redundant
-  --> $DIR/needless_continue.rs:113:24
+  --> $DIR/needless_continue.rs:128:24
    |
 LL |                   } else {
    |  ________________________^
@@ -94,7 +110,7 @@ LL | |                 }
                            }
 
 error: there is no need for an explicit `else` block for this `if` expression
-  --> $DIR/needless_continue.rs:119:17
+  --> $DIR/needless_continue.rs:134:17
    |
 LL | /                 if condition() {
 LL | |                     continue; // should lint here
@@ -111,5 +127,5 @@ LL | |                 }
                                println!("bar-5");
                            }
 
-error: aborting due to 6 previous errors
+error: aborting due to 8 previous errors