Skip to content

Commit fbeb116

Browse files
Better explain the motivation of RFC 2203
This is useful inside a const-context as well.
1 parent 0e03060 commit fbeb116

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

promotion.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ first context where promotion was done.
2828

2929
### Non-`Copy` array initialization
3030

31-
Another promotion context was introduced in [RFC 2203][]. In this case, we try
32-
to promote the initializer in expressions like `[Vec::new(); 32]`, which allows
33-
non-`Copy` types to be used as array initializers.
31+
Another promotion context, the initializer of an array expression, was
32+
introduced in [RFC 2203][]. Here, promotion allows arrays of
33+
non-`Copy` types to be initialized idiomatically, for example
34+
`[Option::<Box<i32>>::None; 32]`.
3435

3536
[RFC 2203]: https://github.com/rust-lang/rfcs/blob/master/text/2203-const-repeat-expr.md
3637

@@ -71,18 +72,16 @@ implicit context are a superset of the ones in an explicit context.
7172

7273
[warn-rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1229-compile-time-asserts.md
7374

74-
### Lifetime extension in `const` and `static`
75+
### Promotion contexts in `const` and `static`
7576

7677
We defined above that promotion guarantees that code in a non-const context
77-
will be executed at compile-time. However, lifetime extension is useful
78-
*inside* `const`s and `static`s as well (unlike the other promotion contexts).
79-
Strictly speaking, lifetime extension in a const-context is not promotion; it
80-
does not create `promoted`s in the MIR. However the same rules for
81-
promotability apply inside a const-context as outside.
82-
83-
All contexts are treated as explicit ones when determining promotability within
84-
a `const` or `static` initializer because the user has requested that their
85-
code run at compile-time anyway.
78+
will be executed at compile-time. However, lifetime extension and non-`Copy`
79+
array initialziation are useful features *inside* `const`s and `static`s as
80+
well. Strictly speaking, the transformation used to enable these features
81+
inside a const-context is not promotion; no `promoted`s are created in the MIR.
82+
However the same rules for promotability are used with one modification:
83+
Because the user has already requested that this code run at compile time, all
84+
contexts are treated as explicit.
8685

8786
## Promotability
8887

0 commit comments

Comments
 (0)