Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0ec3ea9

Browse files
committedOct 11, 2020
const keyword: brief paragraph on 'const fn'
1 parent 06a079c commit 0ec3ea9

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed
 

‎library/std/src/keyword_docs.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ mod break_keyword {}
102102

103103
#[doc(keyword = "const")]
104104
//
105-
/// Compile-time constants and deterministic functions.
105+
/// Compile-time constants and compile-time evaluable functions.
106+
///
107+
/// ## Compile-time constants
106108
///
107109
/// Sometimes a certain value is used many times throughout a program, and it can become
108110
/// inconvenient to copy it over and over. What's more, it's not always possible or desirable to
@@ -145,15 +147,28 @@ mod break_keyword {}
145147
///
146148
/// Constants, like statics, should always be in `SCREAMING_SNAKE_CASE`.
147149
///
150+
/// For more detail on `const`, see the [Rust Book] or the [Reference].
151+
///
152+
/// ## Compile-time evaluable functions
153+
///
154+
/// The other main use of the `const` keyword is in `const fn`. This marks a function as being
155+
/// callable in the body of a `const` or `static` item and in array initializers (commonly called
156+
/// "const contexts"). `const fn` are restricted in the set of operations they can perform, to
157+
/// ensure that they can be evaluated at compile-time. See the [Reference][const-eval] for more
158+
/// detail.
159+
///
160+
/// Turning a `fn` into a `const fn` has no effect on run-time uses of that function.
161+
///
162+
/// ## Other uses of `const`
163+
///
148164
/// The `const` keyword is also used in raw pointers in combination with `mut`, as seen in `*const
149165
/// T` and `*mut T`. More about `const` as used in raw pointers can be read at the Rust docs for the [pointer primitive].
150166
///
151-
/// For more detail on `const`, see the [Rust Book] or the [Reference].
152-
///
153167
/// [pointer primitive]: primitive.pointer.html
154168
/// [Rust Book]:
155169
/// ../book/ch03-01-variables-and-mutability.html#differences-between-variables-and-constants
156170
/// [Reference]: ../reference/items/constant-items.html
171+
/// [cosnt-eval]: ./reference/const_eval.html
157172
mod const_keyword {}
158173

159174
#[doc(keyword = "continue")]

0 commit comments

Comments
 (0)
Please sign in to comment.