Skip to content

Commit

Permalink
add a compile-fail test for cyclic generators being forbidden
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Nov 11, 2017
1 parent 120b27d commit d5a54a9
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/test/compile-fail/generator-yielding-or-returning-itself.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(generator_trait)]
#![feature(generators)]

// Test that we cannot create a generator that returns a value of its
// own type.

use std::ops::Generator;

pub fn want_cyclic_generator_return<T>(_: T)
where T: Generator<Yield = (), Return = T>
{
}

fn supply_cyclic_generator_return() {
want_cyclic_generator_return(|| {
//~^ ERROR type mismatch
if false { yield None.unwrap(); }
None.unwrap()
})
}

pub fn want_cyclic_generator_yield<T>(_: T)
where T: Generator<Yield = T, Return = ()>
{
}

fn supply_cyclic_generator_yield() {
want_cyclic_generator_yield(|| {
//~^ ERROR type mismatch
if false { yield None.unwrap(); }
None.unwrap()
})
}

fn main() { }

0 comments on commit d5a54a9

Please sign in to comment.