use futures::{future::{BoxFuture, Future, FutureExt}};
async fn f() -> bool {
true
}
#[allow(dead_code)]
struct Foo<'a, F>
where F: Future<Output=bool> + Send {
f: Option<BoxFuture<'a, F>>,
}
impl<'a, F> Foo<'a, F>
where F: Future<Output=bool> + Send + 'a {
fn new(f: F) -> Self {
Self {
f: Some(f.boxed())
}
}
}
fn main() {
Foo::new(f());
}
I expected to see this happen:
I wish the compiler had suggested that I should change f: Option<BoxFuture<'a, F>> to f: Option<BoxFuture<'a, F::Output>>,
Instead, this happened:
27 | impl<'a, F> Foo<'a, F>
| - this type parameter
...
33 | f: Some(f.boxed())
| ^^^^^^^^^
| |
| expected type parameter `F`, found `bool`
| help: you need to pin and box this expression: `Box::pin(f.boxed())`
*/
Rust compiler version (stable version on play.rust-lang.org).
1.43.1
N/A (compile error)Backtrace
cc @estebank, I think the suggestion shouldn't be applied here. Is there a way we can target it more precisely?
Triage: wg-async-foundations will track this until the incorrect suggestion is removed, other improvements to the suggestion are out of scope for us.
Some extra filtering in the following will be needed, but without further checking I can't tell for sure what the check should be:
https://github.com/rust-lang/rust/pull/69082/files#diff-1d1b0d29a2e8da97c6bfb6e364d920c7R5070-R5089
Most helpful comment
Simple reproducer:
playground