Compiler incorrectly reports function return type declaration as source of inner type mismatch with conservative_impl_trait
cc19fa5
Opened by Mahmoud Al-Qudsi at
Given a function specified as returning a composite type that incorrectly returns an object with an inner type mismatch, the compiler reports the error as being in the function return type declaration rather than at the point the incorrect item is returned.
A sample git repo can be found here: https://git.neosmart.net/mqudsi/futuretest/src/rust-46644
The code in question:
fn create_future() -> impl Future<Item=(), Error=()> {
return future::ok(Ok(()));
}
The compiler returns the following;
Compiling futuretest v0.1.0 (file:///mnt/d/GIT/futuretest)
error[E0271]: type mismatch resolving `<futures::FutureResult<std::result::Result<(), _>, ()> as futures::Future>::Item == ()`
--> src/main.rs:17:23
|
17 | fn create_future() -> impl Future<Item=(), Error=()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `std::result::Result`, found ()
|
= note: expected type `std::result::Result<(), _>`
found type `()`
= note: the return type of a function must have a statically known size
error: aborting due to previous error
error: Could not compile `futuretest`.
To learn more, run the command again with --verbose.
Triage: no change.
Esteban Kuber at 2019-09-26 18:21:05
Current output:
error[E0271]: type mismatch resolving `<Done<(), String> as IntoFuture>::Error == &str` --> src/main.rs:12:10 | 12 | .and_then(|_| | ^^^^^^^^ expected `&str`, found `String` | note: required by a bound in `futures::Future::and_then` --> /home/gh-estebank/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-0.1.17/src/future/mod.rs:527:29 | 525 | fn and_then<F, B>(self, f: F) -> AndThen<Self, B, F> | -------- required by a bound in this associated function 526 | where F: FnOnce(Self::Item) -> B, 527 | B: IntoFuture<Error = Self::Error>, | ^^^^^^^^^^^^^^^^^^^ required by this bound in `Future::and_then` error[E0599]: the method `and_then` exists for struct `AndThen<MapErr<Done<(), ()>, [closure@main.rs:11:18]>, Done<(), String>, [closure@main.rs:12:19]>`, but its trait bounds were not satisfied --> src/main.rs:17:10 | 10 | let f = future::result::<(),()>(Ok(())) | _____________- 11 | | .map_err(|_| "&'static str error") 12 | | .and_then(|_| 13 | | future::result(Ok(()) ... | 16 | | ) 17 | | .and_then(|_| future::result::<(), String>(Err("another &'static str error".to_owned()))) | | -^^^^^^^^ method cannot be called due to unsatisfied trait bounds | |_________| | | ::: /home/gh-estebank/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-0.1.17/src/future/result.rs:13:1 | 13 | pub struct FutureResult<T, E> { | ----------------------------- doesn't satisfy `<_ as IntoFuture>::Error = &str` | ::: /home/gh-estebank/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-0.1.17/src/future/and_then.rs:10:1 | 10 | pub struct AndThen<A, B, F> where A: Future, B: IntoFuture { | --------------------------- doesn't satisfy `_: Future` | = note: the following trait bounds were not satisfied: `<Failed<(), String> as futures::IntoFuture>::Error = &str` which is required by `futures::AndThen<futures::MapErr<Failed<(), ()>, [closure@src/main.rs:11:18: 11:21]>, Failed<(), String>, [closure@src/main.rs:12:19: 12:22]>: futures::Future` `futures::AndThen<futures::MapErr<Failed<(), ()>, [closure@src/main.rs:11:18: 11:21]>, Failed<(), String>, [closure@src/main.rs:12:19: 12:22]>: futures::Future` which is required by `&mut futures::AndThen<futures::MapErr<Failed<(), ()>, [closure@src/main.rs:11:18: 11:21]>, Failed<(), String>, [closure@src/main.rs:12:19: 12:22]>: futures::Future` Some errors have detailed explanations: E0271, E0599. For more information about an error, try `rustc --explain E0271`.Esteban Kuber at 2023-08-04 12:20:19