Cannot infer type for type parameter

Hi I am having trouble knowing how to pass a None type using the explicit trait it wraps.
I have the following function

pub async fn run(verbosity: u64, mut output_override: Option<Box<impl output::YosemiteOutput>>) -> Result<(), Box<dyn Error>> {

I call this method where the output_override is based on command line options like

match output_type {
        OutputType::console => {
            run(verbosity, Some(Box::new(outputs::console_output::ConsoleOutput::new()))).await
        },
        OutputType::postgres  => {
            run(verbosity, Some(Box::new(outputs::postgres_output::PostgresOutput::new()))).await
        },
        _ => {
            run(verbosity, do_conversion, None).await // causes error
        }
    }

Without the default option things work fine but when I try to pass None I get the error

type inside `async` block must be known in this context
   --> src/main.rs:441:13
    |
441 |             run(verbosity, None).await
    |             ^^^ type inside `async` block must be known in this context
   --> src/main.rs:441:13
    |
441 |             run(config_path, campus_name, requested_ip, requested_point_name, verbosity, do_conversion, None).await
    |             ^^^ cannot infer type for type parameter `impl output::YosemiteOutput` declared on the function `run`
    |
note: the type is part of the `async` block because of this `await`
   --> src/main.rs:441:13
    |
441 |             run(config_path, campus_name, requested_ip, requested_point_name, verbosity, do_conversion, None).await
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ declared on the function `run`
    |
note: the type is part of the `async` block because of this `await`
   --> src/main.rs:441:13
    |
441 |             run(verbosity, None).await
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I not sure what the error is telling me. How can I explicitly pass the type for that None using the explicit trait ?

None::<Type>, for instance None::<Box<outputs::console_output::ConsoleOutput>> (the real type probably doesn't matter in your case). Or the longer form Option::<Type>::None.

1 Like

Ah thanks. I just chose one real type to put it there. That was the main confusion of what I could put.

Could you make a minimized repro case in play.rust-lang.org and file a ticket? It feels to me that the error itself could be improved to at least point at the None.