rust/src/librustc_trans_utils
bors dce604a8fe Auto merge of #44295 - plietar:extern-types, r=arielb1
Implement RFC 1861: Extern types

A few notes :

- Type parameters are not supported. This was an unresolved question from the RFC. It is not clear how useful this feature is, and how variance should be treated. This can be added in a future PR.

- `size_of_val` / `align_of_val` can be called with extern types, and respectively return 0 and 1. This differs from the RFC, which specified that they should panic, but after discussion with @eddyb on IRC this seems like a better solution.
If/when a `DynSized` trait is added, this will be disallowed statically.

- Auto traits are not implemented by default, since the contents of extern types is unknown. This means extern types are `!Sync`, `!Send` and `!Freeze`. This seems like the correct behaviour to me.
Manual `unsafe impl Sync for Foo` is still possible.

- This PR allows extern type to be used as the tail of a struct, as described by the RFC :
```rust
extern {
    type OpaqueTail;
}

#[repr(C)]
struct FfiStruct {
    data: u8,
    more_data: u32,
    tail: OpaqueTail,
}
```

However this is undesirable, as the alignment of `tail` is unknown (the current PR assumes an alignment of 1). Unfortunately we can't prevent it in the general case as the tail could be a type parameter :
```rust
#[repr(C)]
struct FfiStruct<T: ?Sized> {
    data: u8,
    more_data: u32,
    tail: T,
}
```

Adding a `DynSized` trait would solve this as well, by requiring tail fields to be bound by it.

- Despite being unsized, pointers to extern types are thin and can be casted from/to integers. However it is not possible to write a `null<T>() -> *const T` function which works with extern types, as I've explained here : https://github.com/rust-lang/rust/issues/43467#issuecomment-321678621

- Trait objects cannot be built from extern types. I intend to support it eventually, although how this interacts with `DynSized`/`size_of_val` is still unclear.

- The definition of `c_void` is unmodified
2017-10-28 13:34:12 +00:00
..
Cargo.toml Move collector to rustc_trans_utils 2017-10-19 11:01:31 +02:00
collector.rs Implement RFC 1861: Extern types 2017-10-27 23:01:34 +02:00
common.rs Move type_has_metadata to trans_utils 2017-10-27 23:36:18 +02:00
lib.rs Auto merge of #44295 - plietar:extern-types, r=arielb1 2017-10-28 13:34:12 +00:00
link.rs Fix for upstream changes 2017-09-23 14:46:15 +02:00
monomorphize.rs trans_ -> fully_ prefix 2017-10-21 22:50:21 +01:00
trans_crate.rs Fix error 2017-09-25 08:17:37 +02:00
trans_item.rs Move type_has_metadata to trans_utils 2017-10-27 23:36:18 +02:00