@@ -27,9 +27,7 @@ to be run.
27
27
* [ Struct] expressions.
28
28
* [ Enum variant] expressions.
29
29
* [ Block expressions] , including ` unsafe ` blocks.
30
- * [ let statements] and thus irrefutable [ patterns] , with the caveat that until ` if ` and ` match `
31
- are implemented, one cannot use both short circuiting operators (` && ` and ` || ` ) and let
32
- statements within the same constant.
30
+ * [ let statements] and thus irrefutable [ patterns] , including mutable bindings
33
31
* [ assignment expressions]
34
32
* [ compound assignment expressions]
35
33
* [ expression statements]
@@ -40,11 +38,15 @@ to be run.
40
38
* Built-in [ negation] , [ arithmetic] , [ logical] , [ comparison] or [ lazy boolean]
41
39
operators used on integer and floating point types, ` bool ` , and ` char ` .
42
40
* Shared [ borrow] s, except if applied to a type with [ interior mutability] .
43
- * The [ dereference operator] .
41
+ * The [ dereference operator] except for raw pointers .
44
42
* [ Grouped] expressions.
45
- * [ Cast] expressions, except pointer to address and
46
- function pointer to address casts.
43
+ * [ Cast] expressions, except
44
+ * pointer to address casts,
45
+ * function pointer to address casts, and
46
+ * unsizing casts to trait objects.
47
47
* Calls of [ const functions] and const methods.
48
+ * [ loop] , [ while] and [ ` while let ` ] expressions.
49
+ * [ if] , [ ` if let ` ] and [ match] expressions.
48
50
49
51
## Const context
50
52
@@ -57,6 +59,23 @@ A _const context_ is one of the following:
57
59
* [ statics]
58
60
* [ enum discriminants]
59
61
62
+ ## Const Functions
63
+
64
+ A _ const fn_ is a function that one is permitted to call from a const context. Declaring a function
65
+ ` const ` has no effect on any existing uses, it only restricts the types that arguments and the
66
+ return type may use, as well as prevent various expressions from being used within it.
67
+
68
+ Notable features that const contexts have, but const fn haven't are:
69
+
70
+ * floating point operations
71
+ * floating point values are treated just like generic parameters without trait bounds beyond
72
+ ` Copy ` . So you cannot do anything with them but copy/move them around.
73
+ * ` dyn Trait ` types
74
+ * generic bounds on generic parameters beyond ` Sized `
75
+ * comparing raw pointers
76
+ * union field access
77
+ * [ ` transmute ` ] invocations.
78
+
60
79
[ arithmetic ] : expressions/operator-expr.md#arithmetic-and-logical-binary-operators
61
80
[ array expressions ] : expressions/array-expr.md
62
81
[ array indexing ] : expressions/array-expr.md#array-and-slice-indexing-expressions
@@ -81,10 +100,14 @@ A _const context_ is one of the following:
81
100
[ functions ] : items/functions.md
82
101
[ grouped ] : expressions/grouped-expr.md
83
102
[ interior mutability ] : interior-mutability.md
103
+ [ if ] : expressions/if-expr.md#if-expressions
104
+ [ `if let` ] : expressions/if-expr.md#if-let-expressions
84
105
[ lazy boolean ] : expressions/operator-expr.md#lazy-boolean-operators
85
106
[ let statements ] : statements.md#let-statements
86
107
[ literals ] : expressions/literal-expr.md
87
108
[ logical ] : expressions/operator-expr.md#arithmetic-and-logical-binary-operators
109
+ [ loop ] : expressions/loop-expr.md#infinite-loops
110
+ [ match ] : expressions/match-expr.md
88
111
[ negation ] : expressions/operator-expr.md#negation-operators
89
112
[ overflow ] : expressions/operator-expr.md#overflow
90
113
[ paths ] : expressions/path-expr.md
@@ -94,3 +117,6 @@ A _const context_ is one of the following:
94
117
[ statics ] : items/static-items.md
95
118
[ struct ] : expressions/struct-expr.md
96
119
[ tuple expressions ] : expressions/tuple-expr.md
120
+ [ `transmute` ] : ../std/mem/fn.transmute.html
121
+ [ while ] : expressions/loop-expr.md#predicate-loops
122
+ [ `while let` ] : expressions/loop-expr.md#predicate-pattern-loops
0 commit comments