I'm trying to do the rustlings course and I don't understand the error I'm getting for the following code:
pub fn bigger(a: i32, b: i32) -> i32 {
if a > b {
a
}
b
}
Error:
error[E0308]: mismatched types
--> exercises/if/if1.rs:7:9
|
6 | / if a > b {
7 | | a
| | ^ expected `()`, found `i32`
8 | | }
| |_____- expected this to be `()`
|
help: you might have meant to return this value
|
7 | return a;
| ^^^^^^ ^
if I add the return, it does work but shouldn't the above also work? If I use an if-else it works also:
pub fn bigger(a: i32, b: i32) -> i32 {
if a > b {
a
} else {
b
}
}