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

0 commit comments

Comments
 (0)