Added some tests

This commit is contained in:
John Kåre Alsaker 2017-07-08 00:58:33 +02:00
parent 0b5b0122ae
commit cc40f58b8b
3 changed files with 45 additions and 13 deletions

View file

@ -0,0 +1,23 @@
// 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
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

View file

@ -10,7 +10,8 @@
#![feature(generators)]
const A: u8 = { yield 3u8; 3u8}; //~ ERROR yield statement outside of function body
static B: u8 = { yield 3u8; 3u8}; //~ ERROR yield statement outside of function body
fn main() {}
fn main() {
let gen = |start| { //~ ERROR generators cannot have explicit arguments
yield;
};
}

View file

@ -10,16 +10,24 @@
#![feature(generators)]
fn main() {
let mut a = Vec::<bool>::new();
use std::cell::Cell;
let mut test = || {
let _: () = gen arg;
yield 3;
a.push(true);
2
struct Flag<'a>(&'a Cell<bool>);
impl<'a> Drop for Flag<'a> {
fn drop(&mut self) {
self.0.set(false)
}
}
fn main() {
let alive = Cell::new(true);
let gen = || {
yield;
};
let a1 = test();
let a2 = test(); //~ ERROR use of moved value
gen.resume(Flag(&alive));
assert_eq!(alive.get(), false);
}