]> git.proxmox.com Git - rustc.git/blame - src/test/ui/run-pass/generator/issue-44197.rs
New upstream version 1.30.0+dfsg1
[rustc.git] / src / test / ui / run-pass / generator / issue-44197.rs
CommitLineData
2c00a5a8
XL
1// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
b7449926
XL
11// run-pass
12
0531ce1d 13#![feature(generators, generator_trait)]
2c00a5a8
XL
14
15use std::ops::{ Generator, GeneratorState };
16
17fn foo(_: &str) -> String {
18 String::new()
19}
20
21fn bar(baz: String) -> impl Generator<Yield = String, Return = ()> {
22 move || {
23 yield foo(&baz);
24 }
25}
26
27fn foo2(_: &str) -> Result<String, ()> {
28 Err(())
29}
30
31fn bar2(baz: String) -> impl Generator<Yield = String, Return = ()> {
32 move || {
33 if let Ok(quux) = foo2(&baz) {
34 yield quux;
35 }
36 }
37}
38
39fn main() {
0531ce1d
XL
40 unsafe {
41 assert_eq!(bar(String::new()).resume(), GeneratorState::Yielded(String::new()));
42 assert_eq!(bar2(String::new()).resume(), GeneratorState::Complete(()));
43 }
2c00a5a8 44}