]> git.lizzy.rs Git - rust.git/commit - src/tools/clippy
Rollup merge of #60370 - Richard-W:const-layout-construction, r=sfackler
authorMazdak Farrokhzad <twingoow@gmail.com>
Sun, 19 May 2019 00:31:32 +0000 (02:31 +0200)
committerGitHub <noreply@github.com>
Sun, 19 May 2019 00:31:32 +0000 (02:31 +0200)
commit7885dfc62385b722e04067b2d5c26aeea429fb02
tree0e2763a862c5adba15a38f940376f81ac71e92fd
parent963184bbb670c1ffa97fc28a98cd5e8473118859
parentc0b6d3c975915e740548f0ec7bcf5963e7a3b218
Rollup merge of #60370 - Richard-W:const-layout-construction, r=sfackler

Mark core::alloc::Layout::from_size_align_unchecked const

Makes it possible (pending stabilization of #57563 (`const_fn`)) to rewrite code like

```rust
const BUFFER_SIZE: usize = 0x2000;
const BUFFER_ALIGN: usize = 0x1000;

fn foo() {
  let layout = std::alloc::Layout::from_size_align(BUFFER_SIZE, BUFFER_ALIGN)
    .unwrap();
  let buffer = std::alloc::alloc(layout);
}
```
to
```rust
const BUFFER_LAYOUT: std::alloc::Layout = unsafe {
  std::alloc::Layout::from_size_align_unchecked(0x2000, 0x1000)
};

fn foo() {
  let buffer = std::alloc::alloc(BUFFER_LAYOUT);
}
```

which (although `unsafe` is used) looks somewhat cleaner and is easier to read.