@@ -34,9 +34,9 @@ impl<T: ConstDefault, const N: usize> ConstDefault for [T; N] {
34
34
}
35
35
```
36
36
37
- [ `std:: mem::uninitialized()` ] : https://doc.rust-lang.org/nightly/std/mem/fn.uninitialized.html
37
+ [ `mem::uninitialized()` ] : https://doc.rust-lang.org/nightly/std/mem/fn.uninitialized.html
38
38
39
- In the example given by [ ` std:: mem::uninitialized()` ] , a value of type
39
+ In the example given by [ ` mem::uninitialized() ` ] , a value of type
40
40
` [Vec<u32>; 1000] ` is created and filled. With this RFC, and when ` Vec::new() `
41
41
becomes const, the user can simply write:
42
42
@@ -93,7 +93,18 @@ fn main() {
93
93
}
94
94
```
95
95
96
- Thus, the compiler may rewrite this internally as:
96
+ Thus, the compiler may rewrite the following:
97
+
98
+ ``` rust
99
+ fn main () {
100
+ type T = Option <Box <u32 >>;
101
+ const X : T = None ;
102
+ let mut arr = [X ; 2 ];
103
+ arr [0 ] = Some (Box :: new (1 ));
104
+ }
105
+ ```
106
+
107
+ internally as:
97
108
98
109
``` rust
99
110
// This is the value to be repeated and typeof(X) the type it has.
@@ -134,7 +145,7 @@ argues that the change is quite intuitive.
134
145
[ `ptr::write(..)` ] : https://doc.rust-lang.org/nightly/std/ptr/fn.write.html
135
146
136
147
The alternative, in addition to simply not doing this, is to modify a host of
137
- other constructs such as [ ` std:: mem::uninitialized()` ] , for loops over iterators,
148
+ other constructs such as [ ` mem::uninitialized() ` ] , for loops over iterators,
138
149
[ ` ptr::write ` ] to be ` const ` , which is is a larger change. The design offered by
139
150
this RFC is therefore the simplest and most non-intrusive design. It is also
140
151
the most consistent.
0 commit comments