Closed
Description
With the following code:
use std::process::{Command, Stdio};
fn main() {
let process = Command::new("wc")
.stdout(Stdio::piped())
.spawn()
.or_else(|err| {
panic!("oh no: {:?}", err);
}).unwrap();
}
You will get the error message:
error[E0282]: type annotations needed
--> src/main.rs:7:28
|
7 | .or_else(|err| {
| ^^^^^^^ cannot infer type for `F`
I can't help but feel that this is not useful, because it's not clear what F
is.
A novice user would be baffled. If we are lucky they might look at the signature of or_else
to see if F
is defined there. It is:
fn or_else<F, O>(self, op: O) -> Result<T, F>
where
O: FnOnce(E) -> Result<T, F>,
I think it would be useful to include this signature in the error message, so that the user can see what F
is without having to look it up in the docs.
Indeed, this error is fixed by adding types to the or_else
call, like so:
.or_else::<io::Error, _>(|err| {
...