Skip to content

Commit 0180414

Browse files
committed
Finish BareFunctionType parameter grammar.
1 parent 95fe7d2 commit 0180414

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/types.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,12 +421,22 @@ All function items implement [`Fn`], [`FnMut`], [`FnOnce`], [`Copy`],
421421
> **<sup>Syntax</sup>**\
422422
> _BareFunctionType_ :\
423423
> &nbsp;&nbsp; [_ForLifetimes_]<sup>?</sup> [_FunctionFront_] `fn`\
424-
> &nbsp;&nbsp; &nbsp;&nbsp; `(` [_FunctionParametersMaybeNamedVariadic_]<sup>?</sup> `)` _BareFunctionReturnType_<sup>?</sup>
424+
> &nbsp;&nbsp; &nbsp;&nbsp; `(` _FunctionParametersMaybeNamedVariadic_<sup>?</sup> `)` _BareFunctionReturnType_<sup>?</sup>
425425
>
426426
> _BareFunctionReturnType_:\
427427
> &nbsp;&nbsp; `->` [_TypeNoBounds_]
428-
429-
<!-- TODO: _FunctionParametersMaybeNamedVariadic_ -->
428+
>
429+
> _FunctionParametersMaybeNamedVariadic_ :\
430+
> &nbsp;&nbsp; _MaybeNamedFunctionParameters_ | _MaybeNamedFunctionParametersVariadic_
431+
>
432+
> _MaybeNamedFunctionParameters_ :\
433+
> &nbsp;&nbsp; _MaybeNamedParam_ ( `,` _MaybeNamedParam_ )<sup>\*</sup> `,`<sup>?</sup>
434+
>
435+
> _MaybeNamedParam_ :\
436+
> &nbsp;&nbsp; ( ( [IDENTIFIER] | `_` ) `:` )<sup>?</sup> [_Type_]
437+
>
438+
> _MaybeNamedFunctionParametersVariadic_ :\
439+
> &nbsp;&nbsp; ( _MaybeNamedParam_ `,` )<sup>\*</sup> _MaybeNamedParam_ `,` `...`
430440
431441
Function pointer types, written using the `fn` keyword, refer to a function
432442
whose identity is not necessarily known at compile-time. They can be created
@@ -437,6 +447,9 @@ A function pointer type consists of a possibly-empty set of function-type
437447
modifiers (such as `unsafe` or `extern`), a sequence of input types and an
438448
output type.
439449

450+
Variadic parameters can only be specified with [`extern`] function types with
451+
the `"C"` or `"cdecl"` calling convention.
452+
440453
An example where `Binop` is defined as a function pointer type:
441454

442455
```rust
@@ -825,6 +838,7 @@ impl Printable for String {
825838

826839
> Note: The notation `&self` is a shorthand for `self: &Self`.
827840
841+
[IDENTIFIER]: identifiers.html
828842
[_ArrayType_]: #array-and-slice-types
829843
[_BareFunctionType_]: #function-pointer-types
830844
[_Expression_]: expressions.html
@@ -854,6 +868,7 @@ impl Printable for String {
854868
[`Send`]: special-types-and-traits.html#send
855869
[`Sync`]: special-types-and-traits.html#sync
856870
[`Sized`]: special-types-and-traits.html#sized
871+
[`extern`]: items/external-blocks.html
857872
[derive]: attributes.html#derive
858873
[`Vec<T>`]: ../std/vec/struct.Vec.html
859874
[dynamically sized type]: dynamically-sized-types.html

0 commit comments

Comments
 (0)