Skip to content

Commit c55401b

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 0955af2 commit c55401b

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;
@@ -111,8 +109,7 @@ r[const-eval.const-expr.borrows]
111109
const C: &AtomicU8 = &S; // OK
112110
```
113111

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

117114
```rust
118115
const C: () = {
@@ -260,7 +257,6 @@ of whether you are building on a `64` bit or a `32` bit system.
260257
[interior mutability]: interior-mutability.md
261258
[if]: expressions/if-expr.md#if-expressions
262259
[lazy boolean]: expressions/operator-expr.md#lazy-boolean-operators
263-
[lifetime-extension-const]: destructors.md#r-destructors.scope.lifetime-extension.static
264260
[let statements]: statements.md#let-statements
265261
[literals]: expressions/literal-expr.md
266262
[logical]: expressions/operator-expr.md#arithmetic-and-logical-binary-operators
@@ -275,5 +271,6 @@ of whether you are building on a `64` bit or a `32` bit system.
275271
[slice]: types/slice.md
276272
[statics]: items/static-items.md
277273
[struct]: expressions/struct-expr.md
274+
[temporary lifetime extension]: destructors.scope.lifetime-extension
278275
[tuple expressions]: expressions/tuple-expr.md
279276
[while]: expressions/loop-expr.md#predicate-loops

0 commit comments

Comments
 (0)