Skip to content

const-eval.const-expr.borrows: mention indirect places #1865

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
10 changes: 7 additions & 3 deletions src/const_eval.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,12 @@ r[const-eval.const-expr.builtin-arith-logic]
r[const-eval.const-expr.borrows]
* All forms of [borrow]s, including raw borrows, with one limitation:
mutable borrows and shared borrows to values with interior mutability
are only allowed to refer to *transient* places or to *static* places. A place is *transient*
if its lifetime is strictly contained inside the current [const context].
A place is *static* if it is a `static` item or a [promoted expression].
are not allowed to refer to [lifetime-extended temporaries in the top-level scope of a `const` or `static` initializer expression][lifetime-extension-const].

In other words, they are only allowed to refer to *transient* places, to *indirect* places, or to *static* places.
A place is *transient* if it is based on a local variable whose lifetime is strictly contained inside the current [const context].
A place is *indirect* if it is based on a [dereference expression][dereference operator].
A place is *static* if it is based on a `static` item or a [promoted expression].

r[const-eval.const-expr.deref]
* The [dereference operator] except for raw pointers.
Expand Down Expand Up @@ -187,6 +190,7 @@ of whether you are building on a `64` bit or a `32` bit system.
[interior mutability]: interior-mutability.md
[if]: expressions/if-expr.md#if-expressions
[lazy boolean]: expressions/operator-expr.md#lazy-boolean-operators
[lifetime-extension-const]: destructors.md#r-destructors.scope.lifetime-extension.static
[let statements]: statements.md#let-statements
[literals]: expressions/literal-expr.md
[logical]: expressions/operator-expr.md#arithmetic-and-logical-binary-operators
Expand Down
5 changes: 3 additions & 2 deletions src/destructors.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,9 @@ println!("{}", x);
```

r[destructors.scope.lifetime-extension.static]
Lifetime extension also applies to `static` and `const` items, where it
makes temporaries live until the end of the program. For example:
Lifetime extension also applies to the top-level scope of `static` and `const` items,
where it makes temporaries live until the end of the program.
For example:

```rust
const C: &Vec<i32> = &Vec::new();
Expand Down