@@ -28,9 +28,10 @@ first context where promotion was done.
28
28
29
29
### Non-` Copy ` array initialization
30
30
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] ` .
34
35
35
36
[ RFC 2203 ] : https://github.com/rust-lang/rfcs/blob/master/text/2203-const-repeat-expr.md
36
37
@@ -71,18 +72,16 @@ implicit context are a superset of the ones in an explicit context.
71
72
72
73
[ warn-rfc ] : https://github.com/rust-lang/rfcs/blob/master/text/1229-compile-time-asserts.md
73
74
74
- ### Lifetime extension in ` const ` and ` static `
75
+ ### Promotion contexts in ` const ` and ` static `
75
76
76
77
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.
86
85
87
86
## Promotability
88
87
0 commit comments