Skip to content

Commit 486ecc5

Browse files
committed
Don't add label to the match expr when the type is not fully realized
1 parent 72d965f commit 486ecc5

File tree

5 files changed

+4
-14
lines changed

5 files changed

+4
-14
lines changed

src/librustc/infer/error_reporting/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
488488
fn note_error_origin(&self, err: &mut DiagnosticBuilder<'tcx>, cause: &ObligationCause<'tcx>) {
489489
match cause.code {
490490
ObligationCauseCode::MatchExpressionArmPattern { span, ty } => {
491-
err.span_label(span, format!("this match expression has type `{}`", ty));
491+
if ty.is_suggestable() { // don't show type `_`
492+
err.span_label(span, format!("this match expression has type `{}`", ty));
493+
}
492494
}
493495
ObligationCauseCode::MatchExpressionArm { arm_span, source } => match source {
494496
hir::MatchSource::IfLetDesugar { .. } => {

src/test/ui/match/match-range-fail.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ LL | 10 ..= "what" => ()
1919
error[E0308]: mismatched types
2020
--> $DIR/match-range-fail.rs:17:9
2121
|
22-
LL | match 5 {
23-
| - this match expression has type `{integer}`
2422
LL | 'c' ..= 100 => { }
2523
| ^^^^^^^^^^^ expected integer, found char
2624
|

src/test/ui/mismatched_types/E0409.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ LL | (0, ref y) | (y, 0) => {} //~ ERROR E0409
99
error[E0308]: mismatched types
1010
--> $DIR/E0409.rs:5:23
1111
|
12-
LL | match x {
13-
| - this match expression has type `_`
1412
LL | (0, ref y) | (y, 0) => {} //~ ERROR E0409
1513
| ^ expected &{integer}, found integer
1614
|

src/test/ui/or-pattern-mismatch.stderr

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/or-pattern-mismatch.rs:3:68
33
|
44
LL | fn main() { match Blah::A(1, 1, 2) { Blah::A(_, x, y) | Blah::B(x, y) => { } } }
5-
| ---------------- ^ expected usize, found isize
6-
| |
7-
| this match expression has type `_`
5+
| ^ expected usize, found isize
86
|
97
= note: expected type `usize`
108
found type `isize`

src/test/ui/resolve/resolve-inconsistent-binding-mode.stderr

-6
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ LL | Opts::A(ref mut i) | Opts::B(ref i) => {}
2323
error[E0308]: mismatched types
2424
--> $DIR/resolve-inconsistent-binding-mode.rs:7:32
2525
|
26-
LL | match x {
27-
| - this match expression has type `_`
2826
LL | Opts::A(ref i) | Opts::B(i) => {}
2927
| ^ expected &isize, found isize
3028
|
@@ -34,8 +32,6 @@ LL | Opts::A(ref i) | Opts::B(i) => {}
3432
error[E0308]: mismatched types
3533
--> $DIR/resolve-inconsistent-binding-mode.rs:16:32
3634
|
37-
LL | match x {
38-
| - this match expression has type `_`
3935
LL | Opts::A(ref i) | Opts::B(i) => {}
4036
| ^ expected &isize, found isize
4137
|
@@ -45,8 +41,6 @@ LL | Opts::A(ref i) | Opts::B(i) => {}
4541
error[E0308]: mismatched types
4642
--> $DIR/resolve-inconsistent-binding-mode.rs:25:36
4743
|
48-
LL | match x {
49-
| - this match expression has type `_`
5044
LL | Opts::A(ref mut i) | Opts::B(ref i) => {}
5145
| ^^^^^ types differ in mutability
5246
|

0 commit comments

Comments
 (0)