It's not just the function's body, it's any block. Blocks in rust are expressions and return their last statement's value. It's nothing like Javascript's ASI where it's just inserting ; implicitly and only `return` can return a value.
It's also nothing like Javascript because Rust is statically typed. If you accidentally insert a semi-colon (or not), you're almost guaranteed to get a compile error.
Comments
The thing that really surprised me about Rust is the significance of a semicolon at the end of a function body. E.g.:
Returns unit while Returns 1. This reminds me of nothing so much as the infamous JavaScript ASI footgun where this returns undefined:It's not just the function's body, it's any block. Blocks in rust are expressions and return their last statement's value. It's nothing like Javascript's ASI where it's just inserting ; implicitly and only `return` can return a value.
It's also nothing like Javascript because Rust is statically typed. If you accidentally insert a semi-colon (or not), you're almost guaranteed to get a compile error.
The second function is a syntax error since you are not declaring the return value in the function signature.