Skip to content

Commit e616dd4

Browse files
authored
Merge pull request #512 from oli-obk/master
Let bindings are now available in const contexts
2 parents 78be683 + 3071432 commit e616dd4

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/const_eval.md

+11-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ can be evaluated at compile-time.
99
Certain forms of expressions, called constant expressions, can be evaluated at
1010
compile time. In [const contexts](#const-context), these are the only allowed
1111
expressions, and are always evaluated at compile time. In other places, such as
12-
[`let` statements](statements.html#let-statements), constant expressions *may*
12+
[let statement]s, constant expressions *may*
1313
be, but are not guaranteed to be, evaluated at compile time. Behaviors such as
1414
out of bounds [array indexing] or [overflow] are compiler errors if the value
1515
must be evaluated at compile time (i.e. in const contexts). Otherwise, these
@@ -26,8 +26,13 @@ to be ran.
2626
* [Array expressions].
2727
* [Struct] expressions.
2828
* [Enum variant] expressions.
29-
* [Block expressions], including `unsafe` blocks, which only contain items and
30-
possibly a constant tail expression.
29+
* [Block expressions], including `unsafe` blocks.
30+
* [let statement]s 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.
33+
* [assignment expressions](operator-expr.html#assignment-expressions)
34+
* [assignment operator expressions](operator-expr.html#compound-assignment-expressions)
35+
* [expression statements](statements.html#expression-statements)
3136
* [Field] expressions.
3237
* Index expressions, [array indexing] or [slice] with a `usize`.
3338
* [Range expressions].
@@ -39,7 +44,7 @@ to be ran.
3944
* [Grouped] expressions.
4045
* [Cast] expressions, except pointer to address and
4146
function pointer to address casts.
42-
* Calls of const functions and const methods
47+
* Calls of const functions and const methods.
4348

4449
## Const context
4550

@@ -81,3 +86,5 @@ A _const context_ is one of the following:
8186
[dereference operator]: expressions/operator-expr.html#the-dereference-operator
8287
[grouped]: expressions/grouped-expr.html
8388
[cast]: expressions/operator-expr.html#type-cast-expressions
89+
[let statement]: statements.html#let-statements
90+
[patterns]: patterns.html

0 commit comments

Comments
 (0)