Suggest call fn ctor passed as arg to fn with type param bounds

This commit is contained in:
Esteban Küber 2019-08-24 14:45:03 -07:00
parent 444bc3ca66
commit 5384d5584f
5 changed files with 117 additions and 7 deletions

View file

@ -0,0 +1,10 @@
// edition:2018
use std::future::Future;
async fn foo() {}
fn bar(f: impl Future<Output=()>) {}
fn main() {
bar(foo); //~ERROR E0277
}

View file

@ -0,0 +1,14 @@
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:5
|
LL | fn bar(f: impl Future<Output=()>) {}
| --------------------------------- required by `bar`
...
LL | bar(foo);
| ^^^ the trait `std::future::Future` is not implemented for `fn() -> impl std::future::Future {foo}`
|
= help: it looks like you forgot to use parentheses to call the function: `foo()`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.

View file

@ -0,0 +1,18 @@
// edition:2018
trait T {
type O;
}
struct S;
impl T for S {
type O = ();
}
fn foo() -> impl T<O=()> { S }
fn bar(f: impl T<O=()>) {}
fn main() {
bar(foo); //~ERROR E0277
}

View file

@ -0,0 +1,14 @@
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:5
|
LL | fn bar(f: impl T<O=()>) {}
| ----------------------- required by `bar`
...
LL | bar(foo);
| ^^^ the trait `T` is not implemented for `fn() -> impl T {foo}`
|
= help: it looks like you forgot to use parentheses to call the function: `foo()`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.