1 #![feature(generators, generator_trait)]
7 ops::{Generator, GeneratorState},
10 pub struct Ready<T>(Option<T>);
11 impl<T> Generator<()> for Ready<T> {
14 fn resume(mut self: Pin<&mut Self>, _args: ()) -> GeneratorState<(), T> {
15 GeneratorState::Complete(self.0.take().unwrap())
18 pub fn make_gen1<T>(t: T) -> Ready<T> {
22 fn require_send(_: impl Send) {}
23 //~^ NOTE required by a bound
24 //~| NOTE required by a bound
25 //~| NOTE required by this bound
26 //~| NOTE required by this bound
28 fn make_non_send_generator() -> impl Generator<Return = Arc<RefCell<i32>>> {
29 make_gen1(Arc::new(RefCell::new(0)))
34 let _non_send_gen = make_non_send_generator();
37 //~^ NOTE yield occurs here
38 //~| NOTE value is used across a yield
39 }; //~ NOTE later dropped here
40 require_send(send_gen);
41 //~^ ERROR generator cannot be sent between threads
45 pub fn make_gen2<T>(t: T) -> impl Generator<Return = T> {
46 //~^ NOTE appears within the type
47 //~| NOTE expansion of desugaring
48 || { //~ NOTE used within this generator
53 fn make_non_send_generator2() -> impl Generator<Return = Arc<RefCell<i32>>> { //~ NOTE appears within the type
54 //~^ NOTE expansion of desugaring
55 make_gen2(Arc::new(RefCell::new(0)))
59 let send_gen = || { //~ NOTE used within this generator
60 let _non_send_gen = make_non_send_generator2();
63 require_send(send_gen);
64 //~^ ERROR `RefCell<i32>` cannot be shared between threads safely
65 //~| NOTE `RefCell<i32>` cannot be shared between threads safely
66 //~| NOTE required for
67 //~| NOTE captures the following types