Skip to content

Commit ccf7c88

Browse files
committed
Auto merge of #13648 - samueltardieu:push-rpxvoukpolvm, r=Centri3
needless_continue: check labels consistency before warning changelog: [`needless_continue`]: check labels before warning about `continue` as the last statement in a loop body Fix #13641
2 parents a1a9aae + 2f1b7b6 commit ccf7c88

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

clippy_lints/src/needless_continue.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,11 @@ fn suggestion_snippet_for_continue_inside_else(cx: &EarlyContext<'_>, data: &Lin
330330
}
331331

332332
fn check_and_warn(cx: &EarlyContext<'_>, expr: &ast::Expr) {
333-
if let ast::ExprKind::Loop(loop_block, ..) = &expr.kind
333+
if let ast::ExprKind::Loop(loop_block, loop_label, ..) = &expr.kind
334334
&& let Some(last_stmt) = loop_block.stmts.last()
335335
&& let ast::StmtKind::Expr(inner_expr) | ast::StmtKind::Semi(inner_expr) = &last_stmt.kind
336-
&& let ast::ExprKind::Continue(_) = inner_expr.kind
336+
&& let ast::ExprKind::Continue(continue_label) = inner_expr.kind
337+
&& compare_labels(loop_label.as_ref(), continue_label.as_ref())
337338
{
338339
span_lint_and_help(
339340
cx,

tests/ui/needless_continue.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,20 @@ mod issue_2329 {
151151
}
152152
}
153153
}
154+
155+
fn issue_13641() {
156+
'a: while std::hint::black_box(true) {
157+
#[allow(clippy::never_loop)]
158+
loop {
159+
continue 'a;
160+
}
161+
}
162+
163+
#[allow(clippy::never_loop)]
164+
while std::hint::black_box(true) {
165+
'b: loop {
166+
continue 'b;
167+
//~^ ERROR: this `continue` expression is redundant
168+
}
169+
}
170+
}

tests/ui/needless_continue.stderr

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,5 +136,13 @@ LL | | }
136136
println!("bar-5");
137137
}
138138

139-
error: aborting due to 8 previous errors
139+
error: this `continue` expression is redundant
140+
--> tests/ui/needless_continue.rs:166:13
141+
|
142+
LL | continue 'b;
143+
| ^^^^^^^^^^^^
144+
|
145+
= help: consider dropping the `continue` expression
146+
147+
error: aborting due to 9 previous errors
140148

0 commit comments

Comments
 (0)