Futures-rs: v0.1.19 has broken backward compatibility

Created on 21 Mar 2018  路  5Comments  路  Source: rust-lang/futures-rs

The following code works with v0.1.18 (or earlier versions).

extern crate futures;

 use futures::Future;

 fn main() {
     let future = futures::lazy(|| {
         println!("Hello, world!");

         let result: Result<(), ()> = Ok(());
         result
     });

     let mut future = Some(future);
     let _ = future.poll();
 }

But in v0.1.19, the compiler emits the below error message.

error[E0599]: no method named `poll` found for type `std::option::Option<futures::Lazy<[closure@src/main.rs:6:32: 11:6], std::result::Result<(), ()>>>` in the current scope
  --> src/main.rs:13:20
   |
13 |     let _ = future.poll();
   |                    ^^^^

Most helpful comment

Ah, this was a breaking change intended for the 0.2 release that must have snuck it's way into the 0.1 branch. I'm about to get on a plane, but when I land I'll revert this asap and publish 1.20.

All 5 comments

Ok, I've looked at the change that introduced this regression. In 0.1.19 the Option impl from option.rs which looks identical to the one in master was backported. This changes the actual option type to:

use std::option;

pub struct Option<F> {
    inner: option::Option<F>,
}

//...

impl<F> Future for Option<F> where F: Future {
    type Item = option::Option<F::Item>;
    type Error = F::Error;

    fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
        match self.inner {
            None => Ok(Async::Ready(None)),
            Some(ref mut x) => x.poll().map(|x| x.map(Some)),
        }
    }
}

this used to be just a direct impl over the std::option::Option:

impl<F, T, E> Future for Option<F> where F: Future<Item=T, Error=E> {
    type Item = Option<T>;
    type Error = E;

    fn poll(&mut self) -> Poll<Option<T>, E> {
        match *self {
            None => Ok(Async::Ready(None)),
            Some(ref mut x) => x.poll().map(|x| x.map(Some)),
        }
    }
}

The difference in usage in libraries that are breaking is that people are relying directly on the std::option::Option Future impl, but the new impl is on a different type. That "Option" type can be gotten from an IntoFuture impl on std::option::Option, but this does represent a breaking API change.

@cramertj this looks like your change. Any thoughts?

Ah, this was a breaking change intended for the 0.2 release that must have snuck it's way into the 0.1 branch. I'm about to get on a plane, but when I land I'll revert this asap and publish 1.20.

FYI, I didn't notice this commit: https://github.com/rust-lang-nursery/futures-rs/commit/c5c976d9ee90311ac517c2b5ffe685081709da7c

That appears to have reverted this change.

The problem has been resolved by updating version to v0.1.20. Thanks!

was there another related breaking change that could have introduced https://github.com/rust-lang-nursery/futures-rs/issues/904 ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

flying-sheep picture flying-sheep  路  3Comments

olegnn picture olegnn  路  5Comments

yoshuawuyts picture yoshuawuyts  路  3Comments

seanmonstar picture seanmonstar  路  4Comments

Matthias247 picture Matthias247  路  4Comments