Skip to content

Commit 4b21b64

Browse files
authored
Merge pull request #677 from matthewjasper/const_constructor
Document `const_constructor` feature
2 parents beb79db + f7af030 commit 4b21b64

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
@@ -389,6 +392,8 @@ fn foo_oof(#[some_inert_attribute] arg: u8) {
389392
[_WhereClause_]: generics.md#where-clauses
390393
[_OuterAttribute_]: ../attributes.md
391394
[const context]: ../const_eval.md#const-context
395+
[tuple struct]: structs.md
396+
[tuple variant]: enumerations.md
392397
[external block]: external-blocks.md
393398
[path]: ../paths.md
394399
[block]: ../expressions/block-expr.md

0 commit comments

Comments
 (0)