Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[util] Use new padding_needed_for implementation #833

Merged
merged 1 commit into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
[package]
edition = "2018"
name = "zerocopy"
version = "0.8.0-alpha.2"
version = "0.8.0-alpha.3"
authors = ["Joshua Liebow-Feeser <[email protected]>"]
description = "Utilities for zero-copy parsing and serialization"
license = "BSD-2-Clause OR Apache-2.0 OR MIT"
Expand Down Expand Up @@ -47,13 +47,13 @@ simd-nightly = ["simd"]
__internal_use_only_features_that_work_on_stable = ["alloc", "derive", "simd"]

[dependencies]
zerocopy-derive = { version = "=0.8.0-alpha.2", path = "zerocopy-derive", optional = true }
zerocopy-derive = { version = "=0.8.0-alpha.3", path = "zerocopy-derive", optional = true }

# The "associated proc macro pattern" ensures that the versions of zerocopy and
# zerocopy-derive remain equal, even if the 'derive' feature isn't used.
# See: https://github.com/matklad/macro-dep-test
[target.'cfg(any())'.dependencies]
zerocopy-derive = { version = "=0.8.0-alpha.2", path = "zerocopy-derive" }
zerocopy-derive = { version = "=0.8.0-alpha.3", path = "zerocopy-derive" }

[dev-dependencies]
assert_matches = "1.5"
Expand All @@ -72,6 +72,6 @@ testutil = { path = "testutil" }
# CI test failures.
trybuild = { version = "=1.0.89", features = ["diff"] }
# In tests, unlike in production, zerocopy-derive is not optional
zerocopy-derive = { version = "=0.8.0-alpha.2", path = "zerocopy-derive" }
zerocopy-derive = { version = "=0.8.0-alpha.3", path = "zerocopy-derive" }
# TODO(#381) Remove this dependency once we have our own layout gadgets.
elain = "0.3.0"
24 changes: 11 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ impl DstLayout {
#[doc(hidden)]
#[inline]
pub const fn extend(self, field: DstLayout, repr_packed: Option<NonZeroUsize>) -> Self {
use util::{core_layout::padding_needed_for, max, min};
use util::{max, min, padding_needed_for};

// If `repr_packed` is `None`, there are no alignment constraints, and
// the value can be defaulted to `THEORETICAL_MAX_ALIGN`.
Expand Down Expand Up @@ -672,7 +672,7 @@ impl DstLayout {
#[doc(hidden)]
#[inline]
pub const fn pad_to_align(self) -> Self {
use util::core_layout::padding_needed_for;
use util::padding_needed_for;

let size_info = match self.size_info {
// For sized layouts, we add the minimum amount of trailing padding
Expand Down Expand Up @@ -882,8 +882,8 @@ impl DstLayout {
// up to the next multiple of the alignment will bring
// `self_bytes` up to `max_total_bytes`.
#[allow(clippy::arithmetic_side_effects)]
let self_bytes = without_padding
+ util::core_layout::padding_needed_for(without_padding, self.align);
let self_bytes =
without_padding + util::padding_needed_for(without_padding, self.align);
(elems, self_bytes)
}
};
Expand Down Expand Up @@ -5997,8 +5997,7 @@ mod tests {
}) => {
let padded_size = |elems| {
let without_padding = offset + elems * elem_size;
without_padding
+ util::core_layout::padding_needed_for(without_padding, align)
without_padding + util::padding_needed_for(without_padding, align)
};

let resulting_size = padded_size(elems);
Expand Down Expand Up @@ -6027,7 +6026,7 @@ mod tests {
let min_size = match layout.size_info {
SizeInfo::Sized { _size } => _size,
SizeInfo::SliceDst(TrailingSliceLayout { _offset, .. }) => {
_offset + util::core_layout::padding_needed_for(_offset, layout.align)
_offset + util::padding_needed_for(_offset, layout.align)
}
};

Expand Down Expand Up @@ -6104,8 +6103,7 @@ mod tests {
//
// ...then Rust will automatically round the type's size
// up to 2.
_size: args.offset
+ util::core_layout::padding_needed_for(args.offset, args.align),
_size: args.offset + util::padding_needed_for(args.offset, args.align),
},
};
DstLayout { size_info, align: args.align }
Expand Down Expand Up @@ -6153,8 +6151,8 @@ mod tests {
// count. We expect that the size of the object should be
// `offset + elem_size * elems` rounded up to the next
// alignment.
let expected_size = without_padding
+ util::core_layout::padding_needed_for(without_padding, args.align);
let expected_size =
without_padding + util::padding_needed_for(without_padding, args.align);
assert_eq!(expected_size, size, "{}", assert_msg);

// For zero-sized element types,
Expand Down Expand Up @@ -8508,7 +8506,7 @@ mod proofs {

#[kani::proof]
fn prove_dst_layout_extend() {
use crate::util::{core_layout::padding_needed_for, max, min};
use crate::util::{max, min, padding_needed_for};

let base: DstLayout = kani::any();
let field: DstLayout = kani::any();
Expand Down Expand Up @@ -8649,7 +8647,7 @@ mod proofs {

#[kani::proof]
fn prove_dst_layout_pad_to_align() {
use crate::util::core_layout::padding_needed_for;
use crate::util::padding_needed_for;

let layout: DstLayout = kani::any();

Expand Down
176 changes: 0 additions & 176 deletions src/third_party/rust/LICENSE-APACHE

This file was deleted.

23 changes: 0 additions & 23 deletions src/third_party/rust/LICENSE-MIT

This file was deleted.

7 changes: 0 additions & 7 deletions src/third_party/rust/README.fuchsia

This file was deleted.

45 changes: 0 additions & 45 deletions src/third_party/rust/layout.rs

This file was deleted.

Loading
Loading