Skip to content

Commit

Permalink
Remove confusing usage of terminology "block of a function"
Browse files Browse the repository at this point in the history
It's usually referred to as the "body" of the function, and I'm making it consistent here.
In order to emphasize the nature of the body of a block, occasionally "body block" is used.
(One instance of "body block" was already present.)

This particularly improves the sentence that used to explain
"The block of a function is conceptually wrapped in a block that binds ..."
which was just plain confusing.
  • Loading branch information
steffahn authored and ehuss committed Jul 2, 2024
1 parent ad9a69c commit 40f497b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/items/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
> [^fn-param-2015]: Function parameters with only a type are only allowed
> in an associated function of a [trait item] in the 2015 edition.
A _function_ consists of a [block], along with a name, a set of parameters, and an output type.
A _function_ consists of a [block] (that's the _body_ of the function),
along with a name, a set of parameters, and an output type.
Other than a name, all these are optional.
Functions are declared with the keyword `fn`.
Functions may declare a set of *input* [*variables*][variables] as parameters, through which the caller passes arguments into the function, and the *output* [*type*][type] of the value the function will return to its caller on completion.
Expand Down Expand Up @@ -76,8 +77,8 @@ parameter may have an optional identifier, such as `args: ...`.

## Function body

The block of a function is conceptually wrapped in a block that binds the
argument patterns and then `return`s the value of the function's block. This
The body block of a function is conceptually wrapped in another block that first binds the
argument patterns and then `return`s the value of the function's body. This
means that the tail expression of the block, if evaluated, ends up being
returned to the caller. As usual, an explicit return expression within
the body of the function will short-cut that implicit return, if reached.
Expand Down Expand Up @@ -321,7 +322,7 @@ responsibility to ensure that.
## Attributes on functions

[Outer attributes][attributes] are allowed on functions. [Inner
attributes][attributes] are allowed directly after the `{` inside its [block].
attributes][attributes] are allowed directly after the `{` inside its body [block].

This example shows an inner attribute on a function. The function is documented
with just the word "Example".
Expand Down

0 comments on commit 40f497b

Please sign in to comment.