diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2020-10-20 12:11:02 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-20 12:11:02 +0900 |
| commit | f9db00839efb1fedf48dbabbab3e0779ff2d8d5e (patch) | |
| tree | c6da1d5d018a5e23a6ef8e9d6f401180b8849cde /library/std/src | |
| parent | 24907f3507de7ce5d6908e3003e06a7f0b1a2ab6 (diff) | |
| parent | c8405d2251ce78651f591ed8a2189c41593f5110 (diff) | |
| download | rust-f9db00839efb1fedf48dbabbab3e0779ff2d8d5e.tar.gz rust-f9db00839efb1fedf48dbabbab3e0779ff2d8d5e.zip | |
Rollup merge of #77838 - RalfJung:const-fn, r=kennytm
const keyword: brief paragraph on 'const fn' `const fn` were mentioned in the title, but called "deterministic functions" which is not their main property (though at least currently it is a consequence of being const-evaluable). This adds a brief paragraph discussing them, also in the hopes of clarifying that they do *not* have any effect on run-time uses.
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/keyword_docs.rs | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/library/std/src/keyword_docs.rs b/library/std/src/keyword_docs.rs index 54ce0e7b831..a4bbb18da59 100644 --- a/library/std/src/keyword_docs.rs +++ b/library/std/src/keyword_docs.rs @@ -102,7 +102,9 @@ mod break_keyword {} #[doc(keyword = "const")] // -/// Compile-time constants and deterministic functions. +/// Compile-time constants and compile-time evaluable functions. +/// +/// ## Compile-time constants /// /// Sometimes a certain value is used many times throughout a program, and it can become /// 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 {} /// /// Constants, like statics, should always be in `SCREAMING_SNAKE_CASE`. /// +/// For more detail on `const`, see the [Rust Book] or the [Reference]. +/// +/// ## Compile-time evaluable functions +/// +/// The other main use of the `const` keyword is in `const fn`. This marks a function as being +/// callable in the body of a `const` or `static` item and in array initializers (commonly called +/// "const contexts"). `const fn` are restricted in the set of operations they can perform, to +/// ensure that they can be evaluated at compile-time. See the [Reference][const-eval] for more +/// detail. +/// +/// Turning a `fn` into a `const fn` has no effect on run-time uses of that function. +/// +/// ## Other uses of `const` +/// /// The `const` keyword is also used in raw pointers in combination with `mut`, as seen in `*const /// T` and `*mut T`. More about `const` as used in raw pointers can be read at the Rust docs for the [pointer primitive]. /// -/// For more detail on `const`, see the [Rust Book] or the [Reference]. -/// /// [pointer primitive]: primitive.pointer.html /// [Rust Book]: /// ../book/ch03-01-variables-and-mutability.html#differences-between-variables-and-constants /// [Reference]: ../reference/items/constant-items.html +/// [const-eval]: ../reference/const_eval.html mod const_keyword {} #[doc(keyword = "continue")] |
