Skip to content

Commit c3452f3

Browse files
committed
Lint on continue expression without semi-colon
1 parent 9d6127c commit c3452f3

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

clippy_lints/src/needless_continue.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,8 @@ fn check_and_warn<'a>(cx: &EarlyContext<'_>, expr: &'a ast::Expr) {
371371
if_chain! {
372372
if let ast::ExprKind::Loop(loop_block, ..) = &expr.kind;
373373
if !loop_block.stmts.is_empty();
374-
if let ast::StmtKind::Semi(ref statement) = loop_block.stmts.last().unwrap().kind;
374+
if let ast::StmtKind::Expr(ref statement)
375+
| ast::StmtKind::Semi(ref statement) = loop_block.stmts.last().unwrap().kind;
375376
if let ast::ExprKind::Continue(_) = statement.kind;
376377
then {
377378
span_lint_and_help(

tests/ui/needless_continue.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,21 @@ fn simple_loop2() {
6464
}
6565
}
6666

67+
#[rustfmt::skip]
68+
fn simple_loop3() {
69+
loop {
70+
continue // should lint here
71+
}
72+
}
73+
74+
#[rustfmt::skip]
75+
fn simple_loop4() {
76+
loop {
77+
println!("bleh");
78+
continue // should lint here
79+
}
80+
}
81+
6782
mod issue_2329 {
6883
fn condition() -> bool {
6984
unimplemented!()

tests/ui/needless_continue.stderr

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,24 @@ LL | continue; // should lint here
7070
|
7171
= help: consider dropping the `continue` expression
7272

73+
error: this `continue` expression is redundant
74+
--> $DIR/needless_continue.rs:70:9
75+
|
76+
LL | continue // should lint here
77+
| ^^^^^^^^
78+
|
79+
= help: consider dropping the `continue` expression
80+
81+
error: this `continue` expression is redundant
82+
--> $DIR/needless_continue.rs:78:9
83+
|
84+
LL | continue // should lint here
85+
| ^^^^^^^^
86+
|
87+
= help: consider dropping the `continue` expression
88+
7389
error: this `else` block is redundant
74-
--> $DIR/needless_continue.rs:113:24
90+
--> $DIR/needless_continue.rs:128:24
7591
|
7692
LL | } else {
7793
| ________________________^
@@ -94,7 +110,7 @@ LL | | }
94110
}
95111

96112
error: there is no need for an explicit `else` block for this `if` expression
97-
--> $DIR/needless_continue.rs:119:17
113+
--> $DIR/needless_continue.rs:134:17
98114
|
99115
LL | / if condition() {
100116
LL | | continue; // should lint here
@@ -111,5 +127,5 @@ LL | | }
111127
println!("bar-5");
112128
}
113129

114-
error: aborting due to 6 previous errors
130+
error: aborting due to 8 previous errors
115131

0 commit comments

Comments
 (0)