Skip to content

Commit

Permalink
Update for latest generators changes
Browse files Browse the repository at this point in the history
As of rust-lang/rust#49194 it's now unsafe to
resume a generator, but safe to create an immovable generator.

Fixes alexcrichton#74
  • Loading branch information
Nemo157 committed Mar 25, 2018
1 parent b6ea9af commit 015aa8d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion futures-await-async-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ where F: FnOnce(&Type, &[&Lifetime]) -> proc_macro2::TokenStream
let gen_function = respan(gen_function.into(), &output_span);
let body_inner = if pinned {
quote_cs! {
#gen_function (#[allow(unused_unsafe)] unsafe { static move || -> #output #gen_body })
#gen_function (static move || -> #output #gen_body)
}
} else {
quote_cs! {
Expand Down
5 changes: 4 additions & 1 deletion src/__rt/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ impl<T> Future for GenFuture<T>
fn poll(&mut self, ctx: &mut task::Context) -> Poll<Self::Item, Self::Error> {
CTX.with(|cell| {
let _r = Reset::new(ctx, cell);
match self.0.resume() {
// Because we are controlling the creation of our underlying
// generator, we know that this is definitely a movable generator
// so calling resume is always safe.
match unsafe { self.0.resume() } {
GeneratorState::Yielded(Async::Pending)
=> Ok(Async::Pending),
GeneratorState::Yielded(Async::Ready(mu))
Expand Down
4 changes: 3 additions & 1 deletion src/__rt/pinned_future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ impl<T> StableFuture for GenStableFuture<T>
CTX.with(|cell| {
let _r = Reset::new(ctx, cell);
let this: &mut Self = unsafe { Pin::get_mut(&mut self) };
match this.0.resume() {
// This is an immovable generator, but since we're only accessing
// it via a Pin this is safe.
match unsafe { this.0.resume() } {
GeneratorState::Yielded(Async::Pending)
=> Ok(Async::Pending),
GeneratorState::Yielded(Async::Ready(mu))
Expand Down
4 changes: 3 additions & 1 deletion src/__rt/pinned_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ impl<U, T> StableStream for GenStableStream<U, T>
let _r = Reset::new(ctx, cell);
let this: &mut Self = unsafe { Pin::get_mut(&mut self) };
if this.done { return Ok(Async::Ready(None)) }
match this.gen.resume() {
// This is an immovable generator, but since we're only accessing
// it via a Pin this is safe.
match unsafe { this.gen.resume() } {
GeneratorState::Yielded(Async::Ready(e)) => {
Ok(Async::Ready(Some(e)))
}
Expand Down
5 changes: 4 additions & 1 deletion src/__rt/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ impl<U, T> Stream for GenStream<U, T>
CTX.with(|cell| {
let _r = Reset::new(ctx, cell);
if self.done { return Ok(Async::Ready(None)) }
match self.gen.resume() {
// Because we are controlling the creation of our underlying
// generator, we know that this is definitely a movable generator
// so calling resume is always safe.
match unsafe { self.gen.resume() } {
GeneratorState::Yielded(Async::Ready(e)) => {
Ok(Async::Ready(Some(e)))
}
Expand Down

0 comments on commit 015aa8d

Please sign in to comment.