about summary refs log tree commit diff
path: root/src/test/ui
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2019-11-08 18:04:05 -0800
committerEsteban Küber <esteban@kuber.com.ar>2019-11-16 16:24:00 -0800
commit0487f0c0c38c1bae95bd786bc044307a3ff082e6 (patch)
tree8181469e0ffab3791e947e0c0f936e3c8fde7a0f /src/test/ui
parent5c5b8afd80e6fa1d24632153cb2257c686041d41 (diff)
downloadrust-0487f0c0c38c1bae95bd786bc044307a3ff082e6.tar.gz
rust-0487f0c0c38c1bae95bd786bc044307a3ff082e6.zip
Suggest calling async closure when needed
When using an async closure as a value in a place that expects a future,
suggest calling the closure.

Fix #65923.
Diffstat (limited to 'src/test/ui')
-rw-r--r--src/test/ui/suggestions/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.rs3
-rw-r--r--src/test/ui/suggestions/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr21
-rw-r--r--src/test/ui/suggestions/fn-ctor-passed-as-arg-where-it-should-have-been-called.rs2
-rw-r--r--src/test/ui/suggestions/fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr19
4 files changed, 42 insertions, 3 deletions
diff --git a/src/test/ui/suggestions/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.rs b/src/test/ui/suggestions/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.rs
index a2d2ba145bc..156162c9027 100644
--- a/src/test/ui/suggestions/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.rs
+++ b/src/test/ui/suggestions/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.rs
@@ -1,4 +1,5 @@
 // edition:2018
+#![feature(async_closure)]
 use std::future::Future;
 
 async fn foo() {}
@@ -7,4 +8,6 @@ fn bar(f: impl Future<Output=()>) {}
 
 fn main() {
     bar(foo); //~ERROR E0277
+    let async_closure = async || ();
+    bar(async_closure); //~ERROR E0277
 }
diff --git a/src/test/ui/suggestions/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr b/src/test/ui/suggestions/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr
index 1cc704b4433..05583876a06 100644
--- a/src/test/ui/suggestions/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr
+++ b/src/test/ui/suggestions/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr
@@ -1,6 +1,9 @@
 error[E0277]: the trait bound `fn() -> impl std::future::Future {foo}: std::future::Future` is not satisfied
-  --> $DIR/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:9:9
+  --> $DIR/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:10:9
    |
+LL | async fn foo() {}
+   |          --- consider calling this function
+LL | 
 LL | fn bar(f: impl Future<Output=()>) {}
    |    ---         ----------------- required by this bound in `bar`
 ...
@@ -10,6 +13,20 @@ LL |     bar(foo);
    |         the trait `std::future::Future` is not implemented for `fn() -> impl std::future::Future {foo}`
    |         help: use parentheses to call the function: `foo()`
 
-error: aborting due to previous error
+error[E0277]: the trait bound `[closure@$DIR/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:11:25: 11:36]: std::future::Future` is not satisfied
+  --> $DIR/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:12:9
+   |
+LL | fn bar(f: impl Future<Output=()>) {}
+   |    ---         ----------------- required by this bound in `bar`
+...
+LL |     let async_closure = async || ();
+   |                         -------- consider calling this closure
+LL |     bar(async_closure);
+   |         ^^^^^^^^^^^^^
+   |         |
+   |         the trait `std::future::Future` is not implemented for `[closure@$DIR/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:11:25: 11:36]`
+   |         help: use parentheses to call the closure: `async_closure()`
+
+error: aborting due to 2 previous errors
 
 For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/suggestions/fn-ctor-passed-as-arg-where-it-should-have-been-called.rs b/src/test/ui/suggestions/fn-ctor-passed-as-arg-where-it-should-have-been-called.rs
index acd149c5854..4303e5c5405 100644
--- a/src/test/ui/suggestions/fn-ctor-passed-as-arg-where-it-should-have-been-called.rs
+++ b/src/test/ui/suggestions/fn-ctor-passed-as-arg-where-it-should-have-been-called.rs
@@ -15,4 +15,6 @@ fn bar(f: impl T<O=()>) {}
 
 fn main() {
     bar(foo); //~ERROR E0277
+    let closure = || S;
+    bar(closure); //~ERROR E0277
 }
diff --git a/src/test/ui/suggestions/fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr b/src/test/ui/suggestions/fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr
index 7a49031bde7..91f60e8f426 100644
--- a/src/test/ui/suggestions/fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr
+++ b/src/test/ui/suggestions/fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr
@@ -1,6 +1,9 @@
 error[E0277]: the trait bound `fn() -> impl T {foo}: T` is not satisfied
   --> $DIR/fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:17:9
    |
+LL | fn foo() -> impl T<O=()> { S }
+   |    --- consider calling this function
+LL | 
 LL | fn bar(f: impl T<O=()>) {}
    |    ---         ------- required by this bound in `bar`
 ...
@@ -10,6 +13,20 @@ LL |     bar(foo);
    |         the trait `T` is not implemented for `fn() -> impl T {foo}`
    |         help: use parentheses to call the function: `foo()`
 
-error: aborting due to previous error
+error[E0277]: the trait bound `[closure@$DIR/fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:18:19: 18:23]: T` is not satisfied
+  --> $DIR/fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:19:9
+   |
+LL | fn bar(f: impl T<O=()>) {}
+   |    ---         ------- required by this bound in `bar`
+...
+LL |     let closure = || S;
+   |                   -- consider calling this closure
+LL |     bar(closure);
+   |         ^^^^^^^
+   |         |
+   |         the trait `T` is not implemented for `[closure@$DIR/fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:18:19: 18:23]`
+   |         help: use parentheses to call the closure: `closure()`
+
+error: aborting due to 2 previous errors
 
 For more information about this error, try `rustc --explain E0277`.