From 3c30c79f64bad654d13f237f8996f2f60c18d528 Mon Sep 17 00:00:00 2001 From: Matthew Woodcraft Date: Sun, 1 May 2022 17:19:45 +0100 Subject: [PATCH 1/2] functions.md: one sentence per line for the first section --- src/items/functions.md | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/items/functions.md b/src/items/functions.md index 814221070..9bbcb6d4d 100644 --- a/src/items/functions.md +++ b/src/items/functions.md @@ -43,15 +43,11 @@ > in an associated function of a [trait item] in the 2015 edition. A _function_ consists of a [block], along with a name and a set of parameters. -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. - -When referred to, a _function_ yields a first-class *value* of the -corresponding zero-sized [*function item type*], which -when called evaluates to a direct call to the function. +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. + +When referred to, a _function_ yields a first-class *value* of the corresponding zero-sized [*function item type*], which when called evaluates to a direct call to the function. For example, this is a simple function: ```rust From 42dc534ec62434ea1c05d3fc3430cda9280da583 Mon Sep 17 00:00:00 2001 From: Matthew Woodcraft Date: Sun, 1 May 2022 17:23:01 +0100 Subject: [PATCH 2/2] functions.md: state that the default return type is the unit type --- src/items/functions.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/items/functions.md b/src/items/functions.md index 9bbcb6d4d..adffd2af4 100644 --- a/src/items/functions.md +++ b/src/items/functions.md @@ -42,10 +42,11 @@ > [^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 and a set of parameters. +A _function_ consists of a [block], 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. +If the output type is not explicitly stated, it is the [unit type]. When referred to, a _function_ yields a first-class *value* of the corresponding zero-sized [*function item type*], which when called evaluates to a direct call to the function. @@ -387,6 +388,7 @@ fn foo_oof(#[some_inert_attribute] arg: u8) { [block]: ../expressions/block-expr.md [variables]: ../variables.md [type]: ../types.md#type-expressions +[unit type]: ../types/tuple.md [*function item type*]: ../types/function-item.md [Trait]: traits.md [attributes]: ../attributes.md