aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/tests
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2021-05-15 16:01:27 +0100
committerFlorian Diebold <[email protected]>2021-05-21 16:48:34 +0100
commit32fc944263ae0b30eba130fbcf28f4eb5578fdb3 (patch)
tree779b701955168f7472a5ae7e760cb95c6ca604e4 /crates/hir_ty/src/tests
parenta09079f27aa631b011f6c0703200862d28af81f4 (diff)
Fix handling of diverging branches in match coercion
Fixes #7626.
Diffstat (limited to 'crates/hir_ty/src/tests')
-rw-r--r--crates/hir_ty/src/tests/coercion.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/crates/hir_ty/src/tests/coercion.rs b/crates/hir_ty/src/tests/coercion.rs
index 67295b663..bb568ea37 100644
--- a/crates/hir_ty/src/tests/coercion.rs
+++ b/crates/hir_ty/src/tests/coercion.rs
@@ -873,3 +873,42 @@ fn foo(c: i32) {
873 "#, 873 "#,
874 ) 874 )
875} 875}
876
877#[test]
878fn infer_match_diverging_branch_1() {
879 check_types(
880 r#"
881enum Result<T> { Ok(T), Err }
882fn parse<T>() -> T { loop {} }
883
884fn test() -> i32 {
885 let a = match parse() {
886 Ok(val) => val,
887 Err => return 0,
888 };
889 a
890 //^ i32
891}
892 "#,
893 )
894}
895
896#[test]
897fn infer_match_diverging_branch_2() {
898 // same as 1 except for order of branches
899 check_types(
900 r#"
901enum Result<T> { Ok(T), Err }
902fn parse<T>() -> T { loop {} }
903
904fn test() -> i32 {
905 let a = match parse() {
906 Err => return 0,
907 Ok(val) => val,
908 };
909 a
910 //^ i32
911}
912 "#,
913 )
914}