-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
typing for async function pointer to generic function #134817
Comments
Reduction for the original error: use std::future::Future;
use std::task::Context;
fn make_context() -> Context<'static> {
todo!()
}
fn do_stuff<F>(mut async_fn: F)
where
F: AsyncFnMut(),
{
let _ = Box::pin(async {
async_fn().await;
})
.as_mut()
.poll(&mut make_context());
}
fn make_fn() -> fn() -> dyn Future<Output = ()> {
todo!()
}
fn main() {
do_stuff(make_fn());
} Going further gives use std::future::Future;
use std::task::Context;
fn make_context() -> Context<'static> {
todo!()
}
fn do_stuff<F>(mut async_fn: F)
where
F: AsyncFnMut(),
{
let _ = Box::pin(async_fn()).as_mut().poll(&mut make_context());
}
fn make_fn() -> fn() -> dyn Future<Output = ()> {
todo!()
}
fn main() {
do_stuff(make_fn());
} and removing the last layer gives use std::future::Future;
fn do_stuff<F>(mut async_fn: F)
where
F: AsyncFnMut(),
{
async_fn();
}
fn make_fn() -> fn() -> dyn Future<Output = ()> {
todo!()
}
fn main() {
do_stuff(make_fn());
} |
//@ compile-flags: --crate-type lib -Clink-dead-code --edition=2021
#![feature(async_closure)]
use std::future::Future;
use std::task::Context;
fn make_context() -> Context<'static> {
todo!()
}
fn do_stuff<F>(mut async_fn: F)
where
F: AsyncFnMut(),
{
let _ = Box::pin(async {
async_fn().await;
})
.as_mut()
.poll(&mut make_context());
}
fn make_fn() -> fn() -> dyn Future<Output = ()> {
todo!()
}
fn main() {
do_stuff(make_fn());
} bisects to #132611 cc @compiler-errors |
#132611 just added the |
when I do it like this #![feature(async_closure)]
#![feature(async_fn_traits)]
use std::ops::AsyncFnMut;
use std::future::Future;
use std::task::Context;
fn make_context() -> Context<'static> {
todo!()
}
fn do_stuff<F>(mut async_fn: F)
where
F: AsyncFnMut(),
{
let _ = Box::pin(async {
async_fn().await;
})
.as_mut()
.poll(&mut make_context());
}
fn make_fn() -> fn() -> dyn Future<Output = ()> {
todo!()
}
fn main() {
do_stuff(make_fn());
} it goes to nightly-2024-02-11 commit[0] 2024-02-09: Auto merge of #120852 - matthiaskrgr:rollup-01pr8gj, r=matthiaskrgr |
Code
Meta
rustc --version --verbose
:Error output
Backtrace
In
main
fn, the argumentHello::Bar
to do_stuff requires 2nd parameter to be annotated as compiler will complain about not being able to infer otherwise. I tried to providefn(&mut ()) -> dyn Future<Output = ()>
, and it crashes the compiler. The following code works without crashing the compilerThe text was updated successfully, but these errors were encountered: