]> git.lizzy.rs Git - rust.git/blob - src/test/ui/match/match-type-err-first-arm.rs
Make some diagnostics not depend on the source of what they reference being available
[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     };
22     x
23 }
24
25 fn test_func3(n: i32) -> i32 {
26     let x = match n { //~ NOTE `match` arms have incompatible types
27         1 => 'b',
28         2 => 'b',
29         3 => 'b',
30         4 => 'b',
31         5 => 'b',
32         6 => 'b',
33         //~^ NOTE this and all prior arms are found to be of type `char`
34         _ => 42,
35         //~^ ERROR `match` arms have incompatible types
36         //~| NOTE expected `char`, found integer
37     };
38     x
39 }
40
41 fn test_func4() {
42     match Some(0u32) { //~ NOTE `match` arms have incompatible types
43         Some(x) => {
44             x //~ NOTE this is found to be of type `u32`
45         },
46         None => {}
47         //~^ ERROR `match` arms have incompatible types
48         //~| NOTE expected `u32`, found `()`
49     };
50 }