11use clippy_utils:: diagnostics:: span_lint_and_help;
2- use clippy_utils:: source:: { indent_of, snippet , snippet_block, snippet_with_context} ;
2+ use clippy_utils:: source:: { indent_of, snippet_block, snippet_with_context} ;
33use clippy_utils:: { higher, is_from_proc_macro} ;
44use rustc_ast:: Label ;
55use rustc_errors:: Applicability ;
@@ -193,15 +193,15 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessContinue {
193193/// - The expression node is a block with the first statement being a `continue`.
194194fn needless_continue_in_else ( else_expr : & Expr < ' _ > , label : Option < & Label > ) -> bool {
195195 match else_expr. kind {
196- ExprKind :: Block ( ref else_block, _) => is_first_block_stmt_continue ( else_block, label) ,
196+ ExprKind :: Block ( else_block, _) => is_first_block_stmt_continue ( else_block, label) ,
197197 ExprKind :: Continue ( l) => compare_labels ( label, l. label . as_ref ( ) ) ,
198198 _ => false ,
199199 }
200200}
201201
202202fn is_first_block_stmt_continue ( block : & Block < ' _ > , label : Option < & Label > ) -> bool {
203203 block. stmts . first ( ) . is_some_and ( |stmt| match stmt. kind {
204- StmtKind :: Semi ( ref e) | StmtKind :: Expr ( ref e) => {
204+ StmtKind :: Semi ( e) | StmtKind :: Expr ( e) => {
205205 if let ExprKind :: Continue ( ref l) = e. kind {
206206 compare_labels ( label, l. label . as_ref ( ) )
207207 } else {
@@ -366,7 +366,14 @@ fn suggestion_snippet_for_continue_inside_if(cx: &LateContext<'_>, data: &LintDa
366366}
367367
368368fn suggestion_snippet_for_continue_inside_else ( cx : & LateContext < ' _ > , data : & LintData < ' _ > ) -> String {
369- let cond_code = snippet ( cx, data. if_cond . span , ".." ) ;
369+ let mut applicability = Applicability :: MachineApplicable ;
370+ let ( cond_code, _) = snippet_with_context (
371+ cx,
372+ data. if_cond . span ,
373+ data. if_expr . span . ctxt ( ) ,
374+ ".." ,
375+ & mut applicability,
376+ ) ;
370377
371378 // Region B
372379 let block_code = erode_from_back ( & snippet_block ( cx, data. if_block . span , ".." , Some ( data. if_expr . span ) ) ) ;
@@ -402,7 +409,7 @@ fn suggestion_snippet_for_continue_inside_else(cx: &LateContext<'_>, data: &Lint
402409 }
403410 lines. join ( "\n " )
404411 } else {
405- "" . to_string ( )
412+ String :: new ( )
406413 } ;
407414
408415 let indent_if = indent_of ( cx, data. if_expr . span ) . unwrap_or ( 0 ) ;
@@ -417,7 +424,7 @@ fn check_last_stmt_in_expr<F>(cx: &LateContext<'_>, inner_expr: &Expr<'_>, func:
417424where
418425 F : Fn ( Option < & Label > , Span ) ,
419426{
420- match & inner_expr. kind {
427+ match inner_expr. kind {
421428 ExprKind :: Continue ( continue_label) => {
422429 func ( continue_label. label . as_ref ( ) , inner_expr. span ) ;
423430 } ,
@@ -432,7 +439,7 @@ where
432439 if !match_ty. is_unit ( ) && !match_ty. is_never ( ) {
433440 return ;
434441 }
435- for arm in arms. iter ( ) {
442+ for arm in arms {
436443 check_last_stmt_in_expr ( cx, arm. body , func) ;
437444 }
438445 } ,
0 commit comments