Rollup merge of #82165 - nellshamrell:nell/fix-80658-B, r=estebank
Reword labels on E0308 involving async fn return type Fix for #80658. When someone writes code like this: ```rust fn foo() -> u8 { async fn async_fn() -> () {} async_fn() } ``` And they try to compile it, they will see an error that looks like this: ```bash error[E0308]: mismatched types --> test.rs:4:5 | 1 | fn foo() -> u8 { | -- expected `u8` because of return type 2 | async fn async_fn() -> () {} | -- checked the `Output` of this `async fn`, found opaque type 3 | 4 | async_fn() | ^^^^^^^^^^ expected `u8`, found opaque type | = note: while checking the return type of this `async fn` = note: expected type `u8` found opaque type `impl Future` ```
This commit is contained in:
commit
a56bbb134f
12 changed files with 49 additions and 22 deletions
|
@ -1484,13 +1484,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
for (key, values) in types.iter() {
|
||||
let count = values.len();
|
||||
let kind = key.descr();
|
||||
let mut returned_async_output_error = false;
|
||||
for sp in values {
|
||||
err.span_label(
|
||||
*sp,
|
||||
format!(
|
||||
"{}{}{} {}{}",
|
||||
if sp.is_desugaring(DesugaringKind::Async) {
|
||||
"the `Output` of this `async fn`'s "
|
||||
if sp.is_desugaring(DesugaringKind::Async)
|
||||
&& !returned_async_output_error
|
||||
{
|
||||
"checked the `Output` of this `async fn`, "
|
||||
} else if count == 1 {
|
||||
"the "
|
||||
} else {
|
||||
|
@ -1502,6 +1505,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
pluralize!(count),
|
||||
),
|
||||
);
|
||||
if sp.is_desugaring(DesugaringKind::Async)
|
||||
&& returned_async_output_error == false
|
||||
{
|
||||
err.note("while checking the return type of the `async fn`");
|
||||
returned_async_output_error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue