Closed
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.