]> git.lizzy.rs Git - rust.git/commitdiff
Lint on continue expression without semi-colon
authorF3real <stefan92ff@yandex.com>
Thu, 22 Jul 2021 20:21:34 +0000 (22:21 +0200)
committerF3real <stefan92ff@yandex.com>
Thu, 22 Jul 2021 20:23:59 +0000 (22:23 +0200)
clippy_lints/src/needless_continue.rs
tests/ui/needless_continue.rs
tests/ui/needless_continue.stderr

index 0c2b382b3d28ebd50daa378ebbff66d7a355024f..a1f224e7d3ab854a44221ccba3bd305486b7c81e 100644 (file)
@@ -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(
index 443a21f0268e7c3fbac5edc8a66c2fd0efa40584..83ee27f4887a1822d7aa6ae1eb1deca3fc29edba 100644 (file)
@@ -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!()
index 8042b740c73255c6e382ab6130b4e7023b1bb8e4..22b86f25e8f0e44ced23329d1cc378cc31d27e89 100644 (file)
@@ -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