Skip to content

Commit 259ac5f

Browse files
authored
Prefer "const function" over const fn
1 parent b89691f commit 259ac5f

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/items/functions.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -169,21 +169,21 @@ of the compilation target and not the host. So `usize` is `32` bits if you are
169169
compiling against a `32` bit system, irrelevant of whether you are building on
170170
a `64` bit or a `32` bit system.
171171

172-
If a `const fn` is called outside a "const context", it is indistinguishable
173-
from any other function. You can freely do anything with a `const fn` that
172+
If a const function is called outside a "const context", it is indistinguishable
173+
from any other function. You can freely do anything with a const function that
174174
you can do with a regular function.
175175

176-
`const fn`s have various restrictions to makes sure that you cannot define a
177-
`const fn` that can't be evaluated at compile-time. It is, for example, not
178-
possible to write a random number generator as a const fn. Calling a
179-
const fn at compile-time will always yield the same result as calling it at
176+
const functions have various restrictions to makes sure that you cannot define a
177+
const function that can't be evaluated at compile-time. It is, for example, not
178+
possible to write a random number generator as a const function. Calling a
179+
const function at compile-time will always yield the same result as calling it at
180180
runtime, even when called multiple times. There's one exception to this rule:
181181
if you are doing complex floating point operations in extreme situations,
182182
then you might get (very slightly) different results.
183183
It is adviseable to not make array lengths and enum discriminants depend
184184
on floating point computations.
185185

186-
Exhaustive list of permitted structures in `const fn`:
186+
Exhaustive list of permitted structures in const functions:
187187

188188
> **Note**: this list is more restrictive than what you can write in
189189
> regular constants
@@ -197,21 +197,21 @@ Exhaustive list of permitted structures in `const fn`:
197197
are all permitted.
198198

199199
This rule also applies to type parameters of impl blocks that
200-
contain `const fn` methods
200+
contain const methods
201201

202202
* arithmetic and comparison operators on integers
203203
* all boolean operators except for `&&` and `||` which are banned since
204204
they are short-circuiting.
205205
* any kind of aggregate constructor (array, `struct`, `enum`, tuple, ...)
206-
* calls to other *safe* `const fn`s (whether by function call or method call)
206+
* calls to other *safe* const functions (whether by function call or method call)
207207
* index expressions on arrays and slices
208208
* field accesses on structs and tuples
209209
* reading from constants (but not statics, not even taking a reference to a static)
210210
* `&` and `*` (only dereferencing of references, not raw pointers)
211211
* casts except for raw pointer to integer casts
212212
* `const unsafe fn` is allowed, but the body must consist of safe operations
213213
only and you won't be able to call the `const unsafe fn` from within another
214-
`const fn` even if you use `unsafe`
214+
const function even if you use `unsafe`
215215

216216
[IDENTIFIER]: identifiers.html
217217
[RAW_STRING_LITERAL]: tokens.html#raw-string-literals

0 commit comments

Comments
 (0)