rust/tests/ui/iterators/iter-macro-not-async-closure-simplified.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

30 lines
805 B
Rust

// 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
}