-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Description
- I have checked the latest
main
branch to see if this has already been fixed - I have searched existing issues and pull requests for duplicates
URL to the section(s) of the book with this problem:
https://doc.rust-lang.org/book/ch03-03-how-functions-work.html#function-bodies-contain-statements-and-expressions
Description of the problem:
Some clarification could be added to help differentiate the definition of functions, function bodies, function declaration, and function definitions.
The 3.3 section is describing statements vs expressions.
A description of statements says "Statements are instructions that perform some action and do not return a value."
Then below says "Statements do not return values."
But, in an apparent contradiction, it also says "Function definitions are also statements; the entire preceding example is a statement in itself." followed later by "Functions can return values to the code that calls them."
Suggested fix:
A line defining the relationship of function bodies, function declarations, and function definitions. Perhaps the removal of one of the terms if they are interchangeable. (I noticed that the description for listing 3-1 describes a "declaration" and then is followed immediately with a sentence about "definitions".)
A graphical description of all the statements and expressions and their relationships (statements can be made of expressions etc).
Statement
|.........................|
|........|
fn main() { let y = { let x = 3; x+1 }; }
|.| |..|
|................|
|.......................................|
Expression