about summary refs log tree commit diff
path: root/tests/ui/iterators/iter-macro-not-async-closure-simplified.rs
blob: 4fa14fda661cf11b1bf87a479b12cd633aad6ffd (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
// This test ensures iterators created with the `iter!` macro are not
// accidentally async closures.
//
// We test this both in a `narrow` and `wide` configuration because
// the way that the diagnostic is emitted varies depending on the
// diagnostic width.  If it's too narrow to fit the explanation, that
// explanation is moved to the `help` instead of the span label.
//
//@ edition: 2024
//@ revisions: narrow wide
//@[narrow] compile-flags: --diagnostic-width=20
//@[wide] compile-flags: --diagnostic-width=300

#![feature(yield_expr, iter_macro)]

use std::iter::iter;

fn call_async_once(_: impl AsyncFnOnce()) {}

fn main() {
    let f = iter! { move || {
        for i in 0..10 {
            yield i;
        }
    }};

    call_async_once(f);
    //~^ ERROR AsyncFnOnce()` is not satisfied
}