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

Update const eval chapter to latest changes #842

Merged
merged 5 commits into from
Jul 12, 2020
Merged
Changes from 3 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
28 changes: 25 additions & 3 deletions src/const_eval.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ to be run.
* [Struct] expressions.
* [Enum variant] expressions.
* [Block expressions], including `unsafe` blocks.
* [let statements] 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.
* [let statements] and thus irrefutable [patterns], including mutable bindings
* [assignment expressions]
* [compound assignment expressions]
* [expression statements]
Expand All @@ -45,6 +43,8 @@ to be run.
* [Cast] expressions, except pointer to address and
function pointer to address casts.
* Calls of [const functions] and const methods.
* [loop], [while] and [`while let`] expressions.
* [if], [`if let`] and [match] expressions.

## Const context

Expand All @@ -57,6 +57,22 @@ A _const context_ is one of the following:
* [statics]
* [enum discriminants]

## Const Functions

A _const fn_ is a function that one is permitted to call from a const context. Declaring a function
`const` has no effect on any existing uses, it only restricts the types that arguments and the
return type may use, as well as prevent various expressions from being used within it.

Notable features that const contexts have, but const fn haven't are:

* floating point types
oli-obk marked this conversation as resolved.
Show resolved Hide resolved
* `dyn Trait` types
* generic bounds on generic parameters beyond `Sized`
* dereferencing of raw pointers
* casting raw pointers to integers
* comparing raw pointers
* union field access

[arithmetic]: expressions/operator-expr.md#arithmetic-and-logical-binary-operators
[array expressions]: expressions/array-expr.md
[array indexing]: expressions/array-expr.md#array-and-slice-indexing-expressions
Expand All @@ -81,10 +97,14 @@ A _const context_ is one of the following:
[functions]: items/functions.md
[grouped]: expressions/grouped-expr.md
[interior mutability]: interior-mutability.md
[if]: expressions/if-expr.md#if-expressions
[`if let`]: expressions/if-expr.md#if-let-expressions
[lazy boolean]: expressions/operator-expr.md#lazy-boolean-operators
[let statements]: statements.md#let-statements
[literals]: expressions/literal-expr.md
[logical]: expressions/operator-expr.md#arithmetic-and-logical-binary-operators
[loop]: expressions/loop-expr.md#infinite-loops
[match]: expressions/match-expr.md
[negation]: expressions/operator-expr.md#negation-operators
[overflow]: expressions/operator-expr.md#overflow
[paths]: expressions/path-expr.md
Expand All @@ -94,3 +114,5 @@ A _const context_ is one of the following:
[statics]: items/static-items.md
[struct]: expressions/struct-expr.md
[tuple expressions]: expressions/tuple-expr.md
[while]: expressions/loop-expr.md#predicate-loops
[`while let`]: expressions/loop-expr.md#predicate-pattern-loops