Closed
Description
The code below has superfluous semicolons in the branches of the if expression:
fn test() -> i32 {
let x = if (true) {
3;
}
else {
4;
};
x
}
The error message that results is:
error[E0308]: mismatched types
--> src/lib.rs:11:5
|
4 | fn test() -> i32 {
| --- expected `i32` because of return type
...
11 | x
| ^ expected `i32`, found `()`
This can be confusing to beginners, who may not understand unit type. However, since the expressions 3
and 4
can be shown to have no side effects, the code (as is) can't be what the user intended. Could the compiler produce a more targeted error message that mentions the superfluous semicolon?