From d5a54a962786e4b1761d36e305ded66f5c1cfc79 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 9 Nov 2017 17:00:36 -0500 Subject: [PATCH] add a compile-fail test for cyclic generators being forbidden --- .../generator-yielding-or-returning-itself.rs | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/test/compile-fail/generator-yielding-or-returning-itself.rs diff --git a/src/test/compile-fail/generator-yielding-or-returning-itself.rs b/src/test/compile-fail/generator-yielding-or-returning-itself.rs new file mode 100644 index 0000000000000..13abdf616b29b --- /dev/null +++ b/src/test/compile-fail/generator-yielding-or-returning-itself.rs @@ -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 or the MIT license +// , 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) + where T: Generator +{ +} + +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) + where T: Generator +{ +} + +fn supply_cyclic_generator_yield() { + want_cyclic_generator_yield(|| { + //~^ ERROR type mismatch + if false { yield None.unwrap(); } + None.unwrap() + }) +} + +fn main() { }