@@ -95,15 +95,11 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &RemoveUnnecessaryElse) -> Option<Vec<
95
95
96
96
#[ cfg( test) ]
97
97
mod tests {
98
- use crate :: tests:: { check_diagnostics, check_diagnostics_with_disabled, check_fix} ;
99
-
100
- fn check_diagnostics_with_needless_return_disabled ( ra_fixture : & str ) {
101
- check_diagnostics_with_disabled ( ra_fixture, std:: iter:: once ( "needless_return" . to_owned ( ) ) ) ;
102
- }
98
+ use crate :: tests:: { check_diagnostics_with_disabled, check_fix} ;
103
99
104
100
#[ test]
105
101
fn remove_unnecessary_else_for_return ( ) {
106
- check_diagnostics_with_needless_return_disabled (
102
+ check_diagnostics_with_disabled (
107
103
r#"
108
104
fn test() {
109
105
if foo {
@@ -114,6 +110,7 @@ fn test() {
114
110
}
115
111
}
116
112
"# ,
113
+ & [ "needless_return" , "E0425" ] ,
117
114
) ;
118
115
check_fix (
119
116
r#"
@@ -138,7 +135,7 @@ fn test() {
138
135
139
136
#[ test]
140
137
fn remove_unnecessary_else_for_return2 ( ) {
141
- check_diagnostics_with_needless_return_disabled (
138
+ check_diagnostics_with_disabled (
142
139
r#"
143
140
fn test() {
144
141
if foo {
@@ -151,6 +148,7 @@ fn test() {
151
148
}
152
149
}
153
150
"# ,
151
+ & [ "needless_return" , "E0425" ] ,
154
152
) ;
155
153
check_fix (
156
154
r#"
@@ -181,7 +179,7 @@ fn test() {
181
179
182
180
#[ test]
183
181
fn remove_unnecessary_else_for_return3 ( ) {
184
- check_diagnostics_with_needless_return_disabled (
182
+ check_diagnostics_with_disabled (
185
183
r#"
186
184
fn test(a: bool) -> i32 {
187
185
if a {
@@ -192,6 +190,7 @@ fn test(a: bool) -> i32 {
192
190
}
193
191
}
194
192
"# ,
193
+ & [ "needless_return" , "E0425" ] ,
195
194
) ;
196
195
check_fix (
197
196
r#"
@@ -216,7 +215,7 @@ fn test(a: bool) -> i32 {
216
215
217
216
#[ test]
218
217
fn remove_unnecessary_else_for_return_in_child_if_expr ( ) {
219
- check_diagnostics_with_needless_return_disabled (
218
+ check_diagnostics_with_disabled (
220
219
r#"
221
220
fn test() {
222
221
if foo {
@@ -229,6 +228,7 @@ fn test() {
229
228
}
230
229
}
231
230
"# ,
231
+ & [ "needless_return" , "E0425" ] ,
232
232
) ;
233
233
check_fix (
234
234
r#"
@@ -294,7 +294,7 @@ fn test() {
294
294
295
295
#[ test]
296
296
fn remove_unnecessary_else_for_break ( ) {
297
- check_diagnostics (
297
+ check_diagnostics_with_disabled (
298
298
r#"
299
299
fn test() {
300
300
loop {
@@ -307,6 +307,7 @@ fn test() {
307
307
}
308
308
}
309
309
"# ,
310
+ & [ "E0425" ] ,
310
311
) ;
311
312
check_fix (
312
313
r#"
@@ -335,7 +336,7 @@ fn test() {
335
336
336
337
#[ test]
337
338
fn remove_unnecessary_else_for_continue ( ) {
338
- check_diagnostics (
339
+ check_diagnostics_with_disabled (
339
340
r#"
340
341
fn test() {
341
342
loop {
@@ -348,6 +349,7 @@ fn test() {
348
349
}
349
350
}
350
351
"# ,
352
+ & [ "E0425" ] ,
351
353
) ;
352
354
check_fix (
353
355
r#"
@@ -376,7 +378,7 @@ fn test() {
376
378
377
379
#[ test]
378
380
fn remove_unnecessary_else_for_never ( ) {
379
- check_diagnostics (
381
+ check_diagnostics_with_disabled (
380
382
r#"
381
383
fn test() {
382
384
if foo {
@@ -391,6 +393,7 @@ fn never() -> ! {
391
393
loop {}
392
394
}
393
395
"# ,
396
+ & [ "E0425" ] ,
394
397
) ;
395
398
check_fix (
396
399
r#"
@@ -423,7 +426,7 @@ fn never() -> ! {
423
426
424
427
#[ test]
425
428
fn no_diagnostic_if_no_else_branch ( ) {
426
- check_diagnostics (
429
+ check_diagnostics_with_disabled (
427
430
r#"
428
431
fn test() {
429
432
if foo {
@@ -433,12 +436,13 @@ fn test() {
433
436
do_something_else();
434
437
}
435
438
"# ,
439
+ & [ "E0425" ] ,
436
440
) ;
437
441
}
438
442
439
443
#[ test]
440
444
fn no_diagnostic_if_no_divergence ( ) {
441
- check_diagnostics (
445
+ check_diagnostics_with_disabled (
442
446
r#"
443
447
fn test() {
444
448
if foo {
@@ -448,12 +452,13 @@ fn test() {
448
452
}
449
453
}
450
454
"# ,
455
+ & [ "E0425" ] ,
451
456
) ;
452
457
}
453
458
454
459
#[ test]
455
460
fn no_diagnostic_if_no_divergence_in_else_branch ( ) {
456
- check_diagnostics_with_needless_return_disabled (
461
+ check_diagnostics_with_disabled (
457
462
r#"
458
463
fn test() {
459
464
if foo {
@@ -463,12 +468,13 @@ fn test() {
463
468
}
464
469
}
465
470
"# ,
471
+ & [ "needless_return" , "E0425" ] ,
466
472
) ;
467
473
}
468
474
469
475
#[ test]
470
476
fn no_diagnostic_if_not_expr_stmt ( ) {
471
- check_diagnostics_with_needless_return_disabled (
477
+ check_diagnostics_with_disabled (
472
478
r#"
473
479
fn test1() {
474
480
let _x = if a {
@@ -490,13 +496,15 @@ fn test2() {
490
496
};
491
497
}
492
498
"# ,
499
+ & [ "needless_return" , "E0425" ] ,
493
500
) ;
494
- check_diagnostics (
501
+ check_diagnostics_with_disabled (
495
502
r#"
496
503
fn test3() -> u8 {
497
504
foo(if a { return 1 } else { 0 })
498
505
}
499
506
"# ,
507
+ & [ "E0425" ] ,
500
508
) ;
501
509
}
502
510
}
0 commit comments