diff options
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index c5818b738..0f53f156e 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -3594,3 +3594,107 @@ fn no_such_field_diagnostics() { | |||
3594 | "### | 3594 | "### |
3595 | ); | 3595 | ); |
3596 | } | 3596 | } |
3597 | |||
3598 | #[cfg(test)] | ||
3599 | mod match_with_never_tests { | ||
3600 | use super::type_at; | ||
3601 | |||
3602 | #[test] | ||
3603 | fn match_compex_arm_ty() { | ||
3604 | let t = type_at( | ||
3605 | r#" | ||
3606 | //- /main.rs | ||
3607 | enum Option<T> { | ||
3608 | Some(T), | ||
3609 | None | ||
3610 | } | ||
3611 | |||
3612 | fn test(a: i32) { | ||
3613 | let i = match a { | ||
3614 | 2 => Option::Some(2.0), | ||
3615 | _ => loop {}, | ||
3616 | }; | ||
3617 | i<|> | ||
3618 | () | ||
3619 | } | ||
3620 | "#, | ||
3621 | ); | ||
3622 | assert_eq!(t, "Option<f64>"); | ||
3623 | } | ||
3624 | |||
3625 | #[test] | ||
3626 | fn match_first_arm_never() { | ||
3627 | let t = type_at( | ||
3628 | r#" | ||
3629 | //- /main.rs | ||
3630 | fn test(a: i32) { | ||
3631 | let i = match a { | ||
3632 | 1 => return, | ||
3633 | 2 => 2.0, | ||
3634 | 3 => loop {}, | ||
3635 | _ => 3.0, | ||
3636 | }; | ||
3637 | i<|> | ||
3638 | () | ||
3639 | } | ||
3640 | "#, | ||
3641 | ); | ||
3642 | assert_eq!(t, "f64"); | ||
3643 | } | ||
3644 | |||
3645 | #[test] | ||
3646 | fn match_second_arm_never() { | ||
3647 | let t = type_at( | ||
3648 | r#" | ||
3649 | //- /main.rs | ||
3650 | fn test(a: i32) { | ||
3651 | let i = match a { | ||
3652 | 1 => 3.0, | ||
3653 | 2 => loop {}, | ||
3654 | 3 => 3.0, | ||
3655 | _ => return, | ||
3656 | }; | ||
3657 | i<|> | ||
3658 | () | ||
3659 | } | ||
3660 | "#, | ||
3661 | ); | ||
3662 | assert_eq!(t, "f64"); | ||
3663 | } | ||
3664 | |||
3665 | #[test] | ||
3666 | fn match_all_arms_never() { | ||
3667 | let t = type_at( | ||
3668 | r#" | ||
3669 | //- /main.rs | ||
3670 | fn test(a: i32) { | ||
3671 | let i = match a { | ||
3672 | 2 => return, | ||
3673 | _ => loop {}, | ||
3674 | }; | ||
3675 | i<|> | ||
3676 | () | ||
3677 | } | ||
3678 | "#, | ||
3679 | ); | ||
3680 | assert_eq!(t, "!"); | ||
3681 | } | ||
3682 | |||
3683 | #[test] | ||
3684 | fn match_no_never_arms() { | ||
3685 | let t = type_at( | ||
3686 | r#" | ||
3687 | //- /main.rs | ||
3688 | fn test(a: i32) { | ||
3689 | let i = match a { | ||
3690 | 2 => 2.0, | ||
3691 | _ => 3.0, | ||
3692 | }; | ||
3693 | i<|> | ||
3694 | () | ||
3695 | } | ||
3696 | "#, | ||
3697 | ); | ||
3698 | assert_eq!(t, "f64"); | ||
3699 | } | ||
3700 | } | ||