1
1
use 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} ;
3
3
use clippy_utils:: { higher, is_from_proc_macro} ;
4
4
use rustc_ast:: Label ;
5
5
use rustc_errors:: Applicability ;
@@ -193,15 +193,15 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessContinue {
193
193
/// - The expression node is a block with the first statement being a `continue`.
194
194
fn needless_continue_in_else ( else_expr : & Expr < ' _ > , label : Option < & Label > ) -> bool {
195
195
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) ,
197
197
ExprKind :: Continue ( l) => compare_labels ( label, l. label . as_ref ( ) ) ,
198
198
_ => false ,
199
199
}
200
200
}
201
201
202
202
fn is_first_block_stmt_continue ( block : & Block < ' _ > , label : Option < & Label > ) -> bool {
203
203
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) => {
205
205
if let ExprKind :: Continue ( ref l) = e. kind {
206
206
compare_labels ( label, l. label . as_ref ( ) )
207
207
} else {
@@ -366,7 +366,14 @@ fn suggestion_snippet_for_continue_inside_if(cx: &LateContext<'_>, data: &LintDa
366
366
}
367
367
368
368
fn 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
+ ) ;
370
377
371
378
// Region B
372
379
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
402
409
}
403
410
lines. join ( "\n " )
404
411
} else {
405
- "" . to_string ( )
412
+ String :: new ( )
406
413
} ;
407
414
408
415
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:
417
424
where
418
425
F : Fn ( Option < & Label > , Span ) ,
419
426
{
420
- match & inner_expr. kind {
427
+ match inner_expr. kind {
421
428
ExprKind :: Continue ( continue_label) => {
422
429
func ( continue_label. label . as_ref ( ) , inner_expr. span ) ;
423
430
} ,
@@ -432,7 +439,7 @@ where
432
439
if !match_ty. is_unit ( ) && !match_ty. is_never ( ) {
433
440
return ;
434
441
}
435
- for arm in arms. iter ( ) {
442
+ for arm in arms {
436
443
check_last_stmt_in_expr ( cx, arm. body , func) ;
437
444
}
438
445
} ,
0 commit comments