2024-01-29 11:41:51 -06:00
|
|
|
//@ edition:2021
|
|
|
|
// skip-filecheck
|
|
|
|
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
|
|
|
|
|
|
|
#![feature(async_closure, noop_waker, async_fn_traits)]
|
2024-06-29 16:25:44 -05:00
|
|
|
#![allow(unused)]
|
2024-01-29 11:41:51 -06:00
|
|
|
|
|
|
|
use std::future::Future;
|
2024-06-29 16:25:44 -05:00
|
|
|
use std::ops::{AsyncFn, AsyncFnMut, AsyncFnOnce};
|
2024-01-29 11:41:51 -06:00
|
|
|
use std::pin::pin;
|
|
|
|
use std::task::*;
|
|
|
|
|
|
|
|
pub fn block_on<T>(fut: impl Future<Output = T>) -> T {
|
|
|
|
let mut fut = pin!(fut);
|
|
|
|
let ctx = &mut Context::from_waker(Waker::noop());
|
|
|
|
|
|
|
|
loop {
|
|
|
|
match fut.as_mut().poll(ctx) {
|
|
|
|
Poll::Pending => {}
|
|
|
|
Poll::Ready(t) => break t,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-29 16:25:44 -05:00
|
|
|
async fn call(f: &mut impl AsyncFn(i32)) {
|
|
|
|
f(0).await;
|
|
|
|
}
|
|
|
|
|
2024-01-29 11:41:51 -06:00
|
|
|
async fn call_mut(f: &mut impl AsyncFnMut(i32)) {
|
|
|
|
f(0).await;
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn call_once(f: impl AsyncFnOnce(i32)) {
|
|
|
|
f(1).await;
|
|
|
|
}
|
|
|
|
|
2024-02-28 14:25:25 -06:00
|
|
|
async fn call_normal<F: Future<Output = ()>>(f: &impl Fn(i32) -> F) {
|
|
|
|
f(1).await;
|
|
|
|
}
|
|
|
|
|
2024-06-29 16:25:44 -05:00
|
|
|
async fn call_normal_mut<F: Future<Output = ()>>(f: &mut impl FnMut(i32) -> F) {
|
|
|
|
f(1).await;
|
|
|
|
}
|
|
|
|
|
2024-01-29 11:41:51 -06:00
|
|
|
// EMIT_MIR async_closure_shims.main-{closure#0}-{closure#0}.coroutine_closure_by_move.0.mir
|
|
|
|
// EMIT_MIR async_closure_shims.main-{closure#0}-{closure#0}-{closure#0}.coroutine_by_move.0.mir
|
2024-02-28 14:25:25 -06:00
|
|
|
// EMIT_MIR async_closure_shims.main-{closure#0}-{closure#1}.coroutine_closure_by_ref.0.mir
|
2024-06-29 16:25:44 -05:00
|
|
|
// EMIT_MIR async_closure_shims.main-{closure#0}-{closure#1}.coroutine_closure_by_move.0.mir
|
|
|
|
// EMIT_MIR async_closure_shims.main-{closure#0}-{closure#1}-{closure#0}.coroutine_by_move.0.mir
|
2024-02-06 22:40:58 -06:00
|
|
|
pub fn main() {
|
2024-01-29 11:41:51 -06:00
|
|
|
block_on(async {
|
|
|
|
let b = 2i32;
|
|
|
|
let mut async_closure = async move |a: i32| {
|
|
|
|
let a = &a;
|
|
|
|
let b = &b;
|
|
|
|
};
|
2024-06-29 16:25:44 -05:00
|
|
|
call(&mut async_closure).await;
|
2024-01-29 11:41:51 -06:00
|
|
|
call_mut(&mut async_closure).await;
|
|
|
|
call_once(async_closure).await;
|
2024-02-28 14:25:25 -06:00
|
|
|
|
2024-06-29 16:25:44 -05:00
|
|
|
let b = 2i32;
|
|
|
|
let mut async_closure = async |a: i32| {
|
2024-02-28 14:25:25 -06:00
|
|
|
let a = &a;
|
2024-06-29 16:25:44 -05:00
|
|
|
let b = &b;
|
2024-02-28 14:25:25 -06:00
|
|
|
};
|
|
|
|
call_normal(&async_closure).await;
|
2024-06-29 16:25:44 -05:00
|
|
|
call_normal_mut(&mut async_closure).await;
|
|
|
|
call_once(async_closure).await;
|
2024-01-29 11:41:51 -06:00
|
|
|
});
|
|
|
|
}
|