fn some_fn(a:f32 , b: f32) -> Result<f32, &'static str> {
if b == 0.0 {
return Err("Error for some reason");
}
Ok(a / b)
}
This function compiles, but when I remove the return statement (just for fun)
fn some_fn(a:f32 , b: f32) -> Result<f32, &'static str> {
if b == 0.0 {
Err("Error for some reason");
}
Ok(a / b)
}
It gives the error:
error[E0282]: type annotations needed
--> main.rs:3:9
|
3 | Err("Error for some reason");
| ^^^ cannot infer type of the type parameter `T` declared on the enum `Result`
|
help: consider specifying the generic arguments
|
3 | Err::<T, &str>("Error for some reason");
| +++++++++++
What is going on here? Because I removed the return statement, I would expect it to say "Expected Result<> found something else". What's wrong with the type inference? And the suggestion? I know I should get an error but I am confused by this one.