aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/assists/src/handlers/wrap_return_type_in_result.rs1203
1 files changed, 635 insertions, 568 deletions
diff --git a/crates/assists/src/handlers/wrap_return_type_in_result.rs b/crates/assists/src/handlers/wrap_return_type_in_result.rs
index e08981f89..59e5debb1 100644
--- a/crates/assists/src/handlers/wrap_return_type_in_result.rs
+++ b/crates/assists/src/handlers/wrap_return_type_in_result.rs
@@ -281,14 +281,18 @@ mod tests {
281 fn wrap_return_type_in_result_simple() { 281 fn wrap_return_type_in_result_simple() {
282 check_assist( 282 check_assist(
283 wrap_return_type_in_result, 283 wrap_return_type_in_result,
284 r#"fn foo() -> i3<|>2 { 284 r#"
285 let test = "test"; 285fn foo() -> i3<|>2 {
286 return 42i32; 286 let test = "test";
287 }"#, 287 return 42i32;
288 r#"fn foo() -> Result<i32, ${0:_}> { 288}
289 let test = "test"; 289"#,
290 return Ok(42i32); 290 r#"
291 }"#, 291fn foo() -> Result<i32, ${0:_}> {
292 let test = "test";
293 return Ok(42i32);
294}
295"#,
292 ); 296 );
293 } 297 }
294 298
@@ -296,18 +300,22 @@ mod tests {
296 fn wrap_return_type_in_result_simple_closure() { 300 fn wrap_return_type_in_result_simple_closure() {
297 check_assist( 301 check_assist(
298 wrap_return_type_in_result, 302 wrap_return_type_in_result,
299 r#"fn foo() { 303 r#"
300 || -> i32<|> { 304fn foo() {
301 let test = "test"; 305 || -> i32<|> {
302 return 42i32; 306 let test = "test";
303 }; 307 return 42i32;
304 }"#, 308 };
305 r#"fn foo() { 309}
306 || -> Result<i32, ${0:_}> { 310"#,
307 let test = "test"; 311 r#"
308 return Ok(42i32); 312fn foo() {
309 }; 313 || -> Result<i32, ${0:_}> {
310 }"#, 314 let test = "test";
315 return Ok(42i32);
316 };
317}
318"#,
311 ); 319 );
312 } 320 }
313 321
@@ -315,10 +323,12 @@ mod tests {
315 fn wrap_return_type_in_result_simple_return_type_bad_cursor() { 323 fn wrap_return_type_in_result_simple_return_type_bad_cursor() {
316 check_assist_not_applicable( 324 check_assist_not_applicable(
317 wrap_return_type_in_result, 325 wrap_return_type_in_result,
318 r#"fn foo() -> i32 { 326 r#"
319 let test = "test";<|> 327fn foo() -> i32 {
320 return 42i32; 328 let test = "test";<|>
321 }"#, 329 return 42i32;
330}
331"#,
322 ); 332 );
323 } 333 }
324 334
@@ -326,33 +336,32 @@ mod tests {
326 fn wrap_return_type_in_result_simple_return_type_bad_cursor_closure() { 336 fn wrap_return_type_in_result_simple_return_type_bad_cursor_closure() {
327 check_assist_not_applicable( 337 check_assist_not_applicable(
328 wrap_return_type_in_result, 338 wrap_return_type_in_result,
329 r#"fn foo() { 339 r#"
330 || -> i32 { 340fn foo() {
331 let test = "test";<|> 341 || -> i32 {
332 return 42i32; 342 let test = "test";<|>
333 }; 343 return 42i32;
334 }"#, 344 };
345}
346"#,
335 ); 347 );
336 } 348 }
337 349
338 #[test] 350 #[test]
339 fn wrap_return_type_in_result_closure_non_block() { 351 fn wrap_return_type_in_result_closure_non_block() {
340 check_assist_not_applicable( 352 check_assist_not_applicable(wrap_return_type_in_result, r#"fn foo() { || -> i<|>32 3; }"#);
341 wrap_return_type_in_result,
342 r#"fn foo() {
343 || -> i<|>32 3;
344 }"#,
345 );
346 } 353 }
347 354
348 #[test] 355 #[test]
349 fn wrap_return_type_in_result_simple_return_type_already_result_std() { 356 fn wrap_return_type_in_result_simple_return_type_already_result_std() {
350 check_assist_not_applicable( 357 check_assist_not_applicable(
351 wrap_return_type_in_result, 358 wrap_return_type_in_result,
352 r#"fn foo() -> std::result::Result<i32<|>, String> { 359 r#"
353 let test = "test"; 360fn foo() -> std::result::Result<i32<|>, String> {
354 return 42i32; 361 let test = "test";
355 }"#, 362 return 42i32;
363}
364"#,
356 ); 365 );
357 } 366 }
358 367
@@ -361,10 +370,12 @@ mod tests {
361 mark::check!(wrap_return_type_in_result_simple_return_type_already_result); 370 mark::check!(wrap_return_type_in_result_simple_return_type_already_result);
362 check_assist_not_applicable( 371 check_assist_not_applicable(
363 wrap_return_type_in_result, 372 wrap_return_type_in_result,
364 r#"fn foo() -> Result<i32<|>, String> { 373 r#"
365 let test = "test"; 374fn foo() -> Result<i32<|>, String> {
366 return 42i32; 375 let test = "test";
367 }"#, 376 return 42i32;
377}
378"#,
368 ); 379 );
369 } 380 }
370 381
@@ -372,12 +383,14 @@ mod tests {
372 fn wrap_return_type_in_result_simple_return_type_already_result_closure() { 383 fn wrap_return_type_in_result_simple_return_type_already_result_closure() {
373 check_assist_not_applicable( 384 check_assist_not_applicable(
374 wrap_return_type_in_result, 385 wrap_return_type_in_result,
375 r#"fn foo() { 386 r#"
376 || -> Result<i32<|>, String> { 387fn foo() {
377 let test = "test"; 388 || -> Result<i32<|>, String> {
378 return 42i32; 389 let test = "test";
379 }; 390 return 42i32;
380 }"#, 391 };
392}
393"#,
381 ); 394 );
382 } 395 }
383 396
@@ -385,14 +398,18 @@ mod tests {
385 fn wrap_return_type_in_result_simple_with_cursor() { 398 fn wrap_return_type_in_result_simple_with_cursor() {
386 check_assist( 399 check_assist(
387 wrap_return_type_in_result, 400 wrap_return_type_in_result,
388 r#"fn foo() -> <|>i32 { 401 r#"
389 let test = "test"; 402fn foo() -> <|>i32 {
390 return 42i32; 403 let test = "test";
391 }"#, 404 return 42i32;
392 r#"fn foo() -> Result<i32, ${0:_}> { 405}
393 let test = "test"; 406"#,
394 return Ok(42i32); 407 r#"
395 }"#, 408fn foo() -> Result<i32, ${0:_}> {
409 let test = "test";
410 return Ok(42i32);
411}
412"#,
396 ); 413 );
397 } 414 }
398 415
@@ -400,14 +417,18 @@ mod tests {
400 fn wrap_return_type_in_result_simple_with_tail() { 417 fn wrap_return_type_in_result_simple_with_tail() {
401 check_assist( 418 check_assist(
402 wrap_return_type_in_result, 419 wrap_return_type_in_result,
403 r#"fn foo() -><|> i32 { 420 r#"
404 let test = "test"; 421fn foo() -><|> i32 {
405 42i32 422 let test = "test";
406 }"#, 423 42i32
407 r#"fn foo() -> Result<i32, ${0:_}> { 424}
408 let test = "test"; 425"#,
409 Ok(42i32) 426 r#"
410 }"#, 427fn foo() -> Result<i32, ${0:_}> {
428 let test = "test";
429 Ok(42i32)
430}
431"#,
411 ); 432 );
412 } 433 }
413 434
@@ -415,18 +436,22 @@ mod tests {
415 fn wrap_return_type_in_result_simple_with_tail_closure() { 436 fn wrap_return_type_in_result_simple_with_tail_closure() {
416 check_assist( 437 check_assist(
417 wrap_return_type_in_result, 438 wrap_return_type_in_result,
418 r#"fn foo() { 439 r#"
419 || -><|> i32 { 440fn foo() {
420 let test = "test"; 441 || -><|> i32 {
421 42i32 442 let test = "test";
422 }; 443 42i32
423 }"#, 444 };
424 r#"fn foo() { 445}
425 || -> Result<i32, ${0:_}> { 446"#,
426 let test = "test"; 447 r#"
427 Ok(42i32) 448fn foo() {
428 }; 449 || -> Result<i32, ${0:_}> {
429 }"#, 450 let test = "test";
451 Ok(42i32)
452 };
453}
454"#,
430 ); 455 );
431 } 456 }
432 457
@@ -434,12 +459,8 @@ mod tests {
434 fn wrap_return_type_in_result_simple_with_tail_only() { 459 fn wrap_return_type_in_result_simple_with_tail_only() {
435 check_assist( 460 check_assist(
436 wrap_return_type_in_result, 461 wrap_return_type_in_result,
437 r#"fn foo() -> i32<|> { 462 r#"fn foo() -> i32<|> { 42i32 }"#,
438 42i32 463 r#"fn foo() -> Result<i32, ${0:_}> { Ok(42i32) }"#,
439 }"#,
440 r#"fn foo() -> Result<i32, ${0:_}> {
441 Ok(42i32)
442 }"#,
443 ); 464 );
444 } 465 }
445 466
@@ -447,20 +468,24 @@ mod tests {
447 fn wrap_return_type_in_result_simple_with_tail_block_like() { 468 fn wrap_return_type_in_result_simple_with_tail_block_like() {
448 check_assist( 469 check_assist(
449 wrap_return_type_in_result, 470 wrap_return_type_in_result,
450 r#"fn foo() -> i32<|> { 471 r#"
451 if true { 472fn foo() -> i32<|> {
452 42i32 473 if true {
453 } else { 474 42i32
454 24i32 475 } else {
455 } 476 24i32
456 }"#, 477 }
457 r#"fn foo() -> Result<i32, ${0:_}> { 478}
458 if true { 479"#,
459 Ok(42i32) 480 r#"
460 } else { 481fn foo() -> Result<i32, ${0:_}> {
461 Ok(24i32) 482 if true {
462 } 483 Ok(42i32)
463 }"#, 484 } else {
485 Ok(24i32)
486 }
487}
488"#,
464 ); 489 );
465 } 490 }
466 491
@@ -468,24 +493,28 @@ mod tests {
468 fn wrap_return_type_in_result_simple_without_block_closure() { 493 fn wrap_return_type_in_result_simple_without_block_closure() {
469 check_assist( 494 check_assist(
470 wrap_return_type_in_result, 495 wrap_return_type_in_result,
471 r#"fn foo() { 496 r#"
472 || -> i32<|> { 497fn foo() {
473 if true { 498 || -> i32<|> {
474 42i32 499 if true {
475 } else { 500 42i32
476 24i32 501 } else {
477 } 502 24i32
478 }; 503 }
479 }"#, 504 };
480 r#"fn foo() { 505}
481 || -> Result<i32, ${0:_}> { 506"#,
482 if true { 507 r#"
483 Ok(42i32) 508fn foo() {
484 } else { 509 || -> Result<i32, ${0:_}> {
485 Ok(24i32) 510 if true {
486 } 511 Ok(42i32)
487 }; 512 } else {
488 }"#, 513 Ok(24i32)
514 }
515 };
516}
517"#,
489 ); 518 );
490 } 519 }
491 520
@@ -493,28 +522,32 @@ mod tests {
493 fn wrap_return_type_in_result_simple_with_nested_if() { 522 fn wrap_return_type_in_result_simple_with_nested_if() {
494 check_assist( 523 check_assist(
495 wrap_return_type_in_result, 524 wrap_return_type_in_result,
496 r#"fn foo() -> i32<|> { 525 r#"
497 if true { 526fn foo() -> i32<|> {
498 if false { 527 if true {
499 1 528 if false {
500 } else { 529 1
501 2 530 } else {
502 } 531 2
503 } else { 532 }
504 24i32 533 } else {
505 } 534 24i32
506 }"#, 535 }
507 r#"fn foo() -> Result<i32, ${0:_}> { 536}
508 if true { 537"#,
509 if false { 538 r#"
510 Ok(1) 539fn foo() -> Result<i32, ${0:_}> {
511 } else { 540 if true {
512 Ok(2) 541 if false {
513 } 542 Ok(1)
514 } else { 543 } else {
515 Ok(24i32) 544 Ok(2)
516 } 545 }
517 }"#, 546 } else {
547 Ok(24i32)
548 }
549}
550"#,
518 ); 551 );
519 } 552 }
520 553
@@ -522,28 +555,32 @@ mod tests {
522 fn wrap_return_type_in_result_simple_with_await() { 555 fn wrap_return_type_in_result_simple_with_await() {
523 check_assist( 556 check_assist(
524 wrap_return_type_in_result, 557 wrap_return_type_in_result,
525 r#"async fn foo() -> i<|>32 { 558 r#"
526 if true { 559async fn foo() -> i<|>32 {
527 if false { 560 if true {
528 1.await 561 if false {
529 } else { 562 1.await
530 2.await 563 } else {
531 } 564 2.await
532 } else { 565 }
533 24i32.await 566 } else {
534 } 567 24i32.await
535 }"#, 568 }
536 r#"async fn foo() -> Result<i32, ${0:_}> { 569}
537 if true { 570"#,
538 if false { 571 r#"
539 Ok(1.await) 572async fn foo() -> Result<i32, ${0:_}> {
540 } else { 573 if true {
541 Ok(2.await) 574 if false {
542 } 575 Ok(1.await)
543 } else { 576 } else {
544 Ok(24i32.await) 577 Ok(2.await)
545 } 578 }
546 }"#, 579 } else {
580 Ok(24i32.await)
581 }
582}
583"#,
547 ); 584 );
548 } 585 }
549 586
@@ -551,12 +588,8 @@ mod tests {
551 fn wrap_return_type_in_result_simple_with_array() { 588 fn wrap_return_type_in_result_simple_with_array() {
552 check_assist( 589 check_assist(
553 wrap_return_type_in_result, 590 wrap_return_type_in_result,
554 r#"fn foo() -> [i32;<|> 3] { 591 r#"fn foo() -> [i32;<|> 3] { [1, 2, 3] }"#,
555 [1, 2, 3] 592 r#"fn foo() -> Result<[i32; 3], ${0:_}> { Ok([1, 2, 3]) }"#,
556 }"#,
557 r#"fn foo() -> Result<[i32; 3], ${0:_}> {
558 Ok([1, 2, 3])
559 }"#,
560 ); 593 );
561 } 594 }
562 595
@@ -564,28 +597,32 @@ mod tests {
564 fn wrap_return_type_in_result_simple_with_cast() { 597 fn wrap_return_type_in_result_simple_with_cast() {
565 check_assist( 598 check_assist(
566 wrap_return_type_in_result, 599 wrap_return_type_in_result,
567 r#"fn foo() -<|>> i32 { 600 r#"
568 if true { 601fn foo() -<|>> i32 {
569 if false { 602 if true {
570 1 as i32 603 if false {
571 } else { 604 1 as i32
572 2 as i32 605 } else {
573 } 606 2 as i32
574 } else { 607 }
575 24 as i32 608 } else {
576 } 609 24 as i32
577 }"#, 610 }
578 r#"fn foo() -> Result<i32, ${0:_}> { 611}
579 if true { 612"#,
580 if false { 613 r#"
581 Ok(1 as i32) 614fn foo() -> Result<i32, ${0:_}> {
582 } else { 615 if true {
583 Ok(2 as i32) 616 if false {
584 } 617 Ok(1 as i32)
585 } else { 618 } else {
586 Ok(24 as i32) 619 Ok(2 as i32)
587 } 620 }
588 }"#, 621 } else {
622 Ok(24 as i32)
623 }
624}
625"#,
589 ); 626 );
590 } 627 }
591 628
@@ -593,20 +630,24 @@ mod tests {
593 fn wrap_return_type_in_result_simple_with_tail_block_like_match() { 630 fn wrap_return_type_in_result_simple_with_tail_block_like_match() {
594 check_assist( 631 check_assist(
595 wrap_return_type_in_result, 632 wrap_return_type_in_result,
596 r#"fn foo() -> i32<|> { 633 r#"
597 let my_var = 5; 634fn foo() -> i32<|> {
598 match my_var { 635 let my_var = 5;
599 5 => 42i32, 636 match my_var {
600 _ => 24i32, 637 5 => 42i32,
601 } 638 _ => 24i32,
602 }"#, 639 }
603 r#"fn foo() -> Result<i32, ${0:_}> { 640}
604 let my_var = 5; 641"#,
605 match my_var { 642 r#"
606 5 => Ok(42i32), 643fn foo() -> Result<i32, ${0:_}> {
607 _ => Ok(24i32), 644 let my_var = 5;
608 } 645 match my_var {
609 }"#, 646 5 => Ok(42i32),
647 _ => Ok(24i32),
648 }
649}
650"#,
610 ); 651 );
611 } 652 }
612 653
@@ -614,24 +655,26 @@ mod tests {
614 fn wrap_return_type_in_result_simple_with_loop_with_tail() { 655 fn wrap_return_type_in_result_simple_with_loop_with_tail() {
615 check_assist( 656 check_assist(
616 wrap_return_type_in_result, 657 wrap_return_type_in_result,
617 r#"fn foo() -> i32<|> { 658 r#"
618 let my_var = 5; 659fn foo() -> i32<|> {
619 loop { 660 let my_var = 5;
620 println!("test"); 661 loop {
621 5 662 println!("test");
622 } 663 5
623 664 }
624 my_var 665 my_var
625 }"#, 666}
626 r#"fn foo() -> Result<i32, ${0:_}> { 667"#,
627 let my_var = 5; 668 r#"
628 loop { 669fn foo() -> Result<i32, ${0:_}> {
629 println!("test"); 670 let my_var = 5;
630 5 671 loop {
631 } 672 println!("test");
632 673 5
633 Ok(my_var) 674 }
634 }"#, 675 Ok(my_var)
676}
677"#,
635 ); 678 );
636 } 679 }
637 680
@@ -639,20 +682,22 @@ mod tests {
639 fn wrap_return_type_in_result_simple_with_loop_in_let_stmt() { 682 fn wrap_return_type_in_result_simple_with_loop_in_let_stmt() {
640 check_assist( 683 check_assist(
641 wrap_return_type_in_result, 684 wrap_return_type_in_result,
642 r#"fn foo() -> i32<|> { 685 r#"
643 let my_var = let x = loop { 686fn foo() -> i32<|> {
644 break 1; 687 let my_var = let x = loop {
645 }; 688 break 1;
646 689 };
647 my_var 690 my_var
648 }"#, 691}
649 r#"fn foo() -> Result<i32, ${0:_}> { 692"#,
650 let my_var = let x = loop { 693 r#"
651 break 1; 694fn foo() -> Result<i32, ${0:_}> {
652 }; 695 let my_var = let x = loop {
653 696 break 1;
654 Ok(my_var) 697 };
655 }"#, 698 Ok(my_var)
699}
700"#,
656 ); 701 );
657 } 702 }
658 703
@@ -660,48 +705,52 @@ mod tests {
660 fn wrap_return_type_in_result_simple_with_tail_block_like_match_return_expr() { 705 fn wrap_return_type_in_result_simple_with_tail_block_like_match_return_expr() {
661 check_assist( 706 check_assist(
662 wrap_return_type_in_result, 707 wrap_return_type_in_result,
663 r#"fn foo() -> i32<|> { 708 r#"
664 let my_var = 5; 709fn foo() -> i32<|> {
665 let res = match my_var { 710 let my_var = 5;
666 5 => 42i32, 711 let res = match my_var {
667 _ => return 24i32, 712 5 => 42i32,
668 }; 713 _ => return 24i32,
669 714 };
670 res 715 res
671 }"#, 716}
672 r#"fn foo() -> Result<i32, ${0:_}> { 717"#,
673 let my_var = 5; 718 r#"
674 let res = match my_var { 719fn foo() -> Result<i32, ${0:_}> {
675 5 => 42i32, 720 let my_var = 5;
676 _ => return Ok(24i32), 721 let res = match my_var {
677 }; 722 5 => 42i32,
678 723 _ => return Ok(24i32),
679 Ok(res) 724 };
680 }"#, 725 Ok(res)
726}
727"#,
681 ); 728 );
682 729
683 check_assist( 730 check_assist(
684 wrap_return_type_in_result, 731 wrap_return_type_in_result,
685 r#"fn foo() -> i32<|> { 732 r#"
686 let my_var = 5; 733fn foo() -> i32<|> {
687 let res = if my_var == 5 { 734 let my_var = 5;
688 42i32 735 let res = if my_var == 5 {
689 } else { 736 42i32
690 return 24i32; 737 } else {
691 }; 738 return 24i32;
692 739 };
693 res 740 res
694 }"#, 741}
695 r#"fn foo() -> Result<i32, ${0:_}> { 742"#,
696 let my_var = 5; 743 r#"
697 let res = if my_var == 5 { 744fn foo() -> Result<i32, ${0:_}> {
698 42i32 745 let my_var = 5;
699 } else { 746 let res = if my_var == 5 {
700 return Ok(24i32); 747 42i32
701 }; 748 } else {
702 749 return Ok(24i32);
703 Ok(res) 750 };
704 }"#, 751 Ok(res)
752}
753"#,
705 ); 754 );
706 } 755 }
707 756
@@ -709,44 +758,48 @@ mod tests {
709 fn wrap_return_type_in_result_simple_with_tail_block_like_match_deeper() { 758 fn wrap_return_type_in_result_simple_with_tail_block_like_match_deeper() {
710 check_assist( 759 check_assist(
711 wrap_return_type_in_result, 760 wrap_return_type_in_result,
712 r#"fn foo() -> i32<|> { 761 r#"
713 let my_var = 5; 762fn foo() -> i32<|> {
714 match my_var { 763 let my_var = 5;
715 5 => { 764 match my_var {
716 if true { 765 5 => {
717 42i32 766 if true {
718 } else { 767 42i32
719 25i32 768 } else {
720 } 769 25i32
721 }, 770 }
722 _ => { 771 },
723 let test = "test"; 772 _ => {
724 if test == "test" { 773 let test = "test";
725 return bar(); 774 if test == "test" {
726 } 775 return bar();
727 53i32 776 }
728 }, 777 53i32
729 } 778 },
730 }"#, 779 }
731 r#"fn foo() -> Result<i32, ${0:_}> { 780}
732 let my_var = 5; 781"#,
733 match my_var { 782 r#"
734 5 => { 783fn foo() -> Result<i32, ${0:_}> {
735 if true { 784 let my_var = 5;
736 Ok(42i32) 785 match my_var {
737 } else { 786 5 => {
738 Ok(25i32) 787 if true {
739 } 788 Ok(42i32)
740 }, 789 } else {
741 _ => { 790 Ok(25i32)
742 let test = "test"; 791 }
743 if test == "test" { 792 },
744 return Ok(bar()); 793 _ => {
745 } 794 let test = "test";
746 Ok(53i32) 795 if test == "test" {
747 }, 796 return Ok(bar());
748 } 797 }
749 }"#, 798 Ok(53i32)
799 },
800 }
801}
802"#,
750 ); 803 );
751 } 804 }
752 805
@@ -754,20 +807,24 @@ mod tests {
754 fn wrap_return_type_in_result_simple_with_tail_block_like_early_return() { 807 fn wrap_return_type_in_result_simple_with_tail_block_like_early_return() {
755 check_assist( 808 check_assist(
756 wrap_return_type_in_result, 809 wrap_return_type_in_result,
757 r#"fn foo() -> i<|>32 { 810 r#"
758 let test = "test"; 811fn foo() -> i<|>32 {
759 if test == "test" { 812 let test = "test";
760 return 24i32; 813 if test == "test" {
761 } 814 return 24i32;
762 53i32 815 }
763 }"#, 816 53i32
764 r#"fn foo() -> Result<i32, ${0:_}> { 817}
765 let test = "test"; 818"#,
766 if test == "test" { 819 r#"
767 return Ok(24i32); 820fn foo() -> Result<i32, ${0:_}> {
768 } 821 let test = "test";
769 Ok(53i32) 822 if test == "test" {
770 }"#, 823 return Ok(24i32);
824 }
825 Ok(53i32)
826}
827"#,
771 ); 828 );
772 } 829 }
773 830
@@ -775,45 +832,40 @@ mod tests {
775 fn wrap_return_type_in_result_simple_with_closure() { 832 fn wrap_return_type_in_result_simple_with_closure() {
776 check_assist( 833 check_assist(
777 wrap_return_type_in_result, 834 wrap_return_type_in_result,
778 r#"fn foo(the_field: u32) -><|> u32 { 835 r#"
779 let true_closure = || { 836fn foo(the_field: u32) -><|> u32 {
780 return true; 837 let true_closure = || { return true; };
781 }; 838 if the_field < 5 {
782 if the_field < 5 { 839 let mut i = 0;
783 let mut i = 0; 840 if true_closure() {
784 841 return 99;
785 842 } else {
786 if true_closure() { 843 return 0;
787 return 99; 844 }
788 } else { 845 }
789 return 0; 846 the_field
790 } 847}
791 } 848"#,
792 849 r#"
793 the_field 850fn foo(the_field: u32) -> Result<u32, ${0:_}> {
794 }"#, 851 let true_closure = || { return true; };
795 r#"fn foo(the_field: u32) -> Result<u32, ${0:_}> { 852 if the_field < 5 {
796 let true_closure = || { 853 let mut i = 0;
797 return true; 854 if true_closure() {
798 }; 855 return Ok(99);
799 if the_field < 5 { 856 } else {
800 let mut i = 0; 857 return Ok(0);
801 858 }
802 859 }
803 if true_closure() { 860 Ok(the_field)
804 return Ok(99); 861}
805 } else { 862"#,
806 return Ok(0);
807 }
808 }
809
810 Ok(the_field)
811 }"#,
812 ); 863 );
813 864
814 check_assist( 865 check_assist(
815 wrap_return_type_in_result, 866 wrap_return_type_in_result,
816 r#"fn foo(the_field: u32) -> u32<|> { 867 r#"
868 fn foo(the_field: u32) -> u32<|> {
817 let true_closure = || { 869 let true_closure = || {
818 return true; 870 return true;
819 }; 871 };
@@ -830,8 +882,10 @@ mod tests {
830 let t = None; 882 let t = None;
831 883
832 t.unwrap_or_else(|| the_field) 884 t.unwrap_or_else(|| the_field)
833 }"#, 885 }
834 r#"fn foo(the_field: u32) -> Result<u32, ${0:_}> { 886 "#,
887 r#"
888 fn foo(the_field: u32) -> Result<u32, ${0:_}> {
835 let true_closure = || { 889 let true_closure = || {
836 return true; 890 return true;
837 }; 891 };
@@ -848,7 +902,8 @@ mod tests {
848 let t = None; 902 let t = None;
849 903
850 Ok(t.unwrap_or_else(|| the_field)) 904 Ok(t.unwrap_or_else(|| the_field))
851 }"#, 905 }
906 "#,
852 ); 907 );
853 } 908 }
854 909
@@ -856,236 +911,248 @@ mod tests {
856 fn wrap_return_type_in_result_simple_with_weird_forms() { 911 fn wrap_return_type_in_result_simple_with_weird_forms() {
857 check_assist( 912 check_assist(
858 wrap_return_type_in_result, 913 wrap_return_type_in_result,
859 r#"fn foo() -> i32<|> { 914 r#"
860 let test = "test"; 915fn foo() -> i32<|> {
861 if test == "test" { 916 let test = "test";
862 return 24i32; 917 if test == "test" {
863 } 918 return 24i32;
864 let mut i = 0; 919 }
865 loop { 920 let mut i = 0;
866 if i == 1 { 921 loop {
867 break 55; 922 if i == 1 {
868 } 923 break 55;
869 i += 1; 924 }
870 } 925 i += 1;
871 }"#, 926 }
872 r#"fn foo() -> Result<i32, ${0:_}> { 927}
873 let test = "test"; 928"#,
874 if test == "test" { 929 r#"
875 return Ok(24i32); 930fn foo() -> Result<i32, ${0:_}> {
876 } 931 let test = "test";
877 let mut i = 0; 932 if test == "test" {
878 loop { 933 return Ok(24i32);
879 if i == 1 { 934 }
880 break Ok(55); 935 let mut i = 0;
881 } 936 loop {
882 i += 1; 937 if i == 1 {
883 } 938 break Ok(55);
884 }"#, 939 }
940 i += 1;
941 }
942}
943"#,
885 ); 944 );
886 945
887 check_assist( 946 check_assist(
888 wrap_return_type_in_result, 947 wrap_return_type_in_result,
889 r#"fn foo() -> i32<|> { 948 r#"
890 let test = "test"; 949fn foo() -> i32<|> {
891 if test == "test" { 950 let test = "test";
892 return 24i32; 951 if test == "test" {
893 } 952 return 24i32;
894 let mut i = 0; 953 }
895 loop { 954 let mut i = 0;
896 loop { 955 loop {
897 if i == 1 { 956 loop {
898 break 55; 957 if i == 1 {
899 } 958 break 55;
900 i += 1; 959 }
901 } 960 i += 1;
902 } 961 }
903 }"#, 962 }
904 r#"fn foo() -> Result<i32, ${0:_}> { 963}
905 let test = "test"; 964"#,
906 if test == "test" { 965 r#"
907 return Ok(24i32); 966fn foo() -> Result<i32, ${0:_}> {
908 } 967 let test = "test";
909 let mut i = 0; 968 if test == "test" {
910 loop { 969 return Ok(24i32);
911 loop { 970 }
912 if i == 1 { 971 let mut i = 0;
913 break Ok(55); 972 loop {
914 } 973 loop {
915 i += 1; 974 if i == 1 {
916 } 975 break Ok(55);
917 } 976 }
918 }"#, 977 i += 1;
978 }
979 }
980}
981"#,
919 ); 982 );
920 983
921 check_assist( 984 check_assist(
922 wrap_return_type_in_result, 985 wrap_return_type_in_result,
923 r#"fn foo() -> i3<|>2 { 986 r#"
924 let test = "test"; 987fn foo() -> i3<|>2 {
925 let other = 5; 988 let test = "test";
926 if test == "test" { 989 let other = 5;
927 let res = match other { 990 if test == "test" {
928 5 => 43, 991 let res = match other {
929 _ => return 56, 992 5 => 43,
930 }; 993 _ => return 56,
931 } 994 };
932 let mut i = 0; 995 }
933 loop { 996 let mut i = 0;
934 loop { 997 loop {
935 if i == 1 { 998 loop {
936 break 55; 999 if i == 1 {
937 } 1000 break 55;
938 i += 1; 1001 }
939 } 1002 i += 1;
940 } 1003 }
941 }"#, 1004 }
942 r#"fn foo() -> Result<i32, ${0:_}> { 1005}
943 let test = "test"; 1006"#,
944 let other = 5; 1007 r#"
945 if test == "test" { 1008fn foo() -> Result<i32, ${0:_}> {
946 let res = match other { 1009 let test = "test";
947 5 => 43, 1010 let other = 5;
948 _ => return Ok(56), 1011 if test == "test" {
949 }; 1012 let res = match other {
950 } 1013 5 => 43,
951 let mut i = 0; 1014 _ => return Ok(56),
952 loop { 1015 };
953 loop { 1016 }
954 if i == 1 { 1017 let mut i = 0;
955 break Ok(55); 1018 loop {
956 } 1019 loop {
957 i += 1; 1020 if i == 1 {
958 } 1021 break Ok(55);
959 } 1022 }
960 }"#, 1023 i += 1;
1024 }
1025 }
1026}
1027"#,
961 ); 1028 );
962 1029
963 check_assist( 1030 check_assist(
964 wrap_return_type_in_result, 1031 wrap_return_type_in_result,
965 r#"fn foo(the_field: u32) -> u32<|> { 1032 r#"
966 if the_field < 5 { 1033fn foo(the_field: u32) -> u32<|> {
967 let mut i = 0; 1034 if the_field < 5 {
968 loop { 1035 let mut i = 0;
969 if i > 5 { 1036 loop {
970 return 55u32; 1037 if i > 5 {
971 } 1038 return 55u32;
972 i += 3; 1039 }
973 } 1040 i += 3;
974 1041 }
975 match i { 1042 match i {
976 5 => return 99, 1043 5 => return 99,
977 _ => return 0, 1044 _ => return 0,
978 }; 1045 };
979 } 1046 }
980 1047 the_field
981 the_field 1048}
982 }"#, 1049"#,
983 r#"fn foo(the_field: u32) -> Result<u32, ${0:_}> { 1050 r#"
984 if the_field < 5 { 1051fn foo(the_field: u32) -> Result<u32, ${0:_}> {
985 let mut i = 0; 1052 if the_field < 5 {
986 loop { 1053 let mut i = 0;
987 if i > 5 { 1054 loop {
988 return Ok(55u32); 1055 if i > 5 {
989 } 1056 return Ok(55u32);
990 i += 3; 1057 }
991 } 1058 i += 3;
992 1059 }
993 match i { 1060 match i {
994 5 => return Ok(99), 1061 5 => return Ok(99),
995 _ => return Ok(0), 1062 _ => return Ok(0),
996 }; 1063 };
997 } 1064 }
998 1065 Ok(the_field)
999 Ok(the_field) 1066}
1000 }"#, 1067"#,
1001 ); 1068 );
1002 1069
1003 check_assist( 1070 check_assist(
1004 wrap_return_type_in_result, 1071 wrap_return_type_in_result,
1005 r#"fn foo(the_field: u32) -> u3<|>2 { 1072 r#"
1006 if the_field < 5 { 1073fn foo(the_field: u32) -> u3<|>2 {
1007 let mut i = 0; 1074 if the_field < 5 {
1008 1075 let mut i = 0;
1009 match i { 1076 match i {
1010 5 => return 99, 1077 5 => return 99,
1011 _ => return 0, 1078 _ => return 0,
1012 } 1079 }
1013 } 1080 }
1014 1081 the_field
1015 the_field 1082}
1016 }"#, 1083"#,
1017 r#"fn foo(the_field: u32) -> Result<u32, ${0:_}> { 1084 r#"
1018 if the_field < 5 { 1085fn foo(the_field: u32) -> Result<u32, ${0:_}> {
1019 let mut i = 0; 1086 if the_field < 5 {
1020 1087 let mut i = 0;
1021 match i { 1088 match i {
1022 5 => return Ok(99), 1089 5 => return Ok(99),
1023 _ => return Ok(0), 1090 _ => return Ok(0),
1024 } 1091 }
1025 } 1092 }
1026 1093 Ok(the_field)
1027 Ok(the_field) 1094}
1028 }"#, 1095"#,
1029 ); 1096 );
1030 1097
1031 check_assist( 1098 check_assist(
1032 wrap_return_type_in_result, 1099 wrap_return_type_in_result,
1033 r#"fn foo(the_field: u32) -> u32<|> { 1100 r#"
1034 if the_field < 5 { 1101fn foo(the_field: u32) -> u32<|> {
1035 let mut i = 0; 1102 if the_field < 5 {
1036 1103 let mut i = 0;
1037 if i == 5 { 1104 if i == 5 {
1038 return 99 1105 return 99
1039 } else { 1106 } else {
1040 return 0 1107 return 0
1041 } 1108 }
1042 } 1109 }
1043 1110 the_field
1044 the_field 1111}
1045 }"#, 1112"#,
1046 r#"fn foo(the_field: u32) -> Result<u32, ${0:_}> { 1113 r#"
1047 if the_field < 5 { 1114fn foo(the_field: u32) -> Result<u32, ${0:_}> {
1048 let mut i = 0; 1115 if the_field < 5 {
1049 1116 let mut i = 0;
1050 if i == 5 { 1117 if i == 5 {
1051 return Ok(99) 1118 return Ok(99)
1052 } else { 1119 } else {
1053 return Ok(0) 1120 return Ok(0)
1054 } 1121 }
1055 } 1122 }
1056 1123 Ok(the_field)
1057 Ok(the_field) 1124}
1058 }"#, 1125"#,
1059 ); 1126 );
1060 1127
1061 check_assist( 1128 check_assist(
1062 wrap_return_type_in_result, 1129 wrap_return_type_in_result,
1063 r#"fn foo(the_field: u32) -> <|>u32 { 1130 r#"
1064 if the_field < 5 { 1131fn foo(the_field: u32) -> <|>u32 {
1065 let mut i = 0; 1132 if the_field < 5 {
1066 1133 let mut i = 0;
1067 if i == 5 { 1134 if i == 5 {
1068 return 99; 1135 return 99;
1069 } else { 1136 } else {
1070 return 0; 1137 return 0;
1071 } 1138 }
1072 } 1139 }
1073 1140 the_field
1074 the_field 1141}
1075 }"#, 1142"#,
1076 r#"fn foo(the_field: u32) -> Result<u32, ${0:_}> { 1143 r#"
1077 if the_field < 5 { 1144fn foo(the_field: u32) -> Result<u32, ${0:_}> {
1078 let mut i = 0; 1145 if the_field < 5 {
1079 1146 let mut i = 0;
1080 if i == 5 { 1147 if i == 5 {
1081 return Ok(99); 1148 return Ok(99);
1082 } else { 1149 } else {
1083 return Ok(0); 1150 return Ok(0);
1084 } 1151 }
1085 } 1152 }
1086 1153 Ok(the_field)
1087 Ok(the_field) 1154}
1088 }"#, 1155"#,
1089 ); 1156 );
1090 } 1157 }
1091} 1158}