rust/tests/ui/async-await/for-await.rs
Kevin Reid c48cdfe8ee Remove unnecessary lets and borrowing from Waker::noop() usage.
`Waker::noop()` now returns a `&'static Waker` reference, so it can be
passed directly to `Context` creation with no temporary lifetime issue.
2024-01-17 12:00:27 -08:00

24 lines
643 B
Rust

// run-pass
// edition: 2021
#![feature(async_iterator, async_iter_from_iter, const_waker, async_for_loop, noop_waker)]
use std::future::Future;
// make sure a simple for await loop works
async fn real_main() {
let iter = core::async_iter::from_iter(0..3);
let mut count = 0;
for await i in iter {
assert_eq!(i, count);
count += 1;
}
assert_eq!(count, 3);
}
fn main() {
let future = real_main();
let mut cx = &mut core::task::Context::from_waker(std::task::Waker::noop());
let mut future = core::pin::pin!(future);
while let core::task::Poll::Pending = future.as_mut().poll(&mut cx) {}
}