Closed
Description
rustc
does not produce any warnings for the following code:
fn main() {
8;
}
(which is very different from this code, which does not compile with rustc either, obviously)
fn main() {
8
}
What's happening is that, despite 8
being an "expression", the use of a semicolon afterwards allows not using it. This would be similar to something like
fn not_void() -> i32 {
8
}
fn main() {
not_void();
}
where discarding the return value of a function is fine, unless said function or type is marked with #[must_use]
.
However, gccrs does not seem to be able to discard the value of an expression (and thus transforming said expression into a "statement"). Therefore, the snippets of code above fail with the following error:
/tmp/main.rs:1:1: error: expected [()] got [<integer>] # or `got [i32]` if we use the `not_void()` function
1 | fn main() {
| ^
I haven't found any issues about the subject, but might not have looked hard enough! If so, I apologize