3 // revisions: default nomiropt
4 //[nomiropt]compile-flags: -Z mir-opt-level=0
6 // ignore-emscripten no threads support
7 // compile-flags: --test
9 #![feature(generators, generator_trait)]
11 use std::ops::{GeneratorState, Generator};
23 match Pin::new(&mut foo).resume(()) {
24 GeneratorState::Complete(()) => {}
25 s => panic!("bad state: {:?}", s),
31 let a = String::from("foo");
39 match Pin::new(&mut foo).resume(()) {
40 GeneratorState::Complete(ref s) if *s == "foo" => {}
41 s => panic!("bad state: {:?}", s),
51 match Pin::new(&mut foo).resume(()) {
52 GeneratorState::Yielded(()) => {}
53 s => panic!("bad state: {:?}", s),
55 match Pin::new(&mut foo).resume(()) {
56 GeneratorState::Complete(()) => {}
57 s => panic!("bad state: {:?}", s),
63 let b = String::from("foo");
68 match Pin::new(&mut foo).resume(()) {
69 GeneratorState::Yielded(ref s) if *s == "foo" => {}
70 s => panic!("bad state: {:?}", s),
72 match Pin::new(&mut foo).resume(()) {
73 GeneratorState::Complete(()) => {}
74 s => panic!("bad state: {:?}", s),
79 fn simple_yield_value() {
81 yield String::from("bar");
82 return String::from("foo")
85 match Pin::new(&mut foo).resume(()) {
86 GeneratorState::Yielded(ref s) if *s == "bar" => {}
87 s => panic!("bad state: {:?}", s),
89 match Pin::new(&mut foo).resume(()) {
90 GeneratorState::Complete(ref s) if *s == "foo" => {}
91 s => panic!("bad state: {:?}", s),
96 fn return_after_yield() {
97 let a = String::from("foo");
103 match Pin::new(&mut foo).resume(()) {
104 GeneratorState::Yielded(()) => {}
105 s => panic!("bad state: {:?}", s),
107 match Pin::new(&mut foo).resume(()) {
108 GeneratorState::Complete(ref s) if *s == "foo" => {}
109 s => panic!("bad state: {:?}", s),
115 assert_send_sync(|| {
118 assert_send_sync(|| {
119 yield String::from("foo");
121 assert_send_sync(|| {
123 return String::from("foo");
126 assert_send_sync(|| {
131 assert_send_sync(move || {
135 let a = String::from("a");
136 assert_send_sync(|| {
141 let a = String::from("a");
142 assert_send_sync(move || {
148 fn assert_send_sync<T: Send + Sync>(_: T) {}
152 fn send_over_threads() {
153 let mut foo = || { yield };
154 thread::spawn(move || {
155 match Pin::new(&mut foo).resume(()) {
156 GeneratorState::Yielded(()) => {}
157 s => panic!("bad state: {:?}", s),
159 match Pin::new(&mut foo).resume(()) {
160 GeneratorState::Complete(()) => {}
161 s => panic!("bad state: {:?}", s),
165 let a = String::from("a");
166 let mut foo = || { yield a };
167 thread::spawn(move || {
168 match Pin::new(&mut foo).resume(()) {
169 GeneratorState::Yielded(ref s) if *s == "a" => {}
170 s => panic!("bad state: {:?}", s),
172 match Pin::new(&mut foo).resume(()) {
173 GeneratorState::Complete(()) => {}
174 s => panic!("bad state: {:?}", s),