]> git.lizzy.rs Git - rust.git/blob - tests/ui/suggestions/type-mismatch-byte-literal.rs
Fix problem noticed in PR106859 with char -> u8 suggestion
[rust.git] / tests / ui / suggestions / type-mismatch-byte-literal.rs
1 // Tests that a suggestion is issued for type mismatch errors when a
2 // u8 is expected and a char literal which is ASCII is supplied.
3
4 fn foo(_t: u8) {}
5
6 fn main() {
7     let _x: u8 = 'X';
8     //~^ ERROR: mismatched types [E0308]
9     //~| HELP: if you meant to write a byte literal, prefix with `b`
10
11     foo('#');
12     //~^ ERROR: mismatched types [E0308]
13     //~| HELP: if you meant to write a byte literal, prefix with `b`
14
15     let _a: u8 = '\x20';
16     //~^ ERROR: mismatched types [E0308]
17     //~| HELP: if you meant to write a byte literal, prefix with `b`
18
19     // Do not issue the suggestion if the char literal is a Unicode escape
20     foo('\u{0080}');
21     //~^ ERROR: mismatched types [E0308]
22
23     // Do not issue the suggestion if the char literal isn't ASCII
24     let _t: u8 = '€';
25     //~^ ERROR: mismatched types [E0308]
26
27     // Do not issue the suggestion if the char literal isn't ASCII
28     foo('\u{1f980}');
29     //~^ ERROR: mismatched types [E0308]
30 }