about summary refs log tree commit diff
path: root/src/test/rustdoc-ui/coverage/json.rs
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2020-04-21 00:30:53 +0200
committerGitHub <noreply@github.com>2020-04-21 00:30:53 +0200
commit69a528eda688b3191127865f889fef65d979bb9c (patch)
tree337b095f994acffac33cf2e73756f6fcafc81dc4 /src/test/rustdoc-ui/coverage/json.rs
parent20fc02f836f3035b86b56a7cedb97c5cd4ed9612 (diff)
parent98f0a8241b621b28ac58c7a5e80de4ead13ab0bb (diff)
downloadrust-69a528eda688b3191127865f889fef65d979bb9c.tar.gz
rust-69a528eda688b3191127865f889fef65d979bb9c.zip
Rollup merge of #69362 - CAD97:alloc_layout_extras, r=Amanieu
Stabilize most common subset of alloc_layout_extras

Tracking issue: https://github.com/rust-lang/rust/issues/55724

Specifically, this stabilizes:

```rust
pub fn Layout::align_to(&self, align: usize) -> Result<Layout, LayoutErr>;
pub fn Layout::pad_to_align(&self) -> Layout;
pub fn Layout::extend(&self, next: Layout) -> Result<(Layout, usize), LayoutErr>;
pub fn Layout::array<T>(n: usize) -> Result<Layout, LayoutErr>;
```

Methods that are tracked by #55724 but are not stabilized here:

```rust
pub fn Layout::padding_needed_for(&self, align: usize) -> usize;
pub fn Layout::repeat(&self, n: usize) -> Result<(Layout, usize), LayoutErr>;
pub fn Layout::repeat_packed(&self, n: usize) -> Result<Layout, LayoutErr>;
pub fn Layout::extend_packed(&self, next: Layout) -> Result<Layout, LayoutErr>;
```

Combined, these stabilized functions allow code to construct and manipulate `repr(C)` layouts while letting the standard library handle correctness in the face of edge cases. For example use cases, consider the usage in [hashbrown](https://github.com/Amanieu/hashbrown/blob/2f2af1d/src/raw/mod.rs#L143), [crossbeam-skiplist](https://github.com/crossbeam-rs/crossbeam-skiplist/blob/master/src/base.rs#L99), [pointer-utils/slice-dst](https://github.com/CAD97/pointer-utils/blob/92aeefeed9399f28d1b1654b63f8dcbe1242d8d4/crates/slice-dst/src/layout_polyfill.rs), and of course the standard library itself.

Providing a higher-level API such as `Layout::repr_c<const N: usize>(fields: [Layout; N]) -> Result<(Layout, [usize; N]), LayoutErr>` is blocked on const generics, which are a ways off. Providing an API that doesn't provide offsets would be quite suboptimal, as the reason for calculating the layout like this rather than `Layout::new` is to get the field offsets.

The primary issue with the current API is having to call `.pad_to_align()` to match the layout of a `repr(C)` struct. However, I think this is not just a (failing? limitation?) of the API, but rather intrinsic complexity. While all Rust-defined types have size==stride, and probably will for the foreseeable future, there is no inherent reason why this is a limitation of all allocations. As such, the `Layout` manipulation APIs shouldn't impose this limitation, and instead the higher level api of `repr_c` (or just plain old using `Layout::new`) can make keeping it simple.

cc @matklad r? @rust-lang/libs
Diffstat (limited to 'src/test/rustdoc-ui/coverage/json.rs')
0 files changed, 0 insertions, 0 deletions