summaryrefslogtreecommitdiffstats
path: root/tests/ui/suggestions/type-mismatch-byte-literal.rs
blob: 80cd2ca7dfc9afd0e7f732c47ed84f8d61b2af9c (plain)
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
// Tests that a suggestion is issued for type mismatch errors when a
// u8 is expected and a char literal which is ASCII is supplied.

fn foo(_t: u8) {}

fn main() {
    let _x: u8 = 'X';
    //~^ ERROR: mismatched types [E0308]
    //~| HELP: if you meant to write a byte literal, prefix with `b`

    foo('#');
    //~^ ERROR: mismatched types [E0308]
    //~| HELP: if you meant to write a byte literal, prefix with `b`

    let _a: u8 = '\x20';
    //~^ ERROR: mismatched types [E0308]
    //~| HELP: if you meant to write a byte literal, prefix with `b`

    // Do not issue the suggestion if the char literal is a Unicode escape
    foo('\u{0080}');
    //~^ ERROR: mismatched types [E0308]

    // Do not issue the suggestion if the char literal isn't ASCII
    let _t: u8 = '€';
    //~^ ERROR: mismatched types [E0308]

    // Do not issue the suggestion if the char literal isn't ASCII
    foo('\u{1f980}');
    //~^ ERROR: mismatched types [E0308]
}