]> git.proxmox.com Git - rustc.git/blob - src/tools/rust-analyzer/crates/hir-ty/src/tests/diagnostics.rs
1876be303ad44862802ac0aae149a5502749bfe1
[rustc.git] / src / tools / rust-analyzer / crates / hir-ty / src / tests / diagnostics.rs
1 use super::check;
2
3 #[test]
4 fn function_return_type_mismatch_1() {
5 check(
6 r#"
7 fn test() -> &'static str {
8 5
9 //^ expected &str, got i32
10 }
11 "#,
12 );
13 }
14
15 #[test]
16 fn function_return_type_mismatch_2() {
17 check(
18 r#"
19 fn test(x: bool) -> &'static str {
20 if x {
21 return 1;
22 //^ expected &str, got i32
23 }
24 "ok"
25 }
26 "#,
27 );
28 }
29
30 #[test]
31 fn function_return_type_mismatch_3() {
32 check(
33 r#"
34 fn test(x: bool) -> &'static str {
35 if x {
36 return "ok";
37 }
38 1
39 //^ expected &str, got i32
40 }
41 "#,
42 );
43 }
44
45 #[test]
46 fn function_return_type_mismatch_4() {
47 check(
48 r#"
49 fn test(x: bool) -> &'static str {
50 if x {
51 "ok"
52 } else {
53 1
54 //^ expected &str, got i32
55 }
56 }
57 "#,
58 );
59 }
60
61 #[test]
62 fn function_return_type_mismatch_5() {
63 check(
64 r#"
65 fn test(x: bool) -> &'static str {
66 if x {
67 1
68 //^ expected &str, got i32
69 } else {
70 "ok"
71 }
72 }
73 "#,
74 );
75 }
76
77 #[test]
78 fn non_unit_block_expr_stmt_no_semi() {
79 check(
80 r#"
81 fn test(x: bool) {
82 if x {
83 "notok"
84 //^^^^^^^ expected (), got &str
85 } else {
86 "ok"
87 //^^^^ expected (), got &str
88 }
89 match x { true => true, false => 0 }
90 //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), got bool
91 //^ expected bool, got i32
92 ()
93 }
94 "#,
95 );
96 }