Skip to content

Commit 2eb2ab5

Browse files
committed
Add explanatory note to async block type mismatch error
1 parent 16e8803 commit 2eb2ab5

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
3232
diag.note("no two closures, even if identical, have the same type");
3333
diag.help("consider boxing your closure and/or using it as a trait object");
3434
}
35+
(ty::Coroutine(def_id1, ..), ty::Coroutine(def_id2, ..))
36+
if self.tcx.coroutine_is_async(def_id1)
37+
&& self.tcx.coroutine_is_async(def_id2) =>
38+
{
39+
diag.note("every async block has a different type even when the output type is the same");
40+
}
3541
(ty::Alias(ty::Opaque, ..), ty::Alias(ty::Opaque, ..)) => {
3642
// Issue #63167
3743
diag.note("distinct uses of `impl Trait` result in different opaque types");

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

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ LL | fun(async {}, async {});
1010
|
1111
= note: expected `async` block `{async block@$DIR/coroutine-desc.rs:10:9: 10:17}`
1212
found `async` block `{async block@$DIR/coroutine-desc.rs:10:19: 10:27}`
13+
= note: every async block has a different type even when the output type is the same
1314
note: function defined here
1415
--> $DIR/coroutine-desc.rs:8:4
1516
|
@@ -51,6 +52,7 @@ LL | fun((async || {})(), (async || {})());
5152
|
5253
= note: expected `async` closure body `{async closure body@$DIR/coroutine-desc.rs:14:19: 14:21}`
5354
found `async` closure body `{async closure body@$DIR/coroutine-desc.rs:14:36: 14:38}`
55+
= note: every async block has a different type even when the output type is the same
5456
note: function defined here
5557
--> $DIR/coroutine-desc.rs:8:4
5658
|

0 commit comments

Comments
 (0)