@@ -273,6 +273,8 @@ struct LintData<'a> {
273273 block_stmts : & ' a [ ast:: Stmt ] ,
274274}
275275
276+ const MSG_REDUNDANT_CONTINUE_EXPRESSION : & str = "this `continue` expression is redundant" ;
277+
276278const MSG_REDUNDANT_ELSE_BLOCK : & str = "this `else` block is redundant" ;
277279
278280const MSG_ELSE_BLOCK_NOT_NEEDED : & str = "there is no need for an explicit `else` block for this `if` \
@@ -283,6 +285,8 @@ const DROP_ELSE_BLOCK_AND_MERGE_MSG: &str = "consider dropping the `else` clause
283285
284286const DROP_ELSE_BLOCK_MSG : & str = "consider dropping the `else` clause" ;
285287
288+ const DROP_CONTINUE_EXPRESSION_MSG : & str = "consider dropping the `continue` expression" ;
289+
286290fn emit_warning < ' a > ( cx : & EarlyContext < ' _ > , data : & ' a LintData < ' _ > , header : & str , typ : LintType ) {
287291 // snip is the whole *help* message that appears after the warning.
288292 // message is the warning message.
@@ -364,6 +368,22 @@ fn suggestion_snippet_for_continue_inside_else<'a>(cx: &EarlyContext<'_>, data:
364368}
365369
366370fn check_and_warn < ' a > ( cx : & EarlyContext < ' _ > , expr : & ' a ast:: Expr ) {
371+ if_chain ! {
372+ if let ast:: ExprKind :: Loop ( loop_block, ..) = & expr. kind;
373+ if loop_block. stmts. len( ) == 1 ;
374+ if let ast:: StmtKind :: Semi ( ref statement) = loop_block. stmts. first( ) . unwrap( ) . kind;
375+ if let ast:: ExprKind :: Continue ( _) = statement. kind;
376+ then {
377+ span_lint_and_help(
378+ cx,
379+ NEEDLESS_CONTINUE ,
380+ loop_block. stmts. first( ) . unwrap( ) . span,
381+ MSG_REDUNDANT_CONTINUE_EXPRESSION ,
382+ None ,
383+ DROP_CONTINUE_EXPRESSION_MSG ,
384+ ) ;
385+ }
386+ }
367387 with_loop_block ( expr, |loop_block, label| {
368388 for ( i, stmt) in loop_block. stmts . iter ( ) . enumerate ( ) {
369389 with_if_expr ( stmt, |if_expr, cond, then_block, else_expr| {
0 commit comments