Make yield and gen arg outside generator literals an error and update tests
This commit is contained in:
parent
5efb0cbe04
commit
bc9b4deeb5
7 changed files with 64 additions and 32 deletions
15
src/test/compile-fail/generator/yield-in-const.rs
Normal file
15
src/test/compile-fail/generator/yield-in-const.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright 2017 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(generators)]
|
||||
|
||||
const A: u8 = { yield 3u8; gen arg; 3u8};
|
||||
//~^ ERROR yield statement outside
|
||||
//~| ERROR gen arg expression outside
|
||||
15
src/test/compile-fail/generator/yield-in-function.rs
Normal file
15
src/test/compile-fail/generator/yield-in-function.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright 2017 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(generators)]
|
||||
|
||||
fn main() { yield; gen arg; }
|
||||
//~^ ERROR yield statement outside
|
||||
//~| ERROR gen arg expression outside
|
||||
|
|
@ -10,14 +10,6 @@
|
|||
|
||||
#![feature(generators)]
|
||||
|
||||
const A: u8 = { yield 3u8; gen arg; 3u8};
|
||||
//~^ ERROR yield statement outside
|
||||
//~| ERROR gen arg expression outside
|
||||
|
||||
static B: u8 = { yield 3u8; gen arg; 3u8};
|
||||
//~^ ERROR yield statement outside
|
||||
//~| ERROR gen arg expression outside
|
||||
|
||||
fn main() { yield; gen arg; }
|
||||
//~^ ERROR yield statement outside
|
||||
//~| ERROR gen arg expression outside
|
||||
|
|
@ -34,14 +34,15 @@ fn test() -> impl Generator<Return=(), Yield=u8> {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let start = 6;
|
||||
let end = 11;
|
||||
|
||||
let closure_test = || {
|
||||
for i in start..end {
|
||||
yield i
|
||||
let closure_test = |start| {
|
||||
|| {
|
||||
for i in start..end {
|
||||
yield i
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
assert!(W(test()).chain(W(closure_test)).eq(1..11));
|
||||
assert!(W(test()).chain(W(closure_test(6))).eq(1..11));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue