Skip to content

Commit 04b8523

Browse files
authored
Rollup merge of #109613 - lukas-code:match-str-to-char-suggestion, r=compiler-errors
fix type suggestions in match arms fix #109586
2 parents 32aa4c0 + 08f3deb commit 04b8523

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

Diff for: compiler/rustc_infer/src/infer/error_reporting/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1942,7 +1942,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
19421942
escaped
19431943
}
19441944
let mut err = struct_span_err!(self.tcx.sess, span, E0308, "{}", failure_str);
1945-
if let Some((expected, found)) = trace.values.ty() {
1945+
let values = self.resolve_vars_if_possible(trace.values);
1946+
if let Some((expected, found)) = values.ty() {
19461947
match (expected.kind(), found.kind()) {
19471948
(ty::Tuple(_), ty::Tuple(_)) => {}
19481949
// If a tuple of length one was expected and the found expression has

Diff for: tests/ui/inference/char-as-str-single.fixed

+9
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,12 @@ fn main() {
1010
let _: char = '人'; //~ ERROR mismatched types
1111
let _: char = '\''; //~ ERROR mismatched types
1212
}
13+
14+
// regression test for https://github.com/rust-lang/rust/issues/109586
15+
#[allow(dead_code)]
16+
fn convert_c_to_str(c: char) {
17+
match c {
18+
'A' => {} //~ ERROR mismatched types
19+
_ => {}
20+
}
21+
}

Diff for: tests/ui/inference/char-as-str-single.rs

+9
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,12 @@ fn main() {
1010
let _: char = "人"; //~ ERROR mismatched types
1111
let _: char = "'"; //~ ERROR mismatched types
1212
}
13+
14+
// regression test for https://github.com/rust-lang/rust/issues/109586
15+
#[allow(dead_code)]
16+
fn convert_c_to_str(c: char) {
17+
match c {
18+
"A" => {} //~ ERROR mismatched types
19+
_ => {}
20+
}
21+
}

Diff for: tests/ui/inference/char-as-str-single.stderr

+14-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ help: if you meant to write a `char` literal, use single quotes
3737
LL | let _: char = '\'';
3838
| ~~~~
3939

40-
error: aborting due to 3 previous errors
40+
error[E0308]: mismatched types
41+
--> $DIR/char-as-str-single.rs:18:9
42+
|
43+
LL | match c {
44+
| - this expression has type `char`
45+
LL | "A" => {}
46+
| ^^^ expected `char`, found `&str`
47+
|
48+
help: if you meant to write a `char` literal, use single quotes
49+
|
50+
LL | 'A' => {}
51+
| ~~~
52+
53+
error: aborting due to 4 previous errors
4154

4255
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)