Remove support for gen arg
This commit is contained in:
parent
93172045c8
commit
09a5d319ab
68 changed files with 106 additions and 508 deletions
|
|
@ -10,5 +10,4 @@
|
|||
|
||||
fn main() {
|
||||
yield true; //~ ERROR yield syntax is experimental
|
||||
gen arg; //~ ERROR gen arg syntax is experimental
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,14 +16,13 @@ use std::cell::Cell;
|
|||
fn main() {
|
||||
let _b = {
|
||||
let a = 3;
|
||||
(|| yield &a).resume(())
|
||||
(|| yield &a).resume()
|
||||
//~^ ERROR: `a` does not live long enough
|
||||
};
|
||||
|
||||
let _b = {
|
||||
let a = 3;
|
||||
|| {
|
||||
let _: () = gen arg; // FIXME: shouldn't be needed for inference
|
||||
yield &a
|
||||
//~^ ERROR: `a` does not live long enough
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,4 +14,4 @@ fn main() {
|
|||
let gen = |start| { //~ ERROR generators cannot have explicit arguments
|
||||
yield;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ fn main() {
|
|||
//~^ ERROR: Sync` is not satisfied
|
||||
let a = Cell::new(2);
|
||||
yield;
|
||||
let _: () = gen arg;
|
||||
});
|
||||
|
||||
let a = Cell::new(2);
|
||||
|
|
@ -29,6 +28,5 @@ fn main() {
|
|||
//~^ ERROR: Sync` is not satisfied
|
||||
drop(&a);
|
||||
yield;
|
||||
let _: () = gen arg;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,5 @@
|
|||
|
||||
#![feature(generators)]
|
||||
|
||||
const A: u8 = { yield 3u8; gen arg; 3u8};
|
||||
const A: u8 = { yield 3u8; 3u8};
|
||||
//~^ ERROR yield statement outside
|
||||
//~| ERROR gen arg expression outside
|
||||
|
|
|
|||
|
|
@ -10,6 +10,5 @@
|
|||
|
||||
#![feature(generators)]
|
||||
|
||||
fn main() { yield; gen arg; }
|
||||
fn main() { yield; }
|
||||
//~^ ERROR yield statement outside
|
||||
//~| ERROR gen arg expression outside
|
||||
|
|
|
|||
|
|
@ -10,6 +10,5 @@
|
|||
|
||||
#![feature(generators)]
|
||||
|
||||
static B: u8 = { yield 3u8; gen arg; 3u8};
|
||||
static B: u8 = { yield 3u8; 3u8};
|
||||
//~^ ERROR yield statement outside
|
||||
//~| ERROR gen arg expression outside
|
||||
|
|
|
|||
|
|
@ -13,10 +13,10 @@
|
|||
use std::ops::{State, Generator};
|
||||
|
||||
fn finish<T>(mut amt: usize, mut t: T) -> T::Return
|
||||
where T: Generator<(), Yield = ()>
|
||||
where T: Generator<Yield = ()>
|
||||
{
|
||||
loop {
|
||||
match t.resume(()) {
|
||||
match t.resume() {
|
||||
State::Yielded(()) => amt = amt.checked_sub(1).unwrap(),
|
||||
State::Complete(ret) => {
|
||||
assert_eq!(amt, 0);
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ fn t1() {
|
|||
};
|
||||
|
||||
let n = A.load(Ordering::SeqCst);
|
||||
drop(foo.resume(()));
|
||||
drop(foo.resume());
|
||||
assert_eq!(A.load(Ordering::SeqCst), n);
|
||||
drop(foo);
|
||||
assert_eq!(A.load(Ordering::SeqCst), n + 1);
|
||||
|
|
@ -50,7 +50,7 @@ fn t2() {
|
|||
};
|
||||
|
||||
let n = A.load(Ordering::SeqCst);
|
||||
drop(foo.resume(()));
|
||||
drop(foo.resume());
|
||||
assert_eq!(A.load(Ordering::SeqCst), n + 1);
|
||||
drop(foo);
|
||||
assert_eq!(A.load(Ordering::SeqCst), n + 1);
|
||||
|
|
@ -59,7 +59,6 @@ fn t2() {
|
|||
fn t3() {
|
||||
let b = B;
|
||||
let foo = || {
|
||||
let _: () = gen arg; // FIXME: this line should not be necessary
|
||||
yield;
|
||||
drop(b);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,38 +0,0 @@
|
|||
// 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, generator_trait)]
|
||||
|
||||
use std::ops::Generator;
|
||||
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
|
||||
|
||||
static A: AtomicUsize = ATOMIC_USIZE_INIT;
|
||||
|
||||
struct B;
|
||||
|
||||
impl Drop for B {
|
||||
fn drop(&mut self) {
|
||||
A.fetch_add(1, Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let b = B;
|
||||
|
||||
let mut gen = || {
|
||||
yield;
|
||||
};
|
||||
|
||||
assert_eq!(A.load(Ordering::SeqCst), 0);
|
||||
gen.resume(b);
|
||||
assert_eq!(A.load(Ordering::SeqCst), 1);
|
||||
drop(gen);
|
||||
assert_eq!(A.load(Ordering::SeqCst), 1);
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ impl<T: Generator<Return = ()>> Iterator for W<T> {
|
|||
type Item = T::Yield;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
match self.0.resume(()) {
|
||||
match self.0.resume() {
|
||||
State::Complete(..) => None,
|
||||
State::Yielded(v) => Some(v),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ fn main() {
|
|||
|
||||
assert_eq!(A.load(Ordering::SeqCst), 0);
|
||||
let res = panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
||||
foo.resume(())
|
||||
foo.resume()
|
||||
}));
|
||||
assert!(res.is_err());
|
||||
assert_eq!(A.load(Ordering::SeqCst), 1);
|
||||
|
|
@ -51,7 +51,7 @@ fn main() {
|
|||
|
||||
assert_eq!(A.load(Ordering::SeqCst), 1);
|
||||
let res = panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
||||
foo.resume(())
|
||||
foo.resume()
|
||||
}));
|
||||
assert!(res.is_err());
|
||||
assert_eq!(A.load(Ordering::SeqCst), 1);
|
||||
|
|
|
|||
|
|
@ -22,13 +22,13 @@ fn main() {
|
|||
};
|
||||
|
||||
let res = panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
||||
foo.resume(())
|
||||
foo.resume()
|
||||
}));
|
||||
assert!(res.is_err());
|
||||
|
||||
for _ in 0..10 {
|
||||
let res = panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
||||
foo.resume(())
|
||||
foo.resume()
|
||||
}));
|
||||
assert!(res.is_err());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,12 +21,12 @@ fn main() {
|
|||
yield;
|
||||
};
|
||||
|
||||
match foo.resume(()) {
|
||||
match foo.resume() {
|
||||
State::Complete(()) => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
|
||||
match panic::catch_unwind(move || foo.resume(())) {
|
||||
match panic::catch_unwind(move || foo.resume()) {
|
||||
Ok(_) => panic!("generator successfully resumed"),
|
||||
Err(_) => {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ fn simple() {
|
|||
}
|
||||
};
|
||||
|
||||
match foo.resume(()) {
|
||||
match foo.resume() {
|
||||
State::Complete(()) => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
|
|
@ -39,7 +39,7 @@ fn return_capture() {
|
|||
a
|
||||
};
|
||||
|
||||
match foo.resume(()) {
|
||||
match foo.resume() {
|
||||
State::Complete(ref s) if *s == "foo" => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
|
|
@ -51,11 +51,11 @@ fn simple_yield() {
|
|||
yield;
|
||||
};
|
||||
|
||||
match foo.resume(()) {
|
||||
match foo.resume() {
|
||||
State::Yielded(()) => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
match foo.resume(()) {
|
||||
match foo.resume() {
|
||||
State::Complete(()) => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
|
|
@ -68,11 +68,11 @@ fn yield_capture() {
|
|||
yield b;
|
||||
};
|
||||
|
||||
match foo.resume(()) {
|
||||
match foo.resume() {
|
||||
State::Yielded(ref s) if *s == "foo" => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
match foo.resume(()) {
|
||||
match foo.resume() {
|
||||
State::Complete(()) => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
|
|
@ -85,11 +85,11 @@ fn simple_yield_value() {
|
|||
return String::from("foo")
|
||||
};
|
||||
|
||||
match foo.resume(()) {
|
||||
match foo.resume() {
|
||||
State::Yielded(ref s) if *s == "bar" => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
match foo.resume(()) {
|
||||
match foo.resume() {
|
||||
State::Complete(ref s) if *s == "foo" => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
|
|
@ -103,11 +103,11 @@ fn return_after_yield() {
|
|||
return a
|
||||
};
|
||||
|
||||
match foo.resume(()) {
|
||||
match foo.resume() {
|
||||
State::Yielded(()) => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
match foo.resume(()) {
|
||||
match foo.resume() {
|
||||
State::Complete(ref s) if *s == "foo" => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
|
|
@ -116,40 +116,33 @@ fn return_after_yield() {
|
|||
#[test]
|
||||
fn send_and_sync() {
|
||||
assert_send_sync(|| {
|
||||
let _: () = gen arg;
|
||||
yield
|
||||
});
|
||||
assert_send_sync(|| {
|
||||
let _: () = gen arg;
|
||||
yield String::from("foo");
|
||||
});
|
||||
assert_send_sync(|| {
|
||||
let _: () = gen arg;
|
||||
yield;
|
||||
return String::from("foo");
|
||||
});
|
||||
let a = 3;
|
||||
assert_send_sync(|| {
|
||||
let _: () = gen arg;
|
||||
yield a;
|
||||
return
|
||||
});
|
||||
let a = 3;
|
||||
assert_send_sync(move || {
|
||||
let _: () = gen arg;
|
||||
yield a;
|
||||
return
|
||||
});
|
||||
let a = String::from("a");
|
||||
assert_send_sync(|| {
|
||||
let _: () = gen arg;
|
||||
yield ;
|
||||
drop(a);
|
||||
return
|
||||
});
|
||||
let a = String::from("a");
|
||||
assert_send_sync(move || {
|
||||
let _: () = gen arg;
|
||||
yield ;
|
||||
drop(a);
|
||||
return
|
||||
|
|
@ -162,11 +155,11 @@ fn send_and_sync() {
|
|||
fn send_over_threads() {
|
||||
let mut foo = || { yield };
|
||||
thread::spawn(move || {
|
||||
match foo.resume(()) {
|
||||
match foo.resume() {
|
||||
State::Yielded(()) => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
match foo.resume(()) {
|
||||
match foo.resume() {
|
||||
State::Complete(()) => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
|
|
@ -175,11 +168,11 @@ fn send_over_threads() {
|
|||
let a = String::from("a");
|
||||
let mut foo = || { yield a };
|
||||
thread::spawn(move || {
|
||||
match foo.resume(()) {
|
||||
match foo.resume() {
|
||||
State::Yielded(ref s) if *s == "a" => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
match foo.resume(()) {
|
||||
match foo.resume() {
|
||||
State::Complete(()) => {}
|
||||
s => panic!("bad state: {:?}", s),
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue