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

FutureResult inner type mismatch error points to wrong line #46639

Closed
mqudsi opened this issue Dec 10, 2017 · 3 comments
Closed

FutureResult inner type mismatch error points to wrong line #46639

mqudsi opened this issue Dec 10, 2017 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example 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

Quite apart from #46606 but involving the same test code, an inner type mismatch in FutureResult chaining generates an error for one of mismatched types (perf #46606, which type is a matter of some contention), but aside from which type triggers the error, the error ultimately points to the wrong location.

For example, in the code below:

    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())
            )
        )
    ;

The error

13 |         .and_then(|_|
   |          ^^^^^^^^ expected struct `std::string::String`, found &str

points to the combinator resolving to a String, which:

  • According to the compiler, String was the right result and the &'static str result was the wrong one, so if anything, the error should be on the map_err or map lines and not the and_then line, however,
  • The error should actually point to the line of code that returned the &'str the compiler is complaining about, and not the function accepting the closure returning the wrong type.

(I imagine what is happening here is that and_then is an impl function being passed a FutureMap structure, and the compiler is finding a mismatch between the expected type passed to the the and_then function vs the actual inner type of FutureMap, and complaining at that juncture. Additionally, I no longer have any clue whether I should be posting criticism of compiler errors/hints while compiling against futures-rs here or in the rust-lang repo. Forgive me.)

@mqudsi
Copy link
Contributor Author

mqudsi commented Dec 13, 2017

Possibly related to/partial duplicate of #46658

@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 labels Jan 23, 2018
@crlf0710 crlf0710 added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 11, 2020
@estebank estebank added the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Feb 13, 2021
@apiraino
Copy link
Contributor

Closing as without an MCVE we don't have a lot to reason about

@apiraino apiraino closed this as not planned Won't fix, can't repro, duplicate, stale Jul 17, 2023
@mqudsi
Copy link
Contributor Author

mqudsi commented Jul 17, 2023

@apiraino the code was linked in the issue but is reproduced below for convenience:

extern crate futures;
extern crate tokio_core;
use futures::future::{self};
use futures::future::*;
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())
            )
        )
    ;

    core.run(f).unwrap();
}

compiled against futures 0.1.17 and tokio core 0.1.10

(Lock file in the repo linked in the original post.)

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 C-enhancement Category: An issue proposing an enhancement or a PR with one. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example 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

5 participants