Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/tests/diagnostics.rs')
| -rw-r--r-- | crates/hir-ty/src/tests/diagnostics.rs | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/crates/hir-ty/src/tests/diagnostics.rs b/crates/hir-ty/src/tests/diagnostics.rs new file mode 100644 index 0000000000..f00fa97294 --- /dev/null +++ b/crates/hir-ty/src/tests/diagnostics.rs @@ -0,0 +1,75 @@ +use super::check; + +#[test] +fn function_return_type_mismatch_1() { + check( + r#" +fn test() -> &'static str { + 5 + //^ expected &str, got i32 +} +"#, + ); +} + +#[test] +fn function_return_type_mismatch_2() { + check( + r#" +fn test(x: bool) -> &'static str { + if x { + return 1; + //^ expected &str, got i32 + } + "ok" +} +"#, + ); +} + +#[test] +fn function_return_type_mismatch_3() { + check( + r#" +fn test(x: bool) -> &'static str { + if x { + return "ok"; + } + 1 + //^ expected &str, got i32 +} +"#, + ); +} + +#[test] +fn function_return_type_mismatch_4() { + check( + r#" +fn test(x: bool) -> &'static str { + if x { + "ok" + } else { + 1 + //^ expected &str, got i32 + } +} +"#, + ); +} + +#[test] +fn function_return_type_mismatch_5() { + check( + r#" +fn test(x: bool) -> &'static str { + if x { + 1 + //^ expected &str, got i32 + } else { + "ok" + } +} +"#, + ); +} |