File: match-type-err-first-arm.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 893,176 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; lisp: 29; perl: 29; ruby: 19; sql: 11
file content (50 lines) | stat: -rw-r--r-- 1,312 bytes parent folder | download | duplicates (24)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
fn main() {
    let _ = test_func1(1);
    let _ = test_func2(1);
}

fn test_func1(n: i32) -> i32 { //~ NOTE expected `i32` because of return type
    match n {
        12 => 'b',
        //~^ ERROR mismatched types
        //~| NOTE expected `i32`, found `char`
        _ => 42,
    }
}

fn test_func2(n: i32) -> i32 {
    let x = match n { //~ NOTE `match` arms have incompatible types
        12 => 'b', //~ NOTE this is found to be of type `char`
        _ => 42,
        //~^ ERROR `match` arms have incompatible types
        //~| NOTE expected `char`, found integer
    };
    x
}

fn test_func3(n: i32) -> i32 {
    let x = match n { //~ NOTE `match` arms have incompatible types
        1 => 'b',
        2 => 'b',
        3 => 'b',
        4 => 'b',
        5 => 'b',
        6 => 'b',
        //~^ NOTE this and all prior arms are found to be of type `char`
        _ => 42,
        //~^ ERROR `match` arms have incompatible types
        //~| NOTE expected `char`, found integer
    };
    x
}

fn test_func4() {
    match Some(0u32) { //~ NOTE `match` arms have incompatible types
        Some(x) => {
            x //~ NOTE this is found to be of type `u32`
        },
        None => {}
        //~^ ERROR `match` arms have incompatible types
        //~| NOTE expected `u32`, found `()`
    };
}