Using operator= is not quite sound in presence of destructors and operator
overloading.
It's perfectly fine to assume that the left-hand-side of an operator= expression
is valid memory, however we're using uninitialized memory here, that may not be
the case.
Use placement new to properly construct tagged unions. I don't need this with
any urgency, but it's the right thing to do in presence of complex types, and
the current code seems a bomb waiting to explode :)
I want this to move around slices and boxes across the style system, while
preserving the option size optimizations when they're fully in a repr(Rust)
data-structure.
This is sound because NonNull is repr(transparent):
https://doc.rust-lang.org/src/core/ptr.rs.html#2847
I renamed simplify_option_to_ptr to simplify_standard_types because that's what
it does now.
ABI-wise for NonNull<T> it's guaranteed via repr(transparent). For
Option<NonNull<T>> it is as well, though I've asked in #rustc to confirm.
The LLVM IR of:
```
pub extern "C" fn foo(ptr: Option<::std::ptr::NonNull<i32>>) {}
```
is:
```
define void @foo(i32*) unnamed_addr #0 !dbg !310 {
start:
%ptr = alloca i32*, align 8
store i32* %0, i32** %ptr, align 8
call void @llvm.dbg.declare(metadata i32** %ptr, metadata !327, metadata
!DIExpression()), !dbg !328
ret void, !dbg !329
}
```
Which is the same as for:
```
pub extern "C" fn foo(ptr: ::std::ptr::NonNull<i32>) {}
```
Except without the nonnull annotation.
And the same as for:
```
pub extern "C" fn foo(ptr: *mut i32) {}
```