Skip to content

Commit d7e2f3a

Browse files
committed
refactor and fix this-expression-has-type note
1 parent f35840f commit d7e2f3a

18 files changed

+135
-104
lines changed

src/librustc/infer/error_reporting/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
582582
) {
583583
match cause.code {
584584
ObligationCauseCode::Pattern { span, ty } => {
585+
let ty = self.resolve_vars_if_possible(&ty);
585586
if ty.is_suggestable() {
586587
// don't show type `_`
587588
err.span_label(span, format!("this expression has type `{}`", ty));

src/librustc_typeck/check/pat.rs

Lines changed: 91 additions & 82 deletions
Large diffs are not rendered by default.

src/test/ui/destructure-trait-ref.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ error[E0308]: mismatched types
4444
--> $DIR/destructure-trait-ref.rs:42:13
4545
|
4646
LL | let box box x = box 1isize as Box<dyn T>;
47-
| ^^^^^ expected trait `T`, found struct `std::boxed::Box`
47+
| ^^^^^ ------------------------ this expression has type `std::boxed::Box<dyn T>`
48+
| |
49+
| expected trait `T`, found struct `std::boxed::Box`
4850
|
4951
= note: expected trait object `dyn T`
5052
found struct `std::boxed::Box<_>`

src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ error[E0308]: mismatched types
88
--> $DIR/exclusive_range_pattern_syntax_collision.rs:5:13
99
|
1010
LL | match [5..4, 99..105, 43..44] {
11-
| ----------------------- this expression has type `std::ops::Range<{integer}>`
11+
| ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]`
1212
LL | [_, 99.., _] => {},
1313
| ^^ expected struct `std::ops::Range`, found integer
1414
|

src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ error[E0308]: mismatched types
1414
--> $DIR/exclusive_range_pattern_syntax_collision2.rs:5:13
1515
|
1616
LL | match [5..4, 99..105, 43..44] {
17-
| ----------------------- this expression has type `std::ops::Range<{integer}>`
17+
| ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]`
1818
LL | [_, 99..] => {},
1919
| ^^ expected struct `std::ops::Range`, found integer
2020
|

src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision3.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ error[E0308]: mismatched types
88
--> $DIR/exclusive_range_pattern_syntax_collision3.rs:5:12
99
|
1010
LL | match [5..4, 99..105, 43..44] {
11-
| ----------------------- this expression has type `std::ops::Range<{integer}>`
11+
| ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]`
1212
LL | [..9, 99..100, _] => {},
1313
| ^ expected struct `std::ops::Range`, found integer
1414
|
@@ -19,7 +19,7 @@ error[E0308]: mismatched types
1919
--> $DIR/exclusive_range_pattern_syntax_collision3.rs:5:15
2020
|
2121
LL | match [5..4, 99..105, 43..44] {
22-
| ----------------------- this expression has type `std::ops::Range<{integer}>`
22+
| ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]`
2323
LL | [..9, 99..100, _] => {},
2424
| ^^ --- this is of type `{integer}`
2525
| |
@@ -32,7 +32,7 @@ error[E0308]: mismatched types
3232
--> $DIR/exclusive_range_pattern_syntax_collision3.rs:5:19
3333
|
3434
LL | match [5..4, 99..105, 43..44] {
35-
| ----------------------- this match expression has type `std::ops::Range<{integer}>`
35+
| ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]`
3636
LL | [..9, 99..100, _] => {},
3737
| -- ^^^ expected struct `std::ops::Range`, found integer
3838
| |

src/test/ui/issues/issue-15896.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/issue-15896.rs:11:11
33
|
44
LL | let u = match e {
5-
| - this expression has type `main::R`
5+
| - this expression has type `main::E`
66
LL | E::B(
77
LL | Tau{t: x},
88
| ^^^^^^^^^ expected enum `main::R`, found struct `main::Tau`

src/test/ui/issues/issue-16338.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/issue-16338.rs:7:9
33
|
44
LL | let Slice { data: data, len: len } = "foo";
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ----- this expression has type `str`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ----- this expression has type `&str`
66
| |
77
| expected `str`, found struct `Slice`
88
|

src/test/ui/mismatched_types/E0409.stderr

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

src/test/ui/or-patterns/already-bound-name.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ error[E0308]: mismatched types
9494
--> $DIR/already-bound-name.rs:33:31
9595
|
9696
LL | let B(A(a, _) | B(a)) | A(a, A(a, _) | B(a)) = B(B(1));
97-
| ^ expected integer, found enum `E`
97+
| ^ ------- this expression has type `E<E<{integer}>>`
98+
| |
99+
| expected integer, found enum `E`
98100
|
99101
= note: expected type `{integer}`
100102
found type `E<{integer}>`

0 commit comments

Comments
 (0)