@@ -119,9 +119,9 @@ declare_clippy_lint! {
119
119
declare_lint_pass ! ( NeedlessContinue => [ NEEDLESS_CONTINUE ] ) ;
120
120
121
121
impl EarlyLintPass for NeedlessContinue {
122
- fn check_expr ( & mut self , ctx : & EarlyContext < ' _ > , expr : & ast:: Expr ) {
122
+ fn check_expr ( & mut self , cx : & EarlyContext < ' _ > , expr : & ast:: Expr ) {
123
123
if !expr. span . from_expansion ( ) {
124
- check_and_warn ( ctx , expr) ;
124
+ check_and_warn ( cx , expr) ;
125
125
}
126
126
}
127
127
}
@@ -283,39 +283,39 @@ const DROP_ELSE_BLOCK_AND_MERGE_MSG: &str = "consider dropping the `else` clause
283
283
284
284
const DROP_ELSE_BLOCK_MSG : & str = "consider dropping the `else` clause" ;
285
285
286
- fn emit_warning < ' a > ( ctx : & EarlyContext < ' _ > , data : & ' a LintData < ' _ > , header : & str , typ : LintType ) {
286
+ fn emit_warning < ' a > ( cx : & EarlyContext < ' _ > , data : & ' a LintData < ' _ > , header : & str , typ : LintType ) {
287
287
// snip is the whole *help* message that appears after the warning.
288
288
// message is the warning message.
289
289
// expr is the expression which the lint warning message refers to.
290
290
let ( snip, message, expr) = match typ {
291
291
LintType :: ContinueInsideElseBlock => (
292
- suggestion_snippet_for_continue_inside_else ( ctx , data) ,
292
+ suggestion_snippet_for_continue_inside_else ( cx , data) ,
293
293
MSG_REDUNDANT_ELSE_BLOCK ,
294
294
data. else_expr ,
295
295
) ,
296
296
LintType :: ContinueInsideThenBlock => (
297
- suggestion_snippet_for_continue_inside_if ( ctx , data) ,
297
+ suggestion_snippet_for_continue_inside_if ( cx , data) ,
298
298
MSG_ELSE_BLOCK_NOT_NEEDED ,
299
299
data. if_expr ,
300
300
) ,
301
301
} ;
302
302
span_lint_and_help (
303
- ctx ,
303
+ cx ,
304
304
NEEDLESS_CONTINUE ,
305
305
expr. span ,
306
306
message,
307
307
& format ! ( "{}\n {}" , header, snip) ,
308
308
) ;
309
309
}
310
310
311
- fn suggestion_snippet_for_continue_inside_if < ' a > ( ctx : & EarlyContext < ' _ > , data : & ' a LintData < ' _ > ) -> String {
312
- let cond_code = snippet ( ctx , data. if_cond . span , ".." ) ;
311
+ fn suggestion_snippet_for_continue_inside_if < ' a > ( cx : & EarlyContext < ' _ > , data : & ' a LintData < ' _ > ) -> String {
312
+ let cond_code = snippet ( cx , data. if_cond . span , ".." ) ;
313
313
314
- let continue_code = snippet_block ( ctx , data. if_block . span , ".." , Some ( data. if_expr . span ) ) ;
314
+ let continue_code = snippet_block ( cx , data. if_block . span , ".." , Some ( data. if_expr . span ) ) ;
315
315
316
- let else_code = snippet_block ( ctx , data. else_expr . span , ".." , Some ( data. if_expr . span ) ) ;
316
+ let else_code = snippet_block ( cx , data. else_expr . span , ".." , Some ( data. if_expr . span ) ) ;
317
317
318
- let indent_if = indent_of ( ctx , data. if_expr . span ) . unwrap_or ( 0 ) ;
318
+ let indent_if = indent_of ( cx , data. if_expr . span ) . unwrap_or ( 0 ) ;
319
319
format ! (
320
320
"{indent}if {} {}\n {indent}{}" ,
321
321
cond_code,
@@ -325,24 +325,24 @@ fn suggestion_snippet_for_continue_inside_if<'a>(ctx: &EarlyContext<'_>, data: &
325
325
)
326
326
}
327
327
328
- fn suggestion_snippet_for_continue_inside_else < ' a > ( ctx : & EarlyContext < ' _ > , data : & ' a LintData < ' _ > ) -> String {
329
- let cond_code = snippet ( ctx , data. if_cond . span , ".." ) ;
328
+ fn suggestion_snippet_for_continue_inside_else < ' a > ( cx : & EarlyContext < ' _ > , data : & ' a LintData < ' _ > ) -> String {
329
+ let cond_code = snippet ( cx , data. if_cond . span , ".." ) ;
330
330
331
331
// Region B
332
- let block_code = erode_from_back ( & snippet_block ( ctx , data. if_block . span , ".." , Some ( data. if_expr . span ) ) ) ;
332
+ let block_code = erode_from_back ( & snippet_block ( cx , data. if_block . span , ".." , Some ( data. if_expr . span ) ) ) ;
333
333
334
334
// Region C
335
335
// These is the code in the loop block that follows the if/else construction
336
336
// we are complaining about. We want to pull all of this code into the
337
337
// `then` block of the `if` statement.
338
338
let indent = span_of_first_expr_in_block ( data. if_block )
339
- . and_then ( |span| indent_of ( ctx , span) )
339
+ . and_then ( |span| indent_of ( cx , span) )
340
340
. unwrap_or ( 0 ) ;
341
341
let to_annex = data. block_stmts [ data. stmt_idx + 1 ..]
342
342
. iter ( )
343
343
. map ( |stmt| original_sp ( stmt. span , DUMMY_SP ) )
344
344
. map ( |span| {
345
- let snip = snippet_block ( ctx , span, ".." , None ) . into_owned ( ) ;
345
+ let snip = snippet_block ( cx , span, ".." , None ) . into_owned ( ) ;
346
346
snip. lines ( )
347
347
. map ( |line| format ! ( "{}{}" , " " . repeat( indent) , line) )
348
348
. collect :: < Vec < _ > > ( )
@@ -351,7 +351,7 @@ fn suggestion_snippet_for_continue_inside_else<'a>(ctx: &EarlyContext<'_>, data:
351
351
. collect :: < Vec < _ > > ( )
352
352
. join ( "\n " ) ;
353
353
354
- let indent_if = indent_of ( ctx , data. if_expr . span ) . unwrap_or ( 0 ) ;
354
+ let indent_if = indent_of ( cx , data. if_expr . span ) . unwrap_or ( 0 ) ;
355
355
format ! (
356
356
"{indent_if}if {} {}\n {indent}// merged code follows:\n {}\n {indent_if}}}" ,
357
357
cond_code,
@@ -362,7 +362,7 @@ fn suggestion_snippet_for_continue_inside_else<'a>(ctx: &EarlyContext<'_>, data:
362
362
)
363
363
}
364
364
365
- fn check_and_warn < ' a > ( ctx : & EarlyContext < ' _ > , expr : & ' a ast:: Expr ) {
365
+ fn check_and_warn < ' a > ( cx : & EarlyContext < ' _ > , expr : & ' a ast:: Expr ) {
366
366
with_loop_block ( expr, |loop_block, label| {
367
367
for ( i, stmt) in loop_block. stmts . iter ( ) . enumerate ( ) {
368
368
with_if_expr ( stmt, |if_expr, cond, then_block, else_expr| {
@@ -376,13 +376,13 @@ fn check_and_warn<'a>(ctx: &EarlyContext<'_>, expr: &'a ast::Expr) {
376
376
} ;
377
377
if needless_continue_in_else ( else_expr, label) {
378
378
emit_warning (
379
- ctx ,
379
+ cx ,
380
380
data,
381
381
DROP_ELSE_BLOCK_AND_MERGE_MSG ,
382
382
LintType :: ContinueInsideElseBlock ,
383
383
) ;
384
384
} else if is_first_block_stmt_continue ( then_block, label) {
385
- emit_warning ( ctx , data, DROP_ELSE_BLOCK_MSG , LintType :: ContinueInsideThenBlock ) ;
385
+ emit_warning ( cx , data, DROP_ELSE_BLOCK_MSG , LintType :: ContinueInsideThenBlock ) ;
386
386
}
387
387
} ) ;
388
388
}
0 commit comments