]> git.lizzy.rs Git - rust.git/blob - src/test/ui/match/match-type-err-first-arm.rs
8dfbf1019e9a402245b73b6acd8abf86fd46cd2c
[rust.git] / src / test / ui / match / match-type-err-first-arm.rs
1 fn main() {
2     let _ = test_func1(1);
3     let _ = test_func2(1);
4 }
5
6 fn test_func1(n: i32) -> i32 { //~ NOTE expected `i32` because of return type
7     match n {
8         12 => 'b',
9         //~^ ERROR mismatched types
10         //~| NOTE expected i32, found char
11         _ => 42,
12     }
13 }
14
15 fn test_func2(n: i32) -> i32 {
16     let x = match n { //~ NOTE `match` arms have incompatible types
17         12 => 'b', //~ NOTE this is found to be of type `char`
18         _ => 42,
19         //~^ ERROR match arms have incompatible types
20         //~| NOTE expected char, found integer
21         //~| NOTE expected type `char`
22     };
23     x
24 }
25
26 fn test_func3(n: i32) -> i32 {
27     let x = match n { //~ NOTE `match` arms have incompatible types
28         1 => 'b',
29         2 => 'b',
30         3 => 'b',
31         4 => 'b',
32         5 => 'b',
33         6 => 'b',
34         //~^ NOTE this and all prior arms are found to be of type `char`
35         _ => 42,
36         //~^ ERROR match arms have incompatible types
37         //~| NOTE expected char, found integer
38         //~| NOTE expected type `char`
39     };
40     x
41 }
42
43 fn test_func4() {
44     match Some(0u32) { //~ NOTE `match` arms have incompatible types
45         Some(x) => {
46             x //~ NOTE this is found to be of type `u32`
47         },
48         None => {}
49         //~^ ERROR match arms have incompatible types
50         //~| NOTE expected u32, found ()
51         //~| NOTE expected type `u32`
52     };
53 }