Skip to content

Commit d5a54a9

Browse files
committed
add a compile-fail test for cyclic generators being forbidden
1 parent 120b27d commit d5a54a9

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2016 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+
11+
#![feature(generator_trait)]
12+
#![feature(generators)]
13+
14+
// Test that we cannot create a generator that returns a value of its
15+
// own type.
16+
17+
use std::ops::Generator;
18+
19+
pub fn want_cyclic_generator_return<T>(_: T)
20+
where T: Generator<Yield = (), Return = T>
21+
{
22+
}
23+
24+
fn supply_cyclic_generator_return() {
25+
want_cyclic_generator_return(|| {
26+
//~^ ERROR type mismatch
27+
if false { yield None.unwrap(); }
28+
None.unwrap()
29+
})
30+
}
31+
32+
pub fn want_cyclic_generator_yield<T>(_: T)
33+
where T: Generator<Yield = T, Return = ()>
34+
{
35+
}
36+
37+
fn supply_cyclic_generator_yield() {
38+
want_cyclic_generator_yield(|| {
39+
//~^ ERROR type mismatch
40+
if false { yield None.unwrap(); }
41+
None.unwrap()
42+
})
43+
}
44+
45+
fn main() { }

0 commit comments

Comments
 (0)