-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-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.
Description
Consider this code (playground):
pub fn test(input: &str) -> Result<serde_json::Value, String> {
match serde_json::from_str(input).unwrap() {
Ok(v) => Ok(v),
Err(why) => Err(format!("JSON decode failed: {:?}", why)),
}
}
This looks like perfectly reasonable code, but upon further inspection, you can see an .unwrap()
as a leftover from refactoring. However, Rust chooses a quite confusing way of pointing this out:
error[E0282]: type annotations needed
--> src/lib.rs:4:13
|
4 | Err(why) => Err(format!("JSON decode failed: {:?}", why)),
| ^^^ cannot infer type
As far as I am aware, there is no way to solve this problem with just a type annotation.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-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.