Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler incorrectly reports function return type declaration as source of inner type mismatch with conservative_impl_trait #46644

Open
mqudsi opened this issue Dec 10, 2017 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@mqudsi
Copy link
Contributor

mqudsi commented Dec 10, 2017

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.
@mqudsi mqudsi changed the title Compiler incorrectly reports function declaration as source of inner type mismatch with conservative_impl_trait Compiler incorrectly reports function return type declaration as source of inner type mismatch with conservative_impl_trait Dec 13, 2017
@pietroalbini pietroalbini added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-diagnostics Area: Messages for errors, warnings, and lints A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. labels Jan 30, 2018
@estebank
Copy link
Contributor

Triage: no change.

@estebank estebank added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Sep 26, 2019
@estebank estebank added the D-confusing Diagnostics: Confusing error or lint that should be reworked. label Oct 15, 2019
@estebank
Copy link
Contributor

estebank commented Aug 4, 2023

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`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants