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 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
38 changes: 32 additions & 6 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 @@ -40,11 +38,15 @@ to be run.
* Built-in [negation], [arithmetic], [logical], [comparison] or [lazy boolean]
operators used on integer and floating point types, `bool`, and `char`.
* Shared [borrow]s, except if applied to a type with [interior mutability].
* The [dereference operator].
* The [dereference operator] except for raw pointers.
* [Grouped] expressions.
* [Cast] expressions, except pointer to address and
function pointer to address casts.
* [Cast] expressions, except
* pointer to address casts,
* function pointer to address casts, and
* unsizing casts to trait objects.
* 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 +59,23 @@ 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 operations
* floating point values are treated just like generic parameters without trait bounds beyond
`Copy`. So you cannot do anything with them but copy/move them around.
* `dyn Trait` types
* generic bounds on generic parameters beyond `Sized`
* comparing raw pointers
* union field access
* [`transmute`] invocations.

[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 +100,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 +117,6 @@ A _const context_ is one of the following:
[statics]: items/static-items.md
[struct]: expressions/struct-expr.md
[tuple expressions]: expressions/tuple-expr.md
[`transmute`]: ../std/mem/fn.transmute.html
[while]: expressions/loop-expr.md#predicate-loops
[`while let`]: expressions/loop-expr.md#predicate-pattern-loops