diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2021-01-12 16:13:24 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-12 16:13:24 +0900 |
| commit | babfdafb10cb77f980b11eb7e2ccf0ccdb72b8a1 (patch) | |
| tree | 4f0a9446173ddd9fe94683fc4d1ed2edcd516701 /compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp | |
| parent | 86b900a3eaaf84b48f080dab14b7994385bd19b8 (diff) | |
| parent | 985071b08f5c03e4f18d43c15f3ea82395588a5e (diff) | |
| download | rust-babfdafb10cb77f980b11eb7e2ccf0ccdb72b8a1.tar.gz rust-babfdafb10cb77f980b11eb7e2ccf0ccdb72b8a1.zip | |
Rollup merge of #80600 - CoffeeBlend:maybe_uninit_array_assume_init, r=dtolnay
Add `MaybeUninit` method `array_assume_init`
When initialising an array element-by-element, the conversion to the initialised array is done through `mem::transmute`, which is both ugly and does not work with const generics (see #61956). This PR proposes the associated method `array_assume_init`, matching the style of `slice_assume_init_*`:
```rust
unsafe fn array_assume_init<T, const N: usize>(array: [MaybeUninit<T>; N]) -> [T; N];
```
Example:
```rust
let mut array: [MaybeUninit<i32>; 3] = MaybeUninit::uninit_array();
array[0].write(0);
array[1].write(1);
array[2].write(2);
// SAFETY: Now safe as we initialised all elements
let array: [i32; 3] = unsafe {
MaybeUninit::array_assume_init(array)
};
```
Things I'm unsure about:
* Should this be a method of array instead?
* Should the function be const?
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp')
0 files changed, 0 insertions, 0 deletions
