Skip to content

Commit f7af030

Browse files
committed
Document const_constructor feature
1 parent 580a194 commit f7af030

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/items/functions.md

+12-7
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,13 @@ aborts the process by executing an illegal instruction.
180180

181181
## Const functions
182182

183-
Functions qualified with the `const` keyword are const functions. _Const
184-
functions_ can be called from within [const context]s. When called from a const
185-
context, the function is interpreted by the compiler at compile time. The
186-
interpretation happens in the environment of the compilation target and not the
187-
host. So `usize` is `32` bits if you are compiling against a `32` bit system,
188-
irrelevant of whether you are building on a `64` bit or a `32` bit system.
183+
Functions qualified with the `const` keyword are const functions, as are
184+
[tuple struct] and [tuple variant] constructors. _Const functions_ can be
185+
called from within [const context]s. When called from a const context, the
186+
function is interpreted by the compiler at compile time. The interpretation
187+
happens in the environment of the compilation target and not the host. So
188+
`usize` is `32` bits if you are compiling against a `32` bit system, irrelevant
189+
of whether you are building on a `64` bit or a `32` bit system.
189190

190191
If a const function is called outside a [const context], it is indistinguishable
191192
from any other function. You can freely do anything with a const function that
@@ -214,7 +215,9 @@ Exhaustive list of permitted structures in const functions:
214215
are all permitted.
215216

216217
This rule also applies to type parameters of impl blocks that
217-
contain const methods
218+
contain const methods.
219+
220+
This does not apply to tuple struct and tuple variant constructors.
218221

219222
* Arithmetic and comparison operators on integers
220223
* All boolean operators except for `&&` and `||` which are banned since
@@ -360,6 +363,8 @@ attributes macros.
360363
[_Type_]: ../types.md#type-expressions
361364
[_WhereClause_]: generics.md#where-clauses
362365
[const context]: ../const_eval.md#const-context
366+
[tuple struct]: structs.md
367+
[tuple variant]: enumerations.md
363368
[external block]: external-blocks.md
364369
[path]: ../paths.md
365370
[block]: ../expressions/block-expr.md

0 commit comments

Comments
 (0)