diff options
| author | Michael Goulet <michael@errs.io> | 2024-02-11 22:09:28 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2024-02-11 22:09:52 +0000 |
| commit | 87816378ab4190583df1b74bcfeacb8bc5dd4d70 (patch) | |
| tree | 72a32b37b738880a4f89bea4421bd8886b79c9eb /src/tools | |
| parent | cb024ba6e386242c5bea20fcc613c7edbc48f290 (diff) | |
Fix async closures in CTFE
Diffstat (limited to 'src/tools')
| -rw-r--r-- | src/tools/miri/tests/pass/async-closure.rs | 40 | ||||
| -rw-r--r-- | src/tools/miri/tests/pass/async-closure.stdout | 3 |
2 files changed, 43 insertions, 0 deletions
diff --git a/src/tools/miri/tests/pass/async-closure.rs b/src/tools/miri/tests/pass/async-closure.rs new file mode 100644 index 00000000000..9b2fc2948bf --- /dev/null +++ b/src/tools/miri/tests/pass/async-closure.rs @@ -0,0 +1,40 @@ +#![feature(async_closure, noop_waker, async_fn_traits)] + +use std::future::Future; +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, + } + } +} + +async fn call_once(f: impl async FnOnce(DropMe)) { + f(DropMe("world")).await; +} + +#[derive(Debug)] +struct DropMe(&'static str); + +impl Drop for DropMe { + fn drop(&mut self) { + println!("{}", self.0); + } +} + +pub fn main() { + block_on(async { + let b = DropMe("hello"); + let async_closure = async move |a: DropMe| { + println!("{a:?} {b:?}"); + }; + call_once(async_closure).await; + }); +} diff --git a/src/tools/miri/tests/pass/async-closure.stdout b/src/tools/miri/tests/pass/async-closure.stdout new file mode 100644 index 00000000000..34cfdedc44a --- /dev/null +++ b/src/tools/miri/tests/pass/async-closure.stdout @@ -0,0 +1,3 @@ +DropMe("world") DropMe("hello") +world +hello |
