Skip to content

Commit 3360947

Browse files
committed
rfc, const_repeat_expr: cleanup
1 parent 577ed56 commit 3360947

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

text/0000-const-repeat-expr.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ impl<T: ConstDefault, const N: usize> ConstDefault for [T; N] {
3434
}
3535
```
3636

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
3838

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
4040
`[Vec<u32>; 1000]` is created and filled. With this RFC, and when `Vec::new()`
4141
becomes const, the user can simply write:
4242

@@ -93,7 +93,18 @@ fn main() {
9393
}
9494
```
9595

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:
97108

98109
```rust
99110
// 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.
134145
[`ptr::write(..)`]: https://doc.rust-lang.org/nightly/std/ptr/fn.write.html
135146

136147
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,
138149
[`ptr::write`] to be `const`, which is is a larger change. The design offered by
139150
this RFC is therefore the simplest and most non-intrusive design. It is also
140151
the most consistent.

0 commit comments

Comments
 (0)