fix type suggestions in match arms

This commit is contained in:
Lukas Markeffsky 2023-03-25 22:27:24 +01:00
parent b72e896268
commit 08f3deb3d5
4 changed files with 34 additions and 2 deletions

View file

@ -10,3 +10,12 @@ fn main() {
let _: char = '人'; //~ ERROR mismatched types
let _: char = '\''; //~ ERROR mismatched types
}
// regression test for https://github.com/rust-lang/rust/issues/109586
#[allow(dead_code)]
fn convert_c_to_str(c: char) {
match c {
'A' => {} //~ ERROR mismatched types
_ => {}
}
}

View file

@ -10,3 +10,12 @@ fn main() {
let _: char = ""; //~ ERROR mismatched types
let _: char = "'"; //~ ERROR mismatched types
}
// regression test for https://github.com/rust-lang/rust/issues/109586
#[allow(dead_code)]
fn convert_c_to_str(c: char) {
match c {
"A" => {} //~ ERROR mismatched types
_ => {}
}
}

View file

@ -37,6 +37,19 @@ help: if you meant to write a `char` literal, use single quotes
LL | let _: char = '\'';
| ~~~~
error: aborting due to 3 previous errors
error[E0308]: mismatched types
--> $DIR/char-as-str-single.rs:18:9
|
LL | match c {
| - this expression has type `char`
LL | "A" => {}
| ^^^ expected `char`, found `&str`
|
help: if you meant to write a `char` literal, use single quotes
|
LL | 'A' => {}
| ~~~
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0308`.