Skip to content

It'd be useful to delay E0412 after type checking to improve suggestions #58816

@estebank

Description

@estebank

With the following code:

async fn foo(i: usize, uri: Uri) -> Result<Duration, Error> {
    let client = Client::new();
    let now = Instant::now();
    match await!(client.get(uri).timeout(Duration::from_secs(20))) {
        Ok(_) => {
            Ok(Instant::now() - now)
        }
        Err(err) => Err(err),
    }
}

the diagnostic rightly complains about not knowing what Error is

error[E0412]: cannot find type `Error` in this scope
  --> src/main.rs:11:54
   |
11 | async fn foo(i: usize, uri: Uri) -> Result<Duration, Error> {
   |                                                      ^^^^^ not found in this scope
help: possible candidates are found in other modules, you can import them into scope
   |
5  | use core::fmt::Error;
   |
5  | use futures::core_reexport::fmt::Error;
   |
5  | use futures::io::Error;
   |
5  | use futures::rand_reexport::Error;
   |
and 10 other candidates

but it could use the information gathered later to limit the suggestions. If we change Error in the return type to (), the output is

error[E0271]: type mismatch resolving `<impl std::future::Future as std::future::Future>::Output == std::result::Result<std::time::Duration, ()>`
  --> src/main.rs:11:37
   |
11 | async fn foo(i: usize, uri: Uri) -> Result<Duration, ()> {
   |                                     ^^^^^^^^^^^^^^^^^^^^ expected struct `tokio_timer::timeout::Error`, found ()
   |
   = note: expected type `std::result::Result<_, tokio_timer::timeout::Error<hyper::error::Error>>`
              found type `std::result::Result<_, ()>`
   = note: the return type of a function must have a statically known size

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-papercutDiagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions