rust/tests/ui/iterators/iter-macro-not-async-closure.rs
Oli Scherer 5fbdfc3e10
Add iter macro
This adds an `iter!` macro that can be used to create movable
generators.

This also adds a yield_expr feature so the `yield` keyword can be used
within iter! macro bodies. This was needed because several unstable
features each need `yield` expressions, so this allows us to stabilize
them separately from any individual feature.

Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
Co-authored-by: Jieyou Xu <jieyouxu@outlook.com>
Co-authored-by: Travis Cross <tc@traviscross.com>
2025-06-03 10:52:32 -07:00

33 lines
787 B
Rust

// This test ensures iterators created with the `iter!` macro are not
// accidentally async closures.
//
//@ edition: 2024
//@ remap-src-base
#![feature(yield_expr, iter_macro)]
use std::task::{Waker, Context};
use std::iter::iter;
use std::pin::pin;
use std::future::Future;
async fn call_async_once(f: impl AsyncFnOnce()) {
f().await
}
fn main() {
let f = iter! { move || {
for i in 0..10 {
yield i;
}
}};
let x = pin!(call_async_once(f));
//~^ ERROR AsyncFnOnce()` is not satisfied
//~^^ ERROR AsyncFnOnce()` is not satisfied
//~^^^ ERROR AsyncFnOnce()` is not satisfied
//~^^^^ ERROR AsyncFnOnce()` is not satisfied
x.poll(&mut Context::from_waker(Waker::noop()));
//~^ ERROR AsyncFnOnce()` is not satisfied
}