this the code:
fn main() {
fn diverging_fun() -> String {
println!("diverging function will never return.");
panic!("diverging");
}
fn test_diverging(condition:bool) ->i32 {
if condition {
3 + 5
} else {
diverging_fun();
//diverging_fun()
}
}
test_diverging(true);
}
1. When the function call diverging_fun() with semicolon, the error message:
<anon>:17:9: 21:10 error: if and else have incompatible types:
expected `i32`,
found `()`
(expected i32,
found ()) [E0308]
2. When the function call diverging_fun() without semicolon:
<anon>:12:21: 12:36 error: mismatched types:
expected `i32`,
found `collections::string::String`
(expected i32,
found struct `collections::string::String`) [E0308]
the second is normal, but the first one, the statement diverging_fun();
return a '()'
?