Skip to content

Commit 5c7558e

Browse files
committed
also spell out which borrows are *not* allowed
1 parent 9d83c64 commit 5c7558e

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/const_eval.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ r[const-eval.const-expr.builtin-arith-logic]
8383
r[const-eval.const-expr.borrows]
8484
* All forms of [borrow]s, including raw borrows, with one limitation:
8585
mutable borrows and shared borrows to values with interior mutability
86-
are only allowed to refer to *transient* places, to *indirect* places, or to *static* places.
86+
are not allowed to refer to [lifetime-extended temporaries in the top-level scope of a `const` or `static` initializer expression][lifetime-extension-const].
87+
88+
In other words, they are only allowed to refer to *transient* places, to *indirect* places, or to *static* places.
8789
A place is *transient* if it is based on a local variable whose lifetime is strictly contained inside the current [const context].
8890
A place is *indirect* if it is based on a [dereference expression][dereference operator].
8991
A place is *static* if it is based on a `static` item or a [promoted expression].
@@ -188,6 +190,7 @@ of whether you are building on a `64` bit or a `32` bit system.
188190
[interior mutability]: interior-mutability.md
189191
[if]: expressions/if-expr.md#if-expressions
190192
[lazy boolean]: expressions/operator-expr.md#lazy-boolean-operators
193+
[lifetime-extension-const]: destructors.md#r-destructors.scope.lifetime-extension.static
191194
[let statements]: statements.md#let-statements
192195
[literals]: expressions/literal-expr.md
193196
[logical]: expressions/operator-expr.md#arithmetic-and-logical-binary-operators

src/destructors.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,9 @@ println!("{}", x);
336336
```
337337

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

342343
```rust
343344
const C: &Vec<i32> = &Vec::new();

0 commit comments

Comments
 (0)