From 943d5ac763164ca5b6705dad1e78df5c31ff33e6 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Wed, 13 Dec 2017 09:34:46 -0600 Subject: [PATCH] Illustrating rust-lang/rust#46711 --- cargo.out | 26 +++++++++----------------- src/main.rs | 17 ++++++++--------- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/cargo.out b/cargo.out index d2607d1..707e180 100644 --- a/cargo.out +++ b/cargo.out @@ -1,24 +1,16 @@ Compiling futuretest v0.1.0 (file:///mnt/c/Users/Mahmoud/git/futuretest) -error[E0271]: type mismatch resolving ` as futures::IntoFuture>::Error == &str` - --> src/main.rs:13:10 +error[E0277]: the trait bound `(): futures::Future` is not satisfied + --> src/main.rs:17:1 | -13 | .and_then(|_| - | ^^^^^^^^ expected struct `std::string::String`, found &str +17 | / fn test() -> MapErr<(), ()> { +18 | | future::ok(()) +19 | | .map_err(|String| ()) +20 | | } + | |_^ the trait `futures::Future` is not implemented for `()` | - = note: expected type `std::string::String` - found type `&str` + = note: required by `futures::MapErr` -error[E0271]: type mismatch resolving ` as futures::IntoFuture>::Error == &str` - --> src/main.rs:20:10 - | -20 | core.run(f).unwrap(); - | ^^^ expected struct `std::string::String`, found &str - | - = note: expected type `std::string::String` - found type `&str` - = note: required because of the requirements on the impl of `futures::Future` for `futures::AndThen, [closure@src/main.rs:11:18: 11:43]>, [closure@src/main.rs:12:14: 12:67]>, futures::FutureResult<(), std::string::String>, [closure@src/main.rs:13:19: 16:14]>` - -error: aborting due to 2 previous errors +error: aborting due to previous error error: Could not compile `futuretest`. diff --git a/src/main.rs b/src/main.rs index fe2d780..767c803 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +#![feature(conservative_impl_trait)] + extern crate futures; extern crate tokio_core; use futures::future::{self}; @@ -7,15 +9,12 @@ use tokio_core::reactor::Core; fn main() { let mut core = Core::new().expect("Failed to initialize tokio_core reactor!"); - let f = future::result(Ok(())) - .map_err(|()| "&'static str error") - .map(|_| future::result(Err("another &'static str error"))) - .and_then(|_| - future::result(Ok(()) - .map_err(|()| "String error".to_owned()) - ) - ) - ; + let f = test(); core.run(f).unwrap(); } + +fn test() -> MapErr<(), ()> { + future::ok(()) + .map_err(|String| ()) +}