Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
{
let (span, sugg) = if let Some(snippet) =
self.tcx.sess.source_map().span_to_snippet(obligation.cause.span).ok()
&& snippet.starts_with("|")
&& (snippet.starts_with("|")
|| snippet.starts_with("async ")
|| snippet.starts_with("async|"))
Comment thread
blueberry-dog marked this conversation as resolved.
Outdated
{
(obligation.cause.span, format!("({snippet})({args})"))
} else {
Expand Down
15 changes: 15 additions & 0 deletions tests/ui/suggestions/async-closure-inline-call-suggestion.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//@ edition:2021
use std::future::Future;

async fn f(c: impl Future<Output = ()>) {
c.await
}

fn main() {
f(async || {}());
//~^ ERROR E0618
Comment thread
blueberry-dog marked this conversation as resolved.
Outdated
//~| HELP if you meant to create this closure and immediately call it, surround the closure with parentheses
//~| ERROR E0277
Comment thread
blueberry-dog marked this conversation as resolved.
Outdated
//~| HELP the trait `Future` is not implemented for
//~| HELP use parentheses to call this closure
}
37 changes: 37 additions & 0 deletions tests/ui/suggestions/async-closure-inline-call-suggestion.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
error[E0618]: expected function, found `()`
--> $DIR/async-closure-inline-call-suggestion.rs:9:16
|
LL | f(async || {}());
| ^^--
| |
| call expression requires function
|
help: if you meant to create this closure and immediately call it, surround the closure with parentheses
|
LL | f((async || {})());
| + +

error[E0277]: `{async closure@$DIR/async-closure-inline-call-suggestion.rs:9:7: 9:15}` is not a future
--> $DIR/async-closure-inline-call-suggestion.rs:9:7
|
LL | f(async || {}());
| - ^^^^^^^^^^^^^ `{async closure@$DIR/async-closure-inline-call-suggestion.rs:9:7: 9:15}` is not a future
| |
| required by a bound introduced by this call
|
= help: the trait `Future` is not implemented for `{async closure@$DIR/async-closure-inline-call-suggestion.rs:9:7: 9:15}`
note: required by a bound in `f`
--> $DIR/async-closure-inline-call-suggestion.rs:4:20
|
LL | async fn f(c: impl Future<Output = ()>) {
| ^^^^^^^^^^^^^^^^^^^ required by this bound in `f`
help: use parentheses to call this closure
|
LL - f(async || {}());
LL + f((async || {}())());
Comment thread
fee1-dead marked this conversation as resolved.
Outdated
|

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0277, E0618.
For more information about an error, try `rustc --explain E0277`.