File: stmts-as-exp-105431.rs

package info (click to toggle)
rustc 1.88.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 934,128 kB
  • sloc: xml: 158,127; python: 36,062; javascript: 19,855; sh: 19,700; cpp: 18,947; ansic: 12,993; asm: 4,792; makefile: 690; lisp: 29; perl: 29; ruby: 19; sql: 11
file content (76 lines) | stat: -rw-r--r-- 1,382 bytes parent folder | download | duplicates (15)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#![allow(unused)]

fn test_if() -> i32 {
    let x = if true {
        eprintln!("hello");
        3;
    }
    else {
        4;
    };
    x //~ ERROR mismatched types
}

fn test_if_without_binding() -> i32 {
    if true { //~ ERROR mismatched types
        eprintln!("hello");
        3;
    }
    else { //~ ERROR mismatched types
        4;
    }
}

fn test_match() -> i32 {
    let v = 1;
    let res = match v {
        1 => { 1; }
        _ => { 2; }
    };
    res //~ ERROR mismatched types
}

fn test_match_match_without_binding() -> i32 {
    let v = 1;
    match v {
        1 => { 1; } //~ ERROR mismatched types
        _ => { 2; } //~ ERROR mismatched types
    }
}

fn test_match_arm_different_types() -> i32 {
    let v = 1;
    let res = match v {
        1 => { if 1 < 2 { 1 } else { 2 } }
        _ => { 2; } //~ ERROR `match` arms have incompatible types
    };
    res
}

fn test_if_match_mixed() -> i32 {
    let x = if true {
        3;
    } else {
        match 1 {
            1 => { 1 }
            _ => { 2 }
        };
    };
    x //~ ERROR mismatched types
}

fn test_if_match_mixed_failed() -> i32 {
    let x = if true {
        3;
    } else {
        // because this is a tailed expr, so we won't check deeper
        match 1 {
            1 => { 33; }
            _ => { 44; }
        }
    };
    x //~ ERROR mismatched types
}


fn main() {}