Skip to content

Commit

Permalink
Fix undefined behaviour by removing MayebUninit usage (#4)
Browse files Browse the repository at this point in the history
* Experiments with less uninit

* Some more experimentation

* Some progress on box, ptr, ref (still no mut ref)

* Upgraded MSRV to 1.60.0

* Added more examples

* Mutable ref with const uninit fn

* Clean up const generation

* Removed core->alloc dependency for ptr+ref

* Removed extraneous Static type alias

* Feature `const_ptr_offset_from` stabilised in 1.65.0

* Added back derive attrs for custom PhantomData

* Cleaned up some TODOs

* Added the ! type

* Added the ground attribute

* Use power tools in CI

* Add miri to CI

* Explicit miri component in CI

* Removed rust-toolchain

* Clarified unsafe uninit() API by constructing MaybeUninit

* Added initial inhabited calculation

* Implemented uninit() for uninhabited types

* Fixed enum + union uninit order with #[layout(bound)]
  • Loading branch information
juntyr authored Sep 3, 2022
1 parent 98e219b commit 29fb2ff
Show file tree
Hide file tree
Showing 25 changed files with 1,417 additions and 705 deletions.
74 changes: 51 additions & 23 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,16 @@ jobs:
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
profile: minimal
override: true

- name: Check without default features
run: |
cargo check --all \
--no-default-features
- name: Check with the default features
run: |
cargo check --all
- name: Install power tools
uses: taiki-e/install-action@cargo-hack

- name: Check with all features
- name: Check the powerset
run: |
cargo check --all \
--all-features
cargo hack check --all \
--feature-powerset --keep-going
test:
name: Test Suite
Expand All @@ -62,11 +57,16 @@ jobs:
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
profile: minimal
override: true

- name: Install power tools
uses: taiki-e/install-action@cargo-hack

- name: Run the test-suite
- name: Run the test-suite powerset
run: |
cargo test --workspace --no-fail-fast
cargo hack test --workspace \
--no-fail-fast --feature-powerset --keep-going
fmt:
name: Rustfmt
Expand All @@ -80,6 +80,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
profile: minimal
components: rustfmt
override: true

Expand All @@ -102,22 +103,49 @@ jobs:
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
profile: minimal
components: clippy
override: true

- name: Check the code style without default features
- name: Install power tools
uses: taiki-e/install-action@cargo-hack

- name: Check the code style powerset
run: |
cargo clippy --all \
--no-default-features \
cargo hack clippy --all \
--feature-powerset --keep-going \
-- -D warnings
- name: Check the code style with the default features
miri:
name: Miri
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
rust: [nightly]

steps:
- name: Checkout the Repository
uses: actions/checkout@v2

- name: Install the Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
profile: minimal
components: miri, rust-src
override: true

- name: Install power tools
uses: taiki-e/install-action@cargo-hack

- name: Run the miri powerset tests
run: |
cargo clippy --all \
-- -D warnings
cargo hack miri test --workspace \
--no-fail-fast --feature-powerset --keep-going
- name: Check the code style with all features
- name: Run the miri trycrate powerset
run: |
cargo clippy --all \
--all-features \
-- -D warnings
cd try-crate
cargo hack miri run \
--feature-powerset --keep-going
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# const-type-layout   [![CI Status]][workflow] [![Rust Doc]][docs] [![License Status]][fossa] [![Code Coverage]][codecov] [![Gitpod Ready-to-Code]][gitpod]
# const-type-layout   [![CI Status]][workflow] [![MSRV]][repo] [![Rust Doc]][docs] [![License Status]][fossa] [![Code Coverage]][codecov] [![Gitpod Ready-to-Code]][gitpod]

[CI Status]: https://img.shields.io/github/workflow/status/MomoLangenstein/const-type-layout/CI/main?label=CI
[workflow]: https://github.com/MomoLangenstein/const-type-layout/actions/workflows/ci.yml?query=branch%3Amain

[MSRV]: https://img.shields.io/badge/MSRV-1.60.0-orange
[repo]: https://github.com/ron-rs/ron

[Rust Doc]: https://img.shields.io/badge/docs-main-blue
[docs]: https://momolangenstein.github.io/const-type-layout/const_type_layout

Expand Down Expand Up @@ -32,7 +35,7 @@ The layout of types is only defined if they're `#[repr(C)]`. This crate works on
non-`#[repr(C)]` types, but their layout is unpredictable.

```rust
use type_layout::TypeLayout;
use const_type_layout::TypeLayout;

#[derive(TypeLayout)]
#[repr(C)]
Expand Down Expand Up @@ -70,7 +73,7 @@ Over-aligned types have trailing padding, which can be a source of bugs in some
FFI scenarios:

```rust
use type_layout::TypeLayout;
use const_type_layout::TypeLayout;

#[derive(TypeLayout)]
#[repr(C, align(128))]
Expand Down
Loading

0 comments on commit 29fb2ff

Please sign in to comment.