Skip to content

Barely noticeable compiler suggestion #62597

Open

Description

fn main() {
    let new_service = {
        hyper::service::service_fn_ok(unimplemented!())
    };
    hyper::Server::bind(unimplemented!())
        .serve(new_service);
}

Compiler error:

error[E0277]: expected a `std::ops::Fn<()>` closure, found `hyper::service::service::ServiceFnOk<_, _>`
 --> src/main.rs:6:10
  |
6 |         .serve(new_service);
  |          ^^^^^ expected an `Fn<()>` closure, found `hyper::service::service::ServiceFnOk<_, _>`
  |
  = help: the trait `std::ops::Fn<()>` is not implemented for `hyper::service::service::ServiceFnOk<_, _>`
  = note: wrap the `hyper::service::service::ServiceFnOk<_, _>` in a closure with no arguments: `|| { /* code */ }
  = note: required because of the requirements on the impl of `hyper::service::new_service::NewService` for `hyper::service::service::ServiceFnOk<_, _>`
  = note: required because of the requirements on the impl of `hyper::service::make_service::MakeServiceRef<hyper::server::tcp::addr_stream::AddrStream>` for `hyper::service::service::ServiceFnOk<_, _>`

I think it's better to improve this note

  = note: wrap the `hyper::service::service::ServiceFnOk<_, _>` in a closure with no arguments: `|| { /* code */ }

So it's more noticeable and readable.

Playground link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.F-on_unimplementedError messages that can be tackled with `#[rustc_on_unimplemented]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions