Statements do not return values. expressions do.
Expressions evaluate to a value.
Calling a function is an expression. Calling a macro is an expression. A new scope block created with curly brackets is an expression
in other languages, such as C and Ruby, where the assignment returns the value of the assignment. In those languages, you can write x = y = 6 and have both x and y have the value 6; that is not the case in Rust.
fn main() {
let y = {
let x = 3;
x + 1
};
println!("The value of y is: {y}");
}
This expression:
{
let x = 3;
x + 1
}
is a block that, in this case, evaluates to 4. That value gets bound to y as part of the let statement. Note that the x + 1 line doesn’t have a semicolon at the end, which is unlike most of the lines you’ve seen so far. Expressions do not include ending semicolons. If you add a semicolon to the end of an expression, you turn it into a statement, and it will then not return a value.