Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let bindings are now available in const contexts #512

Merged
merged 2 commits into from
Jan 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/const_eval.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ can be evaluated at compile-time.
Certain forms of expressions, called constant expressions, can be evaluated at
compile time. In [const contexts](#const-context), these are the only allowed
expressions, and are always evaluated at compile time. In other places, such as
[`let` statements](statements.html#let-statements), constant expressions *may*
[let statement]s, constant expressions *may*
be, but are not guaranteed to be, evaluated at compile time. Behaviors such as
out of bounds [array indexing] or [overflow] are compiler errors if the value
must be evaluated at compile time (i.e. in const contexts). Otherwise, these
Expand All @@ -26,8 +26,13 @@ to be ran.
* [Array expressions].
* [Struct] expressions.
* [Enum variant] expressions.
* [Block expressions], including `unsafe` blocks, which only contain items and
possibly a constant tail expression.
* [Block expressions], including `unsafe` blocks.
* [let statement]s and thus irrefutable [patterns], with the caveat that until `if` and `match`
are implemented, one cannot use both short circuiting operators (`&&` and `||`) and let
statements within the same constant.
* [assignment expressions](operator-expr.html#assignment-expressions)
* [assignment operator expressions](operator-expr.html#compound-assignment-expressions)
* [expression statements](statements.html#expression-statements)
* [Field] expressions.
* Index expressions, [array indexing] or [slice] with a `usize`.
* [Range expressions].
Expand All @@ -39,7 +44,7 @@ to be ran.
* [Grouped] expressions.
* [Cast] expressions, except pointer to address and
function pointer to address casts.
* Calls of const functions and const methods
* Calls of const functions and const methods.

## Const context

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