]> git.lizzy.rs Git - rust.git/blob - src/test/ui/generator-yielding-or-returning-itself.rs
Rollup merge of #57132 - daxpedda:master, r=steveklabnik
[rust.git] / src / test / ui / generator-yielding-or-returning-itself.rs
1 #![feature(generator_trait)]
2 #![feature(generators)]
3
4 // Test that we cannot create a generator that returns a value of its
5 // own type.
6
7 use std::ops::Generator;
8
9 pub fn want_cyclic_generator_return<T>(_: T)
10     where T: Generator<Yield = (), Return = T>
11 {
12 }
13
14 fn supply_cyclic_generator_return() {
15     want_cyclic_generator_return(|| {
16         //~^ ERROR type mismatch
17         if false { yield None.unwrap(); }
18         None.unwrap()
19     })
20 }
21
22 pub fn want_cyclic_generator_yield<T>(_: T)
23     where T: Generator<Yield = T, Return = ()>
24 {
25 }
26
27 fn supply_cyclic_generator_yield() {
28     want_cyclic_generator_yield(|| {
29         //~^ ERROR type mismatch
30         if false { yield None.unwrap(); }
31         None.unwrap()
32     })
33 }
34
35 fn main() { }