Skip to content

Barely noticeable compiler suggestion #62597

Open

Description

@In-line
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

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Jul 12, 2019
  2. estebank commented on Jul 13, 2019

    @estebank
    Contributor

    rustc_on_unimplemented should have a flag to hide the default E0277 notes.

  3. added
    F-on_unimplementedError messages that can be tackled with `#[rustc_on_unimplemented]`
    on Aug 4, 2019
  4. added
    E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
    and removed
    E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
    on Jun 11, 2021
  5. rylev commented on Jun 11, 2021

    @rylev
    Contributor

    Triage: the example code still produces the error but it no longer works in the playground as hyper 0.12 needs to be used.

  6. added
    E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
    on Sep 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

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.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleF-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