Skip to content

Commit 1c85987

Browse files
committed
Point (again) to more expressions with their type, even if not fully resolved
1 parent c4d741f commit 1c85987

30 files changed

+125
-31
lines changed

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
602602
match *cause.code() {
603603
ObligationCauseCode::Pattern { origin_expr: true, span: Some(span), root_ty } => {
604604
let ty = self.resolve_vars_if_possible(root_ty);
605-
if ty.is_suggestable() {
605+
if !matches!(ty.kind(), ty::Infer(ty::InferTy::TyVar(_) | ty::InferTy::FreshTy(_)))
606+
{
606607
// don't show type `_`
607608
err.span_label(span, format!("this expression has type `{}`", ty));
608609
}

src/test/ui/async-await/issue-61076.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ async fn baz() -> Result<(), ()> {
8787

8888
async fn match_() {
8989
match tuple() { //~ HELP consider `await`ing on the `Future`
90+
//~^ NOTE this expression has type `impl Future<Output = Tuple>`
9091
Tuple(_) => {} //~ ERROR mismatched types
9192
//~^ NOTE expected opaque type, found struct `Tuple`
9293
//~| NOTE expected opaque type `impl Future<Output = Tuple>`

src/test/ui/async-await/issue-61076.stderr

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,11 @@ LL | struct_().await.method();
5656
| ++++++
5757

5858
error[E0308]: mismatched types
59-
--> $DIR/issue-61076.rs:90:9
59+
--> $DIR/issue-61076.rs:91:9
6060
|
61+
LL | match tuple() {
62+
| ------- this expression has type `impl Future<Output = Tuple>`
63+
LL |
6164
LL | Tuple(_) => {}
6265
| ^^^^^^^^ expected opaque type, found struct `Tuple`
6366
|

src/test/ui/async-await/suggest-missing-await.stderr

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ LL ~ 1 => dummy().await,
9191
error[E0308]: mismatched types
9292
--> $DIR/suggest-missing-await.rs:53:9
9393
|
94+
LL | let _x = match dummy() {
95+
| ------- this expression has type `impl Future<Output = ()>`
9496
LL | () => {}
9597
| ^^ expected opaque type, found `()`
9698
|
@@ -109,6 +111,9 @@ LL | let _x = match dummy().await {
109111
error[E0308]: mismatched types
110112
--> $DIR/suggest-missing-await.rs:67:9
111113
|
114+
LL | match dummy_result() {
115+
| -------------- this expression has type `impl Future<Output = Result<(), ()>>`
116+
...
112117
LL | Ok(_) => {}
113118
| ^^^^^ expected opaque type, found enum `Result`
114119
|
@@ -127,6 +132,9 @@ LL | match dummy_result().await {
127132
error[E0308]: mismatched types
128133
--> $DIR/suggest-missing-await.rs:69:9
129134
|
135+
LL | match dummy_result() {
136+
| -------------- this expression has type `impl Future<Output = Result<(), ()>>`
137+
...
130138
LL | Err(_) => {}
131139
| ^^^^^^ expected opaque type, found enum `Result`
132140
|

src/test/ui/blind/blind-item-block-middle.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | mod foo { pub struct bar; }
55
| --------------- unit struct defined here
66
...
77
LL | let bar = 5;
8-
| ^^^
8+
| ^^^ - this expression has type `{integer}`
99
| |
1010
| expected integer, found struct `bar`
1111
| `bar` is interpreted as a unit struct, not a new binding

src/test/ui/destructuring-assignment/default-match-bindings-forbidden.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0308]: mismatched types
22
--> $DIR/default-match-bindings-forbidden.rs:4:5
33
|
44
LL | (x, y) = &(1, 2);
5-
| ^^^^^^ expected reference, found tuple
5+
| ^^^^^^ ------- this expression has type `&({integer}, {integer})`
6+
| |
7+
| expected reference, found tuple
68
|
79
= note: expected type `&({integer}, {integer})`
810
found tuple `(_, _)`

src/test/ui/destructuring-assignment/tuple_destructure_fail.stderr

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ error[E0308]: mismatched types
1010
--> $DIR/tuple_destructure_fail.rs:6:5
1111
|
1212
LL | (a, a, b) = (1, 2);
13-
| ^^^^^^^^^ expected a tuple with 2 elements, found one with 3 elements
13+
| ^^^^^^^^^ ------ this expression has type `({integer}, {integer})`
14+
| |
15+
| expected a tuple with 2 elements, found one with 3 elements
1416
|
1517
= note: expected type `({integer}, {integer})`
1618
found tuple `(_, _, _)`
@@ -27,7 +29,9 @@ error[E0308]: mismatched types
2729
--> $DIR/tuple_destructure_fail.rs:8:5
2830
|
2931
LL | (_,) = (1, 2);
30-
| ^^^^ expected a tuple with 2 elements, found one with 1 element
32+
| ^^^^ ------ this expression has type `({integer}, {integer})`
33+
| |
34+
| expected a tuple with 2 elements, found one with 1 element
3135
|
3236
= note: expected type `({integer}, {integer})`
3337
found tuple `(_,)`

src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
error[E0308]: mismatched types
22
--> $DIR/exclusive_range_pattern_syntax_collision.rs:6:13
33
|
4+
LL | match [5..4, 99..105, 43..44] {
5+
| ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]`
46
LL | [_, 99.., _] => {},
57
| ^^ expected struct `std::ops::Range`, found integer
68
|

src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision2.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ LL | [_, 99..] => {},
77
error[E0308]: mismatched types
88
--> $DIR/exclusive_range_pattern_syntax_collision2.rs:6:13
99
|
10+
LL | match [5..4, 99..105, 43..44] {
11+
| ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]`
1012
LL | [_, 99..] => {},
1113
| ^^ expected struct `std::ops::Range`, found integer
1214
|

src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision3.stderr

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
error[E0308]: mismatched types
22
--> $DIR/exclusive_range_pattern_syntax_collision3.rs:6:12
33
|
4+
LL | match [5..4, 99..105, 43..44] {
5+
| ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]`
46
LL | [..9, 99..100, _] => {},
57
| ^ expected struct `std::ops::Range`, found integer
68
|
@@ -10,6 +12,8 @@ LL | [..9, 99..100, _] => {},
1012
error[E0308]: mismatched types
1113
--> $DIR/exclusive_range_pattern_syntax_collision3.rs:6:15
1214
|
15+
LL | match [5..4, 99..105, 43..44] {
16+
| ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]`
1317
LL | [..9, 99..100, _] => {},
1418
| ^^ --- this is of type `{integer}`
1519
| |
@@ -21,6 +25,8 @@ LL | [..9, 99..100, _] => {},
2125
error[E0308]: mismatched types
2226
--> $DIR/exclusive_range_pattern_syntax_collision3.rs:6:19
2327
|
28+
LL | match [5..4, 99..105, 43..44] {
29+
| ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]`
2430
LL | [..9, 99..100, _] => {},
2531
| -- ^^^ expected struct `std::ops::Range`, found integer
2632
| |

src/test/ui/half-open-range-patterns/pat-tuple-5.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
error[E0308]: mismatched types
22
--> $DIR/pat-tuple-5.rs:8:10
33
|
4+
LL | match (0, 1) {
5+
| ------ this expression has type `({integer}, {integer})`
46
LL | (PAT ..) => {}
57
| ^^^ expected tuple, found `u8`
68
|

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
error[E0308]: mismatched types
22
--> $DIR/issue-11844.rs:6:9
33
|
4+
LL | match a {
5+
| - this expression has type `Option<Box<{integer}>>`
46
LL | Ok(a) =>
57
| ^^^^^ expected enum `Option`, found enum `Result`
68
|

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
error[E0308]: mismatched types
22
--> $DIR/issue-12552.rs:6:5
33
|
4+
LL | match t {
5+
| - this expression has type `Result<_, {integer}>`
46
LL | Some(k) => match k {
57
| ^^^^^^^ expected enum `Result`, found enum `Option`
68
|
@@ -10,6 +12,9 @@ LL | Some(k) => match k {
1012
error[E0308]: mismatched types
1113
--> $DIR/issue-12552.rs:9:5
1214
|
15+
LL | match t {
16+
| - this expression has type `Result<_, {integer}>`
17+
...
1318
LL | None => ()
1419
| ^^^^ expected enum `Result`, found enum `Option`
1520
|

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
error[E0308]: mismatched types
22
--> $DIR/issue-13466.rs:8:9
33
|
4+
LL | let _x: usize = match Some(1) {
5+
| ------- this expression has type `Option<{integer}>`
46
LL | Ok(u) => u,
57
| ^^^^^ expected enum `Option`, found enum `Result`
68
|
@@ -10,6 +12,9 @@ LL | Ok(u) => u,
1012
error[E0308]: mismatched types
1113
--> $DIR/issue-13466.rs:14:9
1214
|
15+
LL | let _x: usize = match Some(1) {
16+
| ------- this expression has type `Option<{integer}>`
17+
...
1318
LL | Err(e) => panic!(e)
1419
| ^^^^^^ expected enum `Option`, found enum `Result`
1520
|

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | struct Test;
55
| ------------ unit struct defined here
66
...
77
LL | let Test = 1;
8-
| ^^^^
8+
| ^^^^ - this expression has type `{integer}`
99
| |
1010
| expected integer, found struct `Test`
1111
| `Test` is interpreted as a unit struct, not a new binding

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
error[E0308]: mismatched types
22
--> $DIR/issue-3680.rs:3:9
33
|
4+
LL | match None {
5+
| ---- this expression has type `Option<_>`
46
LL | Err(_) => ()
57
| ^^^^^^ expected enum `Option`, found enum `Result`
68
|

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ LL | const A: (isize,isize) = (4,2);
55
| ------------------------------- constant defined here
66
LL | fn main() {
77
LL | match 42 { A => () }
8-
| ^
9-
| |
10-
| expected integer, found tuple
11-
| `A` is interpreted as a constant, not a new binding
12-
| help: introduce a new binding instead: `other_a`
8+
| -- ^
9+
| | |
10+
| | expected integer, found tuple
11+
| | `A` is interpreted as a constant, not a new binding
12+
| | help: introduce a new binding instead: `other_a`
13+
| this expression has type `{integer}`
1314
|
1415
= note: expected type `{integer}`
1516
found tuple `(isize, isize)`

src/test/ui/issues/issue-72574-1.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ LL | (_a, _x @ ..) => {}
2121
error[E0308]: mismatched types
2222
--> $DIR/issue-72574-1.rs:4:9
2323
|
24+
LL | match x {
25+
| - this expression has type `({integer}, {integer}, {integer})`
2426
LL | (_a, _x @ ..) => {}
2527
| ^^^^^^^^^^^^^ expected a tuple with 3 elements, found one with 2 elements
2628
|

src/test/ui/keyword/keyword-false-as-identifier.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0308]: mismatched types
22
--> $DIR/keyword-false-as-identifier.rs:2:9
33
|
44
LL | let false = 22;
5-
| ^^^^^ expected integer, found `bool`
5+
| ^^^^^ -- this expression has type `{integer}`
6+
| |
7+
| expected integer, found `bool`
68

79
error: aborting due to previous error
810

src/test/ui/keyword/keyword-true-as-identifier.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0308]: mismatched types
22
--> $DIR/keyword-true-as-identifier.rs:2:9
33
|
44
LL | let true = 22;
5-
| ^^^^ expected integer, found `bool`
5+
| ^^^^ -- this expression has type `{integer}`
6+
| |
7+
| expected integer, found `bool`
68

79
error: aborting due to previous error
810

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ LL | true ..= "what" => {}
2727
error[E0308]: mismatched types
2828
--> $DIR/match-range-fail.rs:18:9
2929
|
30+
LL | match 5 {
31+
| - this expression has type `{integer}`
3032
LL | 'c' ..= 100 => { }
3133
| ^^^ --- this is of type `{integer}`
3234
| |

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/mut/mut-pattern-mismatched.stderr

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ error[E0308]: mismatched types
33
|
44
LL | let &_
55
| ^^ types differ in mutability
6+
...
7+
LL | = foo;
8+
| --- this expression has type `&mut {integer}`
69
|
710
= note: expected mutable reference `&mut {integer}`
811
found reference `&_`
@@ -12,6 +15,9 @@ error[E0308]: mismatched types
1215
|
1316
LL | let &mut _
1417
| ^^^^^^ types differ in mutability
18+
...
19+
LL | = bar;
20+
| --- this expression has type `&{integer}`
1521
|
1622
= note: expected reference `&{integer}`
1723
found mutable reference `&mut _`

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ error[E0308]: mismatched types
8686
--> $DIR/already-bound-name.rs:30:32
8787
|
8888
LL | let (B(A(a, _) | B(a)) | A(a, A(a, _) | B(a))) = B(B(1));
89-
| - ^ expected integer, found enum `E`
90-
| |
89+
| - ^ ------- this expression has type `E<E<{integer}>>`
90+
| | |
91+
| | expected integer, found enum `E`
9192
| first introduced with type `{integer}` here
9293
|
9394
= note: expected type `{integer}`

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ error[E0308]: mismatched types
6565
--> $DIR/inconsistent-modes.rs:13:32
6666
|
6767
LL | let (Ok((ref a, b)) | Err((ref mut a, ref b))) = Ok((0, &0));
68-
| ----- ^^^^^^^^^ types differ in mutability
69-
| |
68+
| ----- ^^^^^^^^^ ----------- this expression has type `Result<({integer}, &{integer}), (_, _)>`
69+
| | |
70+
| | types differ in mutability
7071
| first introduced with type `&{integer}` here
7172
|
7273
= note: expected type `&{integer}`

0 commit comments

Comments
 (0)