Skip to content

Commit a63f5dc

Browse files
Remove confusing 'while checking' note from opaque future type mismatches
1 parent 8e68090 commit a63f5dc

18 files changed

+35
-236
lines changed

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

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ use crate::traits::{
6060

6161
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
6262
use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorGuaranteed, IntoDiagnosticArg};
63-
use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString, MultiSpan};
63+
use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
6464
use rustc_hir as hir;
6565
use rustc_hir::def::DefKind;
6666
use rustc_hir::def_id::{DefId, LocalDefId};
@@ -1468,51 +1468,17 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
14681468
for (key, values) in types.iter() {
14691469
let count = values.len();
14701470
let kind = key.descr();
1471-
let mut returned_async_output_error = false;
14721471
for &sp in values {
1473-
if sp.is_desugaring(DesugaringKind::Async) && !returned_async_output_error {
1474-
if [sp] != err.span.primary_spans() {
1475-
let mut span: MultiSpan = sp.into();
1476-
span.push_span_label(
1477-
sp,
1478-
format!(
1479-
"checked the `Output` of this `async fn`, {}{} {}{}",
1480-
if count > 1 { "one of the " } else { "" },
1481-
target,
1482-
kind,
1483-
pluralize!(count),
1484-
),
1485-
);
1486-
err.span_note(
1487-
span,
1488-
"while checking the return type of the `async fn`",
1489-
);
1490-
} else {
1491-
err.span_label(
1492-
sp,
1493-
format!(
1494-
"checked the `Output` of this `async fn`, {}{} {}{}",
1495-
if count > 1 { "one of the " } else { "" },
1496-
target,
1497-
kind,
1498-
pluralize!(count),
1499-
),
1500-
);
1501-
err.note("while checking the return type of the `async fn`");
1502-
}
1503-
returned_async_output_error = true;
1504-
} else {
1505-
err.span_label(
1506-
sp,
1507-
format!(
1508-
"{}{} {}{}",
1509-
if count == 1 { "the " } else { "one of the " },
1510-
target,
1511-
kind,
1512-
pluralize!(count),
1513-
),
1514-
);
1515-
}
1472+
err.span_label(
1473+
sp,
1474+
format!(
1475+
"{}{} {}{}",
1476+
if count == 1 { "the " } else { "one of the " },
1477+
target,
1478+
kind,
1479+
pluralize!(count),
1480+
),
1481+
);
15161482
}
15171483
}
15181484
}
@@ -1535,7 +1501,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
15351501
// |
15361502
// = note: expected unit type `()`
15371503
// found closure `[closure@$DIR/issue-20862.rs:2:5: 2:14 x:_]`
1538-
if !self.ignore_span.overlaps(span) {
1504+
//
1505+
// Also ignore opaque `Future`s that come from async fns.
1506+
if !self.ignore_span.overlaps(span)
1507+
&& !span.is_desugaring(DesugaringKind::Async)
1508+
{
15391509
self.types.entry(kind).or_default().insert(span);
15401510
}
15411511
}

tests/ui/async-await/dont-suggest-missing-await.stderr

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ LL | take_u32(x)
66
| |
77
| arguments to this function are incorrect
88
|
9-
note: while checking the return type of the `async fn`
10-
--> $DIR/dont-suggest-missing-await.rs:7:24
11-
|
12-
LL | async fn make_u32() -> u32 {
13-
| ^^^ checked the `Output` of this `async fn`, found opaque type
149
= note: expected type `u32`
1510
found opaque type `impl Future<Output = u32>`
1611
note: function defined here

tests/ui/async-await/generator-desc.stderr

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,6 @@ LL | fun(one(), two());
2121
| |
2222
| arguments to this function are incorrect
2323
|
24-
note: while checking the return type of the `async fn`
25-
--> $DIR/generator-desc.rs:5:16
26-
|
27-
LL | async fn one() {}
28-
| ^ checked the `Output` of this `async fn`, expected opaque type
29-
note: while checking the return type of the `async fn`
30-
--> $DIR/generator-desc.rs:6:16
31-
|
32-
LL | async fn two() {}
33-
| ^ checked the `Output` of this `async fn`, found opaque type
3424
= note: expected opaque type `impl Future<Output = ()>` (opaque type at <$DIR/generator-desc.rs:5:16>)
3525
found opaque type `impl Future<Output = ()>` (opaque type at <$DIR/generator-desc.rs:6:16>)
3626
= help: consider `await`ing on both `Future`s

tests/ui/async-await/issue-61076.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ async fn struct_() -> Struct {
5454
}
5555

5656
async fn tuple() -> Tuple {
57-
//~^ NOTE checked the `Output` of this `async fn`, expected opaque type
58-
//~| NOTE while checking the return type of the `async fn`
59-
//~| NOTE in this expansion of desugaring of `async` block or function
6057
Tuple(1i32)
6158
}
6259

tests/ui/async-await/issue-61076.stderr

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LL | foo().await?;
1111
| ++++++
1212

1313
error[E0277]: the `?` operator can only be applied to values that implement `Try`
14-
--> $DIR/issue-61076.rs:65:5
14+
--> $DIR/issue-61076.rs:62:5
1515
|
1616
LL | t?;
1717
| ^^ the `?` operator cannot be applied to type `T`
@@ -23,7 +23,7 @@ LL | t.await?;
2323
| ++++++
2424

2525
error[E0609]: no field `0` on type `impl Future<Output = Tuple>`
26-
--> $DIR/issue-61076.rs:74:26
26+
--> $DIR/issue-61076.rs:71:26
2727
|
2828
LL | let _: i32 = tuple().0;
2929
| ^ field not available in `impl Future`, but it is available in its `Output`
@@ -34,7 +34,7 @@ LL | let _: i32 = tuple().await.0;
3434
| ++++++
3535

3636
error[E0609]: no field `a` on type `impl Future<Output = Struct>`
37-
--> $DIR/issue-61076.rs:78:28
37+
--> $DIR/issue-61076.rs:75:28
3838
|
3939
LL | let _: i32 = struct_().a;
4040
| ^ field not available in `impl Future`, but it is available in its `Output`
@@ -45,7 +45,7 @@ LL | let _: i32 = struct_().await.a;
4545
| ++++++
4646

4747
error[E0599]: no method named `method` found for opaque type `impl Future<Output = Struct>` in the current scope
48-
--> $DIR/issue-61076.rs:82:15
48+
--> $DIR/issue-61076.rs:79:15
4949
|
5050
LL | struct_().method();
5151
| ^^^^^^ method not found in `impl Future<Output = Struct>`
@@ -56,19 +56,14 @@ LL | struct_().await.method();
5656
| ++++++
5757

5858
error[E0308]: mismatched types
59-
--> $DIR/issue-61076.rs:91:9
59+
--> $DIR/issue-61076.rs:88:9
6060
|
6161
LL | match tuple() {
6262
| ------- this expression has type `impl Future<Output = Tuple>`
6363
LL |
6464
LL | Tuple(_) => {}
6565
| ^^^^^^^^ expected opaque type, found struct `Tuple`
6666
|
67-
note: while checking the return type of the `async fn`
68-
--> $DIR/issue-61076.rs:56:21
69-
|
70-
LL | async fn tuple() -> Tuple {
71-
| ^^^^^ checked the `Output` of this `async fn`, expected opaque type
7267
= note: expected opaque type `impl Future<Output = Tuple>`
7368
found struct `Tuple`
7469
help: consider `await`ing on the `Future`

tests/ui/async-await/issue-98634.stderr

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ error[E0271]: expected `fn() -> impl Future<Output = ()> {callback}` to be a fn
44
LL | StructAsync { callback }.await;
55
| ^^^^^^^^ expected struct `Pin`, found opaque type
66
|
7-
note: while checking the return type of the `async fn`
8-
--> $DIR/issue-98634.rs:24:21
9-
|
10-
LL | async fn callback() {}
11-
| ^ checked the `Output` of this `async fn`, found opaque type
127
= note: expected struct `Pin<Box<(dyn Future<Output = ()> + 'static)>>`
138
found opaque type `impl Future<Output = ()>`
149
note: required by a bound in `StructAsync`
@@ -23,11 +18,6 @@ error[E0271]: expected `fn() -> impl Future<Output = ()> {callback}` to be a fn
2318
LL | StructAsync { callback }.await;
2419
| ^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `Pin`, found opaque type
2520
|
26-
note: while checking the return type of the `async fn`
27-
--> $DIR/issue-98634.rs:24:21
28-
|
29-
LL | async fn callback() {}
30-
| ^ checked the `Output` of this `async fn`, found opaque type
3121
= note: expected struct `Pin<Box<(dyn Future<Output = ()> + 'static)>>`
3222
found opaque type `impl Future<Output = ()>`
3323
note: required by a bound in `StructAsync`
@@ -42,11 +32,6 @@ error[E0271]: expected `fn() -> impl Future<Output = ()> {callback}` to be a fn
4232
LL | StructAsync { callback }.await;
4333
| ^^^^^^ expected struct `Pin`, found opaque type
4434
|
45-
note: while checking the return type of the `async fn`
46-
--> $DIR/issue-98634.rs:24:21
47-
|
48-
LL | async fn callback() {}
49-
| ^ checked the `Output` of this `async fn`, found opaque type
5035
= note: expected struct `Pin<Box<(dyn Future<Output = ()> + 'static)>>`
5136
found opaque type `impl Future<Output = ()>`
5237
note: required by a bound in `StructAsync`

tests/ui/async-await/issues/issue-102206.stderr

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ LL | std::mem::size_of_val(foo());
88
| | help: consider borrowing here: `&foo()`
99
| arguments to this function are incorrect
1010
|
11-
note: while checking the return type of the `async fn`
12-
--> $DIR/issue-102206.rs:3:16
13-
|
14-
LL | async fn foo() {}
15-
| ^ checked the `Output` of this `async fn`, found opaque type
1611
= note: expected reference `&_`
1712
found opaque type `impl Future<Output = ()>`
1813
note: function defined here

tests/ui/async-await/suggest-missing-await-closure.stderr

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ LL | take_u32(x)
66
| |
77
| arguments to this function are incorrect
88
|
9-
note: while checking the return type of the `async fn`
10-
--> $DIR/suggest-missing-await-closure.rs:8:24
11-
|
12-
LL | async fn make_u32() -> u32 {
13-
| ^^^ checked the `Output` of this `async fn`, found opaque type
149
= note: expected type `u32`
1510
found opaque type `impl Future<Output = u32>`
1611
note: function defined here

tests/ui/async-await/suggest-missing-await.stderr

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ LL | take_u32(x)
66
| |
77
| arguments to this function are incorrect
88
|
9-
note: while checking the return type of the `async fn`
10-
--> $DIR/suggest-missing-await.rs:5:24
11-
|
12-
LL | async fn make_u32() -> u32 {
13-
| ^^^ checked the `Output` of this `async fn`, found opaque type
149
= note: expected type `u32`
1510
found opaque type `impl Future<Output = u32>`
1611
note: function defined here
@@ -29,11 +24,6 @@ error[E0308]: mismatched types
2924
LL | dummy()
3025
| ^^^^^^^ expected `()`, found opaque type
3126
|
32-
note: while checking the return type of the `async fn`
33-
--> $DIR/suggest-missing-await.rs:18:18
34-
|
35-
LL | async fn dummy() {}
36-
| ^ checked the `Output` of this `async fn`, found opaque type
3727
= note: expected unit type `()`
3828
found opaque type `impl Future<Output = ()>`
3929
help: consider `await`ing on the `Future`
@@ -60,11 +50,6 @@ LL | |
6050
LL | | };
6151
| |_____- `if` and `else` have incompatible types
6252
|
63-
note: while checking the return type of the `async fn`
64-
--> $DIR/suggest-missing-await.rs:18:18
65-
|
66-
LL | async fn dummy() {}
67-
| ^ checked the `Output` of this `async fn`, expected opaque type
6853
= note: expected opaque type `impl Future<Output = ()>`
6954
found unit type `()`
7055
help: consider `await`ing on the `Future`
@@ -87,11 +72,6 @@ LL | |
8772
LL | | };
8873
| |_____- `match` arms have incompatible types
8974
|
90-
note: while checking the return type of the `async fn`
91-
--> $DIR/suggest-missing-await.rs:18:18
92-
|
93-
LL | async fn dummy() {}
94-
| ^ checked the `Output` of this `async fn`, expected opaque type
9575
= note: expected opaque type `impl Future<Output = ()>`
9676
found unit type `()`
9777
help: consider `await`ing on the `Future`
@@ -108,11 +88,6 @@ LL | let _x = match dummy() {
10888
LL | () => {}
10989
| ^^ expected opaque type, found `()`
11090
|
111-
note: while checking the return type of the `async fn`
112-
--> $DIR/suggest-missing-await.rs:18:18
113-
|
114-
LL | async fn dummy() {}
115-
| ^ checked the `Output` of this `async fn`, expected opaque type
11691
= note: expected opaque type `impl Future<Output = ()>`
11792
found unit type `()`
11893
help: consider `await`ing on the `Future`
@@ -129,11 +104,6 @@ LL | match dummy_result() {
129104
LL | Ok(_) => {}
130105
| ^^^^^ expected opaque type, found enum `Result`
131106
|
132-
note: while checking the return type of the `async fn`
133-
--> $DIR/suggest-missing-await.rs:57:28
134-
|
135-
LL | async fn dummy_result() -> Result<(), ()> {
136-
| ^^^^^^^^^^^^^^ checked the `Output` of this `async fn`, expected opaque type
137107
= note: expected opaque type `impl Future<Output = Result<(), ()>>`
138108
found enum `Result<_, _>`
139109
help: consider `await`ing on the `Future`
@@ -150,11 +120,6 @@ LL | match dummy_result() {
150120
LL | Err(_) => {}
151121
| ^^^^^^ expected opaque type, found enum `Result`
152122
|
153-
note: while checking the return type of the `async fn`
154-
--> $DIR/suggest-missing-await.rs:57:28
155-
|
156-
LL | async fn dummy_result() -> Result<(), ()> {
157-
| ^^^^^^^^^^^^^^ checked the `Output` of this `async fn`, expected opaque type
158123
= note: expected opaque type `impl Future<Output = Result<(), ()>>`
159124
found enum `Result<_, _>`
160125
help: consider `await`ing on the `Future`

tests/ui/impl-trait/in-trait/method-signature-matches.stderr

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,6 @@ LL | async fn owo(_: u8) {}
2424
| expected `()`, found `u8`
2525
| help: change the parameter type to match the trait: `()`
2626
|
27-
note: while checking the return type of the `async fn`
28-
--> $DIR/method-signature-matches.rs:20:25
29-
|
30-
LL | async fn owo(_: u8) {}
31-
| ^ checked the `Output` of this `async fn`, expected opaque type
32-
note: while checking the return type of the `async fn`
33-
--> $DIR/method-signature-matches.rs:20:25
34-
|
35-
LL | async fn owo(_: u8) {}
36-
| ^ checked the `Output` of this `async fn`, found opaque type
3727
note: type in trait
3828
--> $DIR/method-signature-matches.rs:16:21
3929
|

tests/ui/impl-trait/issue-102605.stderr

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ LL | convert_result(foo())
66
| |
77
| arguments to this function are incorrect
88
|
9-
note: while checking the return type of the `async fn`
10-
--> $DIR/issue-102605.rs:3:19
11-
|
12-
LL | async fn foo() -> Result<(), String> {
13-
| ^^^^^^^^^^^^^^^^^^ checked the `Output` of this `async fn`, found opaque type
149
= note: expected enum `Result<(), _>`
1510
found opaque type `impl Future<Output = Result<(), String>>`
1611
note: function defined here

tests/ui/impl-trait/issue-99914.stderr

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ error[E0308]: mismatched types
44
LL | t.and_then(|t| -> _ { bar(t) });
55
| ^^^^^^ expected enum `Result`, found opaque type
66
|
7-
note: while checking the return type of the `async fn`
8-
--> $DIR/issue-99914.rs:13:23
9-
|
10-
LL | async fn bar(t: Okay) {}
11-
| ^ checked the `Output` of this `async fn`, found opaque type
127
= note: expected enum `Result<_, Error>`
138
found opaque type `impl Future<Output = ()>`
149
help: try wrapping the expression in `Ok`

tests/ui/suggestions/if-then-neeing-semi.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,9 @@ fn extra_semicolon() {
1515
};
1616
}
1717

18-
async fn async_dummy() {} //~ NOTE checked the `Output` of this `async fn`, found opaque type
19-
//~| NOTE while checking the return type of the `async fn`
20-
//~| NOTE in this expansion of desugaring of `async` block or function
21-
//~| NOTE checked the `Output` of this `async fn`, expected opaque type
22-
//~| NOTE while checking the return type of the `async fn`
23-
//~| NOTE in this expansion of desugaring of `async` block or function
24-
async fn async_dummy2() {} //~ NOTE checked the `Output` of this `async fn`, found opaque type
25-
//~| NOTE checked the `Output` of this `async fn`, found opaque type
26-
//~| NOTE while checking the return type of the `async fn`
27-
//~| NOTE in this expansion of desugaring of `async` block or function
28-
//~| NOTE while checking the return type of the `async fn`
29-
//~| NOTE in this expansion of desugaring of `async` block or function
18+
async fn async_dummy() {}
19+
20+
async fn async_dummy2() {}
3021

3122
async fn async_extra_semicolon_same() {
3223
let _ = if true {

0 commit comments

Comments
 (0)