Skip to content

Commit 691ec18

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 3d8c53d commit 691ec18

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: () = {
@@ -240,7 +237,6 @@ of whether you are building on a `64` bit or a `32` bit system.
240237
[interior mutability]: interior-mutability.md
241238
[if]: expressions/if-expr.md#if-expressions
242239
[lazy boolean]: expressions/operator-expr.md#lazy-boolean-operators
243-
[lifetime-extension-const]: destructors.md#r-destructors.scope.lifetime-extension.static
244240
[let statements]: statements.md#let-statements
245241
[literals]: expressions/literal-expr.md
246242
[logical]: expressions/operator-expr.md#arithmetic-and-logical-binary-operators
@@ -255,5 +251,6 @@ of whether you are building on a `64` bit or a `32` bit system.
255251
[slice]: types/slice.md
256252
[statics]: items/static-items.md
257253
[struct]: expressions/struct-expr.md
254+
[temporary lifetime extension]: destructors.scope.lifetime-extension
258255
[tuple expressions]: expressions/tuple-expr.md
259256
[while]: expressions/loop-expr.md#predicate-loops

0 commit comments

Comments
 (0)