Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions compiler/rustc_infer/src/infer/error_reporting/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
}
(Some(ty), _) if self.same_type_modulo_infer(ty, exp_found.found) => match cause.code()
{
ObligationCauseCode::Pattern { span: Some(then_span), .. } => {
Some(ConsiderAddingAwait::FutureSugg { span: then_span.shrink_to_hi() })
ObligationCauseCode::Pattern { span: Some(then_span), origin_expr, .. } => {
origin_expr.then_some(ConsiderAddingAwait::FutureSugg {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any test that exercises the case when origin_expr is Some?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, most of suggest-missing-await.rs does

span: then_span.shrink_to_hi(),
})
}
ObligationCauseCode::IfExpression(box IfExpressionCause { then_id, .. }) => {
let then_span = self.find_block_span_from_hir_id(*then_id);
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/async-await/suggest-missing-await.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,11 @@ async fn suggest_await_in_generic_pattern() {
}
}

// Issue #126903
async fn do_async() {}
fn dont_suggest_awaiting_closure_patterns() {
Some(do_async()).map(|()| {});
//~^ ERROR mismatched types [E0308]
}

fn main() {}
14 changes: 13 additions & 1 deletion tests/ui/async-await/suggest-missing-await.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ help: consider `await`ing on the `Future`
LL | match dummy_result().await {
| ++++++

error: aborting due to 7 previous errors
error[E0308]: mismatched types
--> $DIR/suggest-missing-await.rs:77:27
|
LL | Some(do_async()).map(|()| {});
| ^^
| |
| expected future, found `()`
| expected due to this
|
= note: expected opaque type `impl Future<Output = ()>`
found unit type `()`

error: aborting due to 8 previous errors

For more information about this error, try `rustc --explain E0308`.