From 44386d5373114ffc88ef6bd182fb3b58a7c27e69 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Thu, 22 Aug 2019 00:34:50 +0300 Subject: An attempt to add the coercion logic for Never --- crates/ra_hir/src/ty/tests.rs | 58 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'crates/ra_hir/src/ty/tests.rs') diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index a30a645eb..4fa9d131d 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -3618,6 +3618,26 @@ fn test(a: i32) { assert_eq!(t, "f64"); } + #[test] + fn match_second_block_arm_never() { + let t = type_at( + r#" +//- /main.rs +fn test(a: i32) { + let i = match a { + 1 => { 3.0 }, + 2 => { loop {} }, + 3 => { 3.0 }, + _ => { return }, + }; + i<|> + () +} +"#, + ); + assert_eq!(t, "f64"); + } + #[test] fn if_never() { let t = type_at( @@ -3656,6 +3676,26 @@ fn test(input: bool) { assert_eq!(t, "f64"); } + #[test] + fn match_first_block_arm_never() { + let t = type_at( + r#" +//- /main.rs +fn test(a: i32) { + let i = match a { + 1 => { return }, + 2 => { 2.0 }, + 3 => { loop {} }, + _ => { 3.0 }, + }; + i<|> + () +} +"#, + ); + assert_eq!(t, "f64"); + } + #[test] fn match_second_arm_never() { let t = type_at( @@ -3694,6 +3734,24 @@ fn test(a: i32) { assert_eq!(t, "!"); } + #[test] + fn match_all_block_arms_never() { + let t = type_at( + r#" +//- /main.rs +fn test(a: i32) { + let i = match a { + 2 => { return }, + _ => { loop {} }, + }; + i<|> + () +} +"#, + ); + assert_eq!(t, "!"); + } + #[test] fn match_no_never_arms() { let t = type_at( -- cgit v1.2.3