diff --git a/src/items/functions.md b/src/items/functions.md index 1586adc33c..cdfda69d9c 100644 --- a/src/items/functions.md +++ b/src/items/functions.md @@ -9,9 +9,9 @@ Function -> FunctionReturnType? WhereClause? ( BlockExpression | `;` ) -FunctionQualifiers -> `const`? `async`?[^async-edition] ItemSafety?[^extern-qualifiers] (`extern` Abi?)? +FunctionQualifiers -> `const`? `async`?[^async-edition] Safety?[^extern-qualifiers] (`extern` Abi?)? -ItemSafety -> `safe`[^extern-safe] | `unsafe` +Safety -> `safe`[^safe-semantics] | `unsafe` Abi -> STRING_LITERAL | RAW_STRING_LITERAL @@ -34,12 +34,12 @@ FunctionReturnType -> `->` Type [^async-edition]: The `async` qualifier is not allowed in the 2015 edition. -[^extern-safe]: The `safe` function qualifier is only allowed semantically within `extern` blocks. - -[^extern-qualifiers]: *Relevant to editions earlier than Rust 2024*: Within `extern` blocks, the `safe` or `unsafe` function qualifier is only allowed when the `extern` is qualified as `unsafe`. +[^extern-qualifiers]: The `safe` or `unsafe` qualifiers are only allowed semantically within `extern` blocks. *Relevant to editions earlier than Rust 2024*: More specifically within `extern` blocks that are qualified as `unsafe`. [^fn-param-2015]: Function parameters with only a type are only allowed in an associated function of a [trait item] in the 2015 edition. +[^safe-semantics]: The `safe` qualifier is only allowed semantically on functions and function pointer types within `extern` blocks. + r[items.fn.intro] 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. diff --git a/src/items/static-items.md b/src/items/static-items.md index 395d69c3ce..54d03b1a99 100644 --- a/src/items/static-items.md +++ b/src/items/static-items.md @@ -4,10 +4,10 @@ r[items.static] r[items.static.syntax] ```grammar,items StaticItem -> - ItemSafety?[^extern-safety] `static` `mut`? IDENTIFIER `:` Type ( `=` Expression )? `;` + Safety?[^extern-qualifiers] `static` `mut`? IDENTIFIER `:` Type ( `=` Expression )? `;` ``` -[^extern-safety]: The `safe` and `unsafe` function qualifiers are only allowed semantically within `extern` blocks. +[^extern-qualifiers]: The `safe` and `unsafe` qualifiers are only allowed semantically within `extern` blocks. *Relevant to editions earlier than Rust 2024*: More specifically within `extern` blocks that are qualified as `unsafe`. r[items.static.intro] A *static item* is similar to a [constant], except that it represents an allocation in the program that is initialized with the initializer expression. All references and raw pointers to the static refer to the same allocation. diff --git a/src/types/function-pointer.md b/src/types/function-pointer.md index 08dfbbf235..143912b0c7 100644 --- a/src/types/function-pointer.md +++ b/src/types/function-pointer.md @@ -5,23 +5,21 @@ r[type.fn-pointer.syntax] ```grammar,types BareFunctionType -> ForLifetimes? FunctionTypeQualifiers `fn` - `(` FunctionParametersMaybeNamedVariadic? `)` BareFunctionReturnType? + `(` MaybeNamedFunctionParameters? `)` BareFunctionReturnType? -FunctionTypeQualifiers -> `unsafe`? (`extern` Abi?)? +FunctionTypeQualifiers -> Safety? (`extern` Abi?)? BareFunctionReturnType -> `->` TypeNoBounds -FunctionParametersMaybeNamedVariadic -> - MaybeNamedFunctionParameters | MaybeNamedFunctionParametersVariadic - MaybeNamedFunctionParameters -> - MaybeNamedParam ( `,` MaybeNamedParam )* `,`? + SelfParam `,`? + | (SelfParam `,`)? MaybeNamedParam ( `,` MaybeNamedParam )* `,`? MaybeNamedParam -> - OuterAttribute* ( ( IDENTIFIER | `_` ) `:` )? Type + OuterAttribute* ( MaybeNamedPattern `:` )? ( Type | `...` ) -MaybeNamedFunctionParametersVariadic -> - ( MaybeNamedParam `,` )* MaybeNamedParam `,` OuterAttribute* `...` +MaybeNamedPattern -> + `mut`? IDENTIFIER | ( `&` | `&&` )? ( `_` | `false` | `true` ) ``` r[type.fn-pointer.intro]