Skip to content

Commit bf9bc37

Browse files
committed
Revise and clarify
Rather than talking about lifetime-extended temporaries in the top-level scope of an initializer, which is maybe a bit ambiguous, let's speak directly to the result of the lifetime extension, which is that these temporaries disallowed for borrows (in cases of interior mutability) would have their lifetimes extended to the end of the program.
1 parent 461be6c commit bf9bc37

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/const_eval.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ r[const-eval.const-expr.builtin-arith-logic]
8181
operators used on integer and floating point types, `bool`, and `char`.
8282

8383
r[const-eval.const-expr.borrows]
84-
* All forms of [borrow]s, including raw borrows, with one limitation:
85-
mutable borrows and shared borrows to values with interior mutability
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].
84+
* All forms of [borrow]s, including raw borrows, with one limitation: mutable borrows and shared borrows of expressions whose temporary scope would be extended (see [temporary lifetime extension]) to the end of the program are not allowed when those borrows refer to values with interior mutability.
8785

8886
```rust,compile_fail,E0492
8987
# use core::sync::atomic::AtomicU8;
@@ -105,8 +103,7 @@ r[const-eval.const-expr.borrows]
105103
const C: () = { _ = &AtomicU8::new(0); }; // OK
106104
```
107105

108-
In other words, they are only allowed to refer to *transient* places, to *indirect* places, or to *static* places.
109-
A place is *transient* if it is based on a local variable whose lifetime is strictly contained inside the current [const context].
106+
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].
110107

111108
```rust
112109
const C: () = {
@@ -250,7 +247,6 @@ of whether you are building on a `64` bit or a `32` bit system.
250247
[interior mutability]: interior-mutability.md
251248
[if]: expressions/if-expr.md#if-expressions
252249
[lazy boolean]: expressions/operator-expr.md#lazy-boolean-operators
253-
[lifetime-extension-const]: destructors.md#r-destructors.scope.lifetime-extension.static
254250
[let statements]: statements.md#let-statements
255251
[literals]: expressions/literal-expr.md
256252
[logical]: expressions/operator-expr.md#arithmetic-and-logical-binary-operators
@@ -265,5 +261,6 @@ of whether you are building on a `64` bit or a `32` bit system.
265261
[slice]: types/slice.md
266262
[statics]: items/static-items.md
267263
[struct]: expressions/struct-expr.md
264+
[temporary lifetime extension]: destructors.scope.lifetime-extension
268265
[tuple expressions]: expressions/tuple-expr.md
269266
[while]: expressions/loop-expr.md#predicate-loops

0 commit comments

Comments
 (0)