]> git.lizzy.rs Git - rust.git/blob - src/test/ui/generator/issue-44197.rs
Auto merge of #102655 - joboet:windows_tls_opt, r=ChrisDenton
[rust.git] / src / test / ui / generator / issue-44197.rs
1 // run-pass
2
3 #![feature(generators, generator_trait)]
4
5 use std::ops::{Generator, GeneratorState};
6 use std::pin::Pin;
7
8 fn foo(_: &str) -> String {
9     String::new()
10 }
11
12 fn bar(baz: String) -> impl Generator<(), Yield = String, Return = ()> {
13     move || {
14         yield foo(&baz);
15     }
16 }
17
18 fn foo2(_: &str) -> Result<String, ()> {
19     Err(())
20 }
21
22 fn bar2(baz: String) -> impl Generator<(), Yield = String, Return = ()> {
23     move || {
24         if let Ok(quux) = foo2(&baz) {
25             yield quux;
26         }
27     }
28 }
29
30 fn main() {
31     assert_eq!(
32         Pin::new(&mut bar(String::new())).resume(()),
33         GeneratorState::Yielded(String::new())
34     );
35     assert_eq!(Pin::new(&mut bar2(String::new())).resume(()), GeneratorState::Complete(()));
36 }