Skip to content

Commit 26677eb

Browse files
committed
don't suggest awaiting type expr patterns
1 parent d371d17 commit 26677eb

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
209209
}
210210
(Some(ty), _) if self.same_type_modulo_infer(ty, exp_found.found) => match cause.code()
211211
{
212-
ObligationCauseCode::Pattern { span: Some(then_span), .. } => {
213-
Some(ConsiderAddingAwait::FutureSugg { span: then_span.shrink_to_hi() })
212+
ObligationCauseCode::Pattern { span: Some(then_span), origin_expr, .. } => {
213+
origin_expr.then_some(ConsiderAddingAwait::FutureSugg {
214+
span: then_span.shrink_to_hi(),
215+
})
214216
}
215217
ObligationCauseCode::IfExpression(box IfExpressionCause { then_id, .. }) => {
216218
let then_span = self.find_block_span_from_hir_id(*then_id);

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

+7
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,11 @@ async fn suggest_await_in_generic_pattern() {
7171
}
7272
}
7373

74+
// Issue #126903
75+
async fn do_async() {}
76+
fn dont_suggest_awaiting_closure_patterns() {
77+
Some(do_async()).map(|()| {});
78+
//~^ ERROR mismatched types [E0308]
79+
}
80+
7481
fn main() {}

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,18 @@ help: consider `await`ing on the `Future`
133133
LL | match dummy_result().await {
134134
| ++++++
135135

136-
error: aborting due to 7 previous errors
136+
error[E0308]: mismatched types
137+
--> $DIR/suggest-missing-await.rs:77:27
138+
|
139+
LL | Some(do_async()).map(|()| {});
140+
| ^^
141+
| |
142+
| expected future, found `()`
143+
| expected due to this
144+
|
145+
= note: expected opaque type `impl Future<Output = ()>`
146+
found unit type `()`
147+
148+
error: aborting due to 8 previous errors
137149

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

0 commit comments

Comments
 (0)