diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-08-27 19:29:00 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-08-27 19:29:00 +0100 |
commit | 5a99184967c89992df4544d0c1ca27d79946a1a7 (patch) | |
tree | 1ffe483a008c2d43441d7f04ef0b006823faf5f0 /crates/ra_hir/src/ty/tests.rs | |
parent | 04c2961d0c5493962e948dc8101445cc76f1d460 (diff) | |
parent | 4adfdea1ad5aca393fa5bb9ff40fdc05827fcd56 (diff) |
Merge #1680
1680: Correctly infer match with early return r=flodiebold a=SomeoneToIgnore
Fixes #1505
Co-authored-by: Kirill Bulatov <[email protected]>
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/ty/tests.rs')
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 140 |
1 files changed, 130 insertions, 10 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index c5818b738..e3eb0c3fa 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -718,16 +718,18 @@ fn main(foo: Foo) { | |||
718 | } | 718 | } |
719 | "#), | 719 | "#), |
720 | @r###" | 720 | @r###" |
721 | [35; 38) 'foo': Foo | 721 | ⋮ |
722 | [45; 109) '{ ... } }': () | 722 | ⋮[35; 38) 'foo': Foo |
723 | [51; 107) 'if tru... }': () | 723 | ⋮[45; 109) '{ ... } }': () |
724 | [54; 58) 'true': bool | 724 | ⋮[51; 107) 'if tru... }': () |
725 | [59; 67) '{ }': () | 725 | ⋮[54; 58) 'true': bool |
726 | [73; 107) 'if fal... }': i32 | 726 | ⋮[59; 67) '{ }': () |
727 | [76; 81) 'false': bool | 727 | ⋮[73; 107) 'if fal... }': () |
728 | [82; 107) '{ ... }': i32 | 728 | ⋮[76; 81) 'false': bool |
729 | [92; 95) 'foo': Foo | 729 | ⋮[82; 107) '{ ... }': i32 |
730 | [92; 101) 'foo.field': i32"### | 730 | ⋮[92; 95) 'foo': Foo |
731 | ⋮[92; 101) 'foo.field': i32 | ||
732 | "### | ||
731 | ) | 733 | ) |
732 | } | 734 | } |
733 | 735 | ||
@@ -3594,3 +3596,121 @@ fn no_such_field_diagnostics() { | |||
3594 | "### | 3596 | "### |
3595 | ); | 3597 | ); |
3596 | } | 3598 | } |
3599 | |||
3600 | mod branching_with_never_tests { | ||
3601 | use super::type_at; | ||
3602 | |||
3603 | #[test] | ||
3604 | fn if_never() { | ||
3605 | let t = type_at( | ||
3606 | r#" | ||
3607 | //- /main.rs | ||
3608 | fn test() { | ||
3609 | let i = if true { | ||
3610 | loop {} | ||
3611 | } else { | ||
3612 | 3.0 | ||
3613 | }; | ||
3614 | i<|> | ||
3615 | () | ||
3616 | } | ||
3617 | "#, | ||
3618 | ); | ||
3619 | assert_eq!(t, "f64"); | ||
3620 | } | ||
3621 | |||
3622 | #[test] | ||
3623 | fn if_else_never() { | ||
3624 | let t = type_at( | ||
3625 | r#" | ||
3626 | //- /main.rs | ||
3627 | fn test(input: bool) { | ||
3628 | let i = if input { | ||
3629 | 2.0 | ||
3630 | } else { | ||
3631 | return | ||
3632 | }; | ||
3633 | i<|> | ||
3634 | () | ||
3635 | } | ||
3636 | "#, | ||
3637 | ); | ||
3638 | assert_eq!(t, "f64"); | ||
3639 | } | ||
3640 | |||
3641 | #[test] | ||
3642 | fn match_first_arm_never() { | ||
3643 | let t = type_at( | ||
3644 | r#" | ||
3645 | //- /main.rs | ||
3646 | fn test(a: i32) { | ||
3647 | let i = match a { | ||
3648 | 1 => return, | ||
3649 | 2 => 2.0, | ||
3650 | 3 => loop {}, | ||
3651 | _ => 3.0, | ||
3652 | }; | ||
3653 | i<|> | ||
3654 | () | ||
3655 | } | ||
3656 | "#, | ||
3657 | ); | ||
3658 | assert_eq!(t, "f64"); | ||
3659 | } | ||
3660 | |||
3661 | #[test] | ||
3662 | fn match_second_arm_never() { | ||
3663 | let t = type_at( | ||
3664 | r#" | ||
3665 | //- /main.rs | ||
3666 | fn test(a: i32) { | ||
3667 | let i = match a { | ||
3668 | 1 => 3.0, | ||
3669 | 2 => loop {}, | ||
3670 | 3 => 3.0, | ||
3671 | _ => return, | ||
3672 | }; | ||
3673 | i<|> | ||
3674 | () | ||
3675 | } | ||
3676 | "#, | ||
3677 | ); | ||
3678 | assert_eq!(t, "f64"); | ||
3679 | } | ||
3680 | |||
3681 | #[test] | ||
3682 | fn match_all_arms_never() { | ||
3683 | let t = type_at( | ||
3684 | r#" | ||
3685 | //- /main.rs | ||
3686 | fn test(a: i32) { | ||
3687 | let i = match a { | ||
3688 | 2 => return, | ||
3689 | _ => loop {}, | ||
3690 | }; | ||
3691 | i<|> | ||
3692 | () | ||
3693 | } | ||
3694 | "#, | ||
3695 | ); | ||
3696 | assert_eq!(t, "!"); | ||
3697 | } | ||
3698 | |||
3699 | #[test] | ||
3700 | fn match_no_never_arms() { | ||
3701 | let t = type_at( | ||
3702 | r#" | ||
3703 | //- /main.rs | ||
3704 | fn test(a: i32) { | ||
3705 | let i = match a { | ||
3706 | 2 => 2.0, | ||
3707 | _ => 3.0, | ||
3708 | }; | ||
3709 | i<|> | ||
3710 | () | ||
3711 | } | ||
3712 | "#, | ||
3713 | ); | ||
3714 | assert_eq!(t, "f64"); | ||
3715 | } | ||
3716 | } | ||