Skip to content

Commit 9602df3

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

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

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

+7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ 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("no two async blocks, even if identical, have the same type");
40+
diag.help("consider pinning your async block and and casting it to a trait object");
41+
}
3542
(ty::Alias(ty::Opaque, ..), ty::Alias(ty::Opaque, ..)) => {
3643
// Issue #63167
3744
diag.note("distinct uses of `impl Trait` result in different opaque types");

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

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ 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: no two async blocks, even if identical, have the same type
14+
= help: consider pinning your async block and and casting it to a trait object
1315
note: function defined here
1416
--> $DIR/coroutine-desc.rs:8:4
1517
|
@@ -51,6 +53,8 @@ LL | fun((async || {})(), (async || {})());
5153
|
5254
= note: expected `async` closure body `{async closure body@$DIR/coroutine-desc.rs:14:19: 14:21}`
5355
found `async` closure body `{async closure body@$DIR/coroutine-desc.rs:14:36: 14:38}`
56+
= note: no two async blocks, even if identical, have the same type
57+
= help: consider pinning your async block and and casting it to a trait object
5458
note: function defined here
5559
--> $DIR/coroutine-desc.rs:8:4
5660
|

0 commit comments

Comments
 (0)