-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-inferenceArea: Type inferenceArea: Type inferenceC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: 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.Relevant to the compiler team, which will review and decide on the PR/issue.WG-diagnosticsWorking group: DiagnosticsWorking group: Diagnostics
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| {
...
scottmcm, estebank, bkda, ValarDragon, terrence2 and 2 more
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-inferenceArea: Type inferenceArea: Type inferenceC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: 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.Relevant to the compiler team, which will review and decide on the PR/issue.WG-diagnosticsWorking group: DiagnosticsWorking group: Diagnostics