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

+1
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

+91-82
Large diffs are not rendered by default.

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

+3-1
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

+1-1
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

+1-1
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

+3-3
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

+1-1
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

+1-1
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

+2
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

+3-1
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}>`

src/test/ui/or-patterns/inconsistent-modes.stderr

+6-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ error[E0308]: mismatched types
6060
--> $DIR/inconsistent-modes.rs:13:25
6161
|
6262
LL | let Ok(ref a) | Err(ref mut a): Result<&u8, &mut u8> = Ok(&0);
63-
| ^^^^^^^^^ types differ in mutability
63+
| ^^^^^^^^^ ------ this expression has type `std::result::Result<&u8, &mut u8>`
64+
| |
65+
| types differ in mutability
6466
|
6567
= note: expected type `&&u8`
6668
found type `&mut &mut u8`
@@ -69,7 +71,9 @@ error[E0308]: mismatched types
6971
--> $DIR/inconsistent-modes.rs:16:31
7072
|
7173
LL | let Ok((ref a, b)) | Err((ref mut a, ref b)) = Ok((0, &0));
72-
| ^^^^^^^^^ types differ in mutability
74+
| ^^^^^^^^^ ----------- this expression has type `std::result::Result<({integer}, &{integer}), (_, _)>`
75+
| |
76+
| types differ in mutability
7377
|
7478
= note: expected type `&{integer}`
7579
found type `&mut _`

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +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`
5+
| ---------------- this expression has type `Blah` ^ expected `usize`, found `isize`
66

77
error: aborting due to previous error
88

src/test/ui/parser/recover-range-pats.stderr

+9-6
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,9 @@ error[E0308]: mismatched types
425425
--> $DIR/recover-range-pats.rs:23:16
426426
|
427427
LL | if let X.. .0 = 0 {}
428-
| - ^^ expected integer, found floating-point number
429-
| |
428+
| - ^^ - this expression has type `u8`
429+
| | |
430+
| | expected integer, found floating-point number
430431
| this is of type `u8`
431432

432433
error[E0029]: only char and numeric types are allowed in range patterns
@@ -457,8 +458,9 @@ error[E0308]: mismatched types
457458
--> $DIR/recover-range-pats.rs:36:16
458459
|
459460
LL | if let X..=.0 = 0 {}
460-
| - ^^ expected integer, found floating-point number
461-
| |
461+
| - ^^ - this expression has type `u8`
462+
| | |
463+
| | expected integer, found floating-point number
462464
| this is of type `u8`
463465

464466
error[E0029]: only char and numeric types are allowed in range patterns
@@ -489,8 +491,9 @@ error[E0308]: mismatched types
489491
--> $DIR/recover-range-pats.rs:52:17
490492
|
491493
LL | if let X... .0 = 0 {}
492-
| - ^^ expected integer, found floating-point number
493-
| |
494+
| - ^^ - this expression has type `u8`
495+
| | |
496+
| | expected integer, found floating-point number
494497
| this is of type `u8`
495498

496499
error[E0029]: only char and numeric types are allowed in range patterns

src/test/ui/pattern/pat-struct-field-expr-has-type.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/pat-struct-field-expr-has-type.rs:7:16
33
|
44
LL | match (S { f: 42 }) {
5-
| ------------- this expression has type `u8`
5+
| ------------- this expression has type `S`
66
LL | S { f: Ok(_) } => {}
77
| ^^^^^ expected `u8`, found enum `std::result::Result`
88
|

src/test/ui/pattern/pattern-tyvar.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/pattern-tyvar.rs:5:18
33
|
44
LL | match t {
5-
| - this expression has type `std::option::Option<std::vec::Vec<isize>>`
5+
| - this expression has type `Bar`
66
LL | Bar::T1(_, Some::<isize>(x)) => {
77
| ^^^^^^^^^^^^^^^^ expected struct `std::vec::Vec`, found `isize`
88
|

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

+6
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,24 @@ 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 expression has type `Opts`
2628
LL | Opts::A(ref i) | Opts::B(i) => {}
2729
| ^ expected `&isize`, found `isize`
2830

2931
error[E0308]: mismatched types
3032
--> $DIR/resolve-inconsistent-binding-mode.rs:16:32
3133
|
34+
LL | match x {
35+
| - this expression has type `Opts`
3236
LL | Opts::A(ref i) | Opts::B(i) => {}
3337
| ^ expected `&isize`, found `isize`
3438

3539
error[E0308]: mismatched types
3640
--> $DIR/resolve-inconsistent-binding-mode.rs:25:36
3741
|
42+
LL | match x {
43+
| - this expression has type `Opts`
3844
LL | Opts::A(ref mut i) | Opts::B(ref i) => {}
3945
| ^^^^^ types differ in mutability
4046
|

src/test/ui/resolve/resolve-inconsistent-names.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ LL | (CONST1, _) | (_, Const2) => ()
8686
error[E0308]: mismatched types
8787
--> $DIR/resolve-inconsistent-names.rs:19:19
8888
|
89+
LL | match x {
90+
| - this expression has type `(E, E)`
8991
LL | (A, B) | (ref B, c) | (c, A) => ()
9092
| ^^^^^ expected enum `E`, found `&E`
9193

src/test/ui/rfc-2497-if-let-chains/disallowed-positions.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ error[E0308]: mismatched types
697697
--> $DIR/disallowed-positions.rs:86:12
698698
|
699699
LL | if let Range { start: true, end } = t..&&false {}
700-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ - this expression has type `bool`
700+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ - this expression has type `&&bool`
701701
| |
702702
| expected `bool`, found struct `std::ops::Range`
703703
|
@@ -885,7 +885,7 @@ error[E0308]: mismatched types
885885
--> $DIR/disallowed-positions.rs:150:15
886886
|
887887
LL | while let Range { start: true, end } = t..&&false {}
888-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ - this expression has type `bool`
888+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ - this expression has type `&&bool`
889889
| |
890890
| expected `bool`, found struct `std::ops::Range`
891891
|

0 commit comments

Comments
 (0)