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

Async-related type error messages defy expectations (in span location) #65180

Closed
nagisa opened this issue Oct 7, 2019 · 1 comment · Fixed by #67392
Closed

Async-related type error messages defy expectations (in span location) #65180

nagisa opened this issue Oct 7, 2019 · 1 comment · Fixed by #67392

Comments

@nagisa
Copy link
Member

@nagisa nagisa commented Oct 7, 2019

Consider for example this code (using hyper-0.13.0):

use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, TcpListener};

#[derive(failure::Fail, Debug)]
enum Error {
    #[fail(display="Cannot bind to port {}", _1)]
    CannotBind(#[cause] std::io::Error, u16),
    #[fail(display="Cannot create a server")]
    UncreatableServer(#[cause] hyper::Error),
    #[fail(display="Could not start serving metrics")]
    Unservable(#[cause] hyper::Error),
}

async fn serve_metrics(
    port: u16,
) -> Result<(), Error> {
    let bind_addrs = [
        SocketAddr::V6(SocketAddrV6::new(Ipv6Addr::UNSPECIFIED, port, 0, 0)),
        SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, port)),
    ];
    let listener = TcpListener::bind(&bind_addrs[..]).map_err(|e| Error::CannotBind(e, port))?;
    let server = hyper::server::Server::from_tcp(listener).map_err(Error::UncreatableServer)?;

    let server = server.serve(hyper::service::make_service_fn(move |_| {
        async move {
            Ok(hyper::service::service_fn(move |req| {
                async move {
                    hyper::Response::builder()
                        .status(hyper::StatusCode::NOT_FOUND)
                        .body(hyper::Body::empty())
                }
            }))
        }
    }));
    server.await.map_err(Error::Unservable)
}

This code will fail to compile due to types which cannot be fully inferred, with an error like this:

error[E0698]: type inside `async` object must be known in this context
  --> src/lib.rs:23:25
   |
23 |     let server = server.serve(hyper::service::make_service_fn(move |_| {
   |                         ^^^^^ cannot infer type for `ME`
   |
note: the type is part of the `async` object because of this `await`
  --> src/lib.rs:34:5
   |
34 |     server.await.map_err(Error::Unservable)
   |     ^^^^^^^^^^^^

However neither of these spans are anywhere near to the real problem which is the fact that Err variant is not inferred for Ok(hyper::service::service_fn(...)).

@nikomatsakis
Copy link
Contributor

@nikomatsakis nikomatsakis commented Oct 8, 2019

@rustbot assign @csmoe

@csmoe will do some investigation here and see if they can get an idea what's going on (and maybe fix)

Centril added a commit to Centril/rust that referenced this issue Dec 19, 2019
Fix unresolved type span inside async object

Closes rust-lang#65180
r? @estebank
It's hard to create a minimal repro for that issue, [decided](https://rust-lang.zulipchat.com/#narrow/stream/187312-wg-async-foundations/topic/meeting.202019.2E12.2E17/near/183675659) to give up finding mcve.
cc [previous take](rust-lang#65668)
Centril added a commit to Centril/rust that referenced this issue Dec 20, 2019
Fix unresolved type span inside async object

Closes rust-lang#65180
r? @estebank
It's hard to create a minimal repro for that issue, [decided](https://rust-lang.zulipchat.com/#narrow/stream/187312-wg-async-foundations/topic/meeting.202019.2E12.2E17/near/183675659) to give up finding mcve.
cc [previous take](rust-lang#65668)
@bors bors closed this in d7dc350 Dec 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

5 participants