Skip to content

Commit 9c3a6e7

Browse files
authored
Rollup merge of #137725 - oli-obk:i-want-to-move-it-move-it, r=compiler-errors,traviscross
Add `iter` macro See related discussion in https://rust-lang.zulipchat.com/#narrow/channel/481571-t-lang.2Fgen/topic/iter!.20macro/near/500784563 very little error case testing so far, but the success path works. There is also no `IterFn` trait yet, as T-lang didn't consider it something urgently needed I think we can implement it in follow-up PRs. r? lang for the tests, `@compiler-errors` for the impl
2 parents 385ee04 + eeea756 commit 9c3a6e7

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/pass/iter_macro.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#![feature(iter_macro, yield_expr)]
2+
3+
use std::iter::iter;
4+
5+
fn main() {
6+
let i = iter! { || {
7+
yield 0;
8+
for x in 5..10 {
9+
yield x * 2;
10+
}
11+
} };
12+
let mut i = i();
13+
assert_eq!(i.next(), Some(0));
14+
assert_eq!(i.next(), Some(10));
15+
assert_eq!(i.next(), Some(12));
16+
assert_eq!(i.next(), Some(14));
17+
assert_eq!(i.next(), Some(16));
18+
assert_eq!(i.next(), Some(18));
19+
assert_eq!(i.next(), None);
20+
assert_eq!(i.next(), None);
21+
assert_eq!(i.next(), None);
22+
}

0 commit comments

Comments
 (0)