In the last paragraph of chapter 3.3 sub chapter Functions with Return Values states that nothing is returned when x + 1 is turned into a statement by adding a semicolon:
fn main() {
let x = plus_one(5);
println!("The value of x is: {x}");
}
fn plus_one(x: i32) -> i32 {
x + 1; // Here
}
But the compiler error shown on the same page says implicitly returns (). The book also correctly identifies () as "the unit type" in the same sentence, making the explanation internally contradictory.
A more accurate phrasing might be: "statements evaluate to (), the unit type, which doesn't satisfy the declared i32 return type."
In the last paragraph of chapter 3.3 sub chapter Functions with Return Values states that
nothing is returnedwhenx + 1is turned into a statement by adding a semicolon:But the compiler error shown on the same page says implicitly returns (). The book also correctly identifies () as "the unit type" in the same sentence, making the explanation internally contradictory.
A more accurate phrasing might be: "statements evaluate to (), the unit type, which doesn't satisfy the declared i32 return type."