about summary refs log tree commit diff
path: root/tests/ui/iterators/iter-macro-not-async-closure.rs
blob: 634391883ea73debb8e5c129854a5f00d1783569 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// 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
}