Skip to content

[wip] Implement error source dropping #1918

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

Draft
wants to merge 23 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5b5d5a6
[ci] Don't run on push (#1882)
joshlf Oct 12, 2024
e7217b5
Release 0.9.0-alpha.0 (#1881)
joshlf Oct 12, 2024
2b56c07
Enable clippy::missing_const_for_fn (#1883)
joshlf Oct 12, 2024
1788f44
Upgrade some code for MSRV 1.65 (#1885)
joshlf Oct 12, 2024
7349fe0
Clean up some code for new MSRV (#1888)
joshlf Oct 12, 2024
19ab41c
Upgrade versions of some dependencies (#1886)
joshlf Oct 12, 2024
5452c3d
Roll pinned toolchains on v0.8.x branch (#1887)
joshlf Oct 12, 2024
2e819ac
[ci] Roll pinned nightly toolchain (#1900)
google-pr-creation-bot Oct 13, 2024
ccf477d
[ci] Roll pinned nightly toolchain (#1902)
google-pr-creation-bot Oct 14, 2024
c128ed2
[CI] Bump github/codeql-action from 3.26.12 to 3.26.13 (#1903)
dependabot[bot] Oct 14, 2024
1c8cbc7
[CI] Bump Swatinem/rust-cache from 2.7.3 to 2.7.5 (#1904)
dependabot[bot] Oct 14, 2024
d9e48e3
[pointer] Clarify semantics of aliasing invariants (#1889)
joshlf Oct 14, 2024
967b3a0
[derive] Document trivial_is_bit_valid (#1905)
joshlf Oct 14, 2024
b43c510
[pointer] Add separate PtrInner (#1891)
joshlf Oct 14, 2024
ca9243f
[pointer][invariant] Move to separate file (#1906)
joshlf Oct 14, 2024
51475bd
[pointer] Match variance of references (#1894)
joshlf Oct 14, 2024
f80a65d
[pointer] Make invariants opaque, more ergonomic (#1895)
joshlf Oct 14, 2024
85a12e2
[pointer] Simplify AliasingSafe, rename to Read (#1908)
joshlf Oct 14, 2024
ae43fce
[pointer] Rename Any -> Unknown/Inaccessible (#1909)
joshlf Oct 14, 2024
0665b90
[pointer] Support generic invariant mapping (#1896)
joshlf Oct 14, 2024
77a5f56
[ci] Roll pinned nightly toolchain (#1915)
google-pr-creation-bot Oct 15, 2024
49749b7
Remove items deprecated in 0.8 (#1916)
joshlf Oct 15, 2024
3309f33
[wip] Implement error source dropping
jswrenn Oct 15, 2024
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
76 changes: 4 additions & 72 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ name: Build & Tests

on:
pull_request:
push:
branches:
- main
- v0.6.x
merge_group:

permissions: read-all
Expand Down Expand Up @@ -56,10 +52,6 @@ jobs:
# which a particular feature is supported.
"zerocopy-core-error",
"zerocopy-diagnostic-on-unimplemented",
"zerocopy-generic-bounds-in-const-fn",
"zerocopy-target-has-atomics",
"zerocopy-aarch64-simd",
"zerocopy-panic-in-const-and-vec-try-reserve"
]
target: [
"i686-unknown-linux-gnu",
Expand Down Expand Up @@ -93,14 +85,6 @@ jobs:
features: "--all-features"
- toolchain: "zerocopy-diagnostic-on-unimplemented"
features: "--all-features"
- toolchain: "zerocopy-generic-bounds-in-const-fn"
features: "--all-features"
- toolchain: "zerocopy-target-has-atomics"
features: "--all-features"
- toolchain: "zerocopy-aarch64-simd"
features: "--all-features"
- toolchain: "zerocopy-panic-in-const-and-vec-try-reserve"
features: "--all-features"
# Exclude any combination for the zerocopy-derive crate which
# uses zerocopy features.
- crate: "zerocopy-derive"
Expand All @@ -117,36 +101,6 @@ jobs:
toolchain: "zerocopy-core-error"
- crate: "zerocopy-derive"
toolchain: "zerocopy-diagnostic-on-unimplemented"
- crate: "zerocopy-derive"
toolchain: "zerocopy-generic-bounds-in-const-fn"
- crate: "zerocopy-derive"
toolchain: "zerocopy-target-has-atomics"
- crate: "zerocopy-derive"
toolchain: "zerocopy-aarch64-simd"
- crate: "zerocopy-derive"
toolchain: "zerocopy-panic-in-const-and-vec-try-reserve"
# Exclude non-aarch64 targets from the `zerocopy-aarch64-simd`
# toolchain.
- toolchain: "zerocopy-aarch64-simd"
target: "i686-unknown-linux-gnu"
- toolchain: "zerocopy-aarch64-simd"
target: "x86_64-unknown-linux-gnu"
- toolchain: "zerocopy-aarch64-simd"
target: "arm-unknown-linux-gnueabi"
- toolchain: "zerocopy-aarch64-simd"
target: "powerpc-unknown-linux-gnu"
- toolchain: "zerocopy-aarch64-simd"
target: "powerpc64-unknown-linux-gnu"
- toolchain: "zerocopy-aarch64-simd"
target: "riscv64gc-unknown-linux-gnu"
- toolchain: "zerocopy-aarch64-simd"
target: "s390x-unknown-linux-gnu"
- toolchain: "zerocopy-aarch64-simd"
target: "x86_64-pc-windows-msvc"
- toolchain: "zerocopy-aarch64-simd"
target: "thumbv6m-none-eabi"
- toolchain: "zerocopy-aarch64-simd"
target: "wasm32-wasi"
# Exclude most targets targets from the `zerocopy-core-error`
# toolchain since the `zerocopy-core-error` feature is unrelated to
# compilation target. This only leaves i686 and x86_64 targets.
Expand Down Expand Up @@ -190,28 +144,6 @@ jobs:
target: "thumbv6m-none-eabi"
- toolchain: "zerocopy-diagnostic-on-unimplemented"
target: "wasm32-wasi"
# Exclude most targets targets from the
# `zerocopy-generic-bounds-in-const-fn` toolchain since the
# `zerocopy-generic-bounds-in-const-fn` feature is unrelated to
# compilation target. This only leaves i686 and x86_64 targets.
- toolchain: "zerocopy-generic-bounds-in-const-fn"
target: "arm-unknown-linux-gnueabi"
- toolchain: "zerocopy-generic-bounds-in-const-fn"
target: "aarch64-unknown-linux-gnu"
- toolchain: "zerocopy-generic-bounds-in-const-fn"
target: "powerpc-unknown-linux-gnu"
- toolchain: "zerocopy-generic-bounds-in-const-fn"
target: "powerpc64-unknown-linux-gnu"
- toolchain: "zerocopy-generic-bounds-in-const-fn"
target: "riscv64gc-unknown-linux-gnu"
- toolchain: "zerocopy-generic-bounds-in-const-fn"
target: "s390x-unknown-linux-gnu"
- toolchain: "zerocopy-generic-bounds-in-const-fn"
target: "x86_64-pc-windows-msvc"
- toolchain: "zerocopy-generic-bounds-in-const-fn"
target: "thumbv6m-none-eabi"
- toolchain: "zerocopy-generic-bounds-in-const-fn"
target: "wasm32-wasi"
# Exclude `thumbv6m-none-eabi` combined with any feature that implies
# the `std` feature since `thumbv6m-none-eabi` does not include a
# pre-compiled std.
Expand Down Expand Up @@ -259,7 +191,7 @@ jobs:
set -eo pipefail
# Override the exising `syn` dependency with one which requires an exact
# version.
cargo add -p zerocopy-derive 'syn@=2.0.46'
cargo add -p zerocopy-derive 'syn@=2.0.79'

- name: Configure environment variables
run: |
Expand Down Expand Up @@ -321,7 +253,7 @@ jobs:
components: clippy, rust-src ${{ matrix.toolchain == 'nightly' && ', miri' || '' }}

- name: Rust Cache
uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3
uses: Swatinem/rust-cache@82a92a6e8fbeee089604da2575dc567ae9ddeaab # v2.7.5
with:
key: "${{ matrix.target }}"

Expand Down Expand Up @@ -594,7 +526,7 @@ jobs:
echo "RUSTFLAGS=$RUSTFLAGS" >> $GITHUB_ENV
echo "ZC_TOOLCHAIN=$ZC_TOOLCHAIN" >> $GITHUB_ENV
- name: Rust Cache
uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3
uses: Swatinem/rust-cache@82a92a6e8fbeee089604da2575dc567ae9ddeaab # v2.7.5
with:
key: aarch64_be-unknown-linux-gnu
- name: Install stable Rust for use in 'cargo.sh'
Expand Down Expand Up @@ -681,7 +613,7 @@ jobs:
#
# TODO(#1595): Debug why this step is still necessary after #1564 and
# maybe remove it.
cargo add -p zerocopy-derive 'syn@=2.0.46' &> /dev/null
cargo add -p zerocopy-derive 'syn@=2.0.79' &> /dev/null

cargo check --workspace --tests &> /dev/null &
cargo metadata &> /dev/null &
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/roll-pinned-toolchain-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
fail-fast: false
matrix:
toolchain: ["stable", "nightly"]
branch: ["main"]
branch: ["main", "v0.8.x"]
name: Roll pinned toolchain ${{ matrix.toolchain }} version on ${{ matrix.branch }}
steps:
- name: Checkout code
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ jobs:

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@c36620d31ac7c881962c3d9dd939c40ec9434f2b # v3.26.12
uses: github/codeql-action/upload-sarif@f779452ac5af1c261dce0346a8f964149f49322b # v3.26.13
with:
sarif_file: results.sarif
35 changes: 10 additions & 25 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
[package]
edition = "2021"
name = "zerocopy"
version = "0.8.5"
version = "0.9.0-alpha.0"
authors = ["Joshua Liebow-Feeser <[email protected]>"]
description = "Zerocopy makes zero-cost memory manipulation effortless. We write \"unsafe\" so you don't have to."
categories = ["embedded", "encoding", "no-std::no-alloc", "parsing", "rust-patterns"]
keywords = ["cast", "convert", "transmute", "transmutation", "type-punning"]
license = "BSD-2-Clause OR Apache-2.0 OR MIT"
repository = "https://github.com/google/zerocopy"
rust-version = "1.56.0"
rust-version = "1.65.0"

exclude = [".*"]

Expand All @@ -38,25 +38,10 @@ zerocopy-core-error = "1.81.0"
# From 1.78.0, Rust supports the `#[diagnostic::on_unimplemented]` attribute.
zerocopy-diagnostic-on-unimplemented = "1.78.0"

# From 1.61.0, Rust supports generic types with trait bounds in `const fn`.
zerocopy-generic-bounds-in-const-fn = "1.61.0"

# From 1.60.0, Rust supports `cfg(target_has_atomics)`, which allows us to
# detect whether a target supports particular sets of atomics.
zerocopy-target-has-atomics = "1.60.0"

# When the "simd" feature is enabled, include SIMD types from the
# `core::arch::aarch64` module, which was stabilized in 1.59.0. On earlier Rust
# versions, these types require the "simd-nightly" feature.
zerocopy-aarch64-simd = "1.59.0"

# Permit panicking in `const fn`s and calling `Vec::try_reserve`.
zerocopy-panic-in-const-and-vec-try-reserve = "1.57.0"

[package.metadata.ci]
# The versions of the stable and nightly compiler toolchains to use in CI.
pinned-stable = "1.81.0"
pinned-nightly = "nightly-2024-10-11"
pinned-nightly = "nightly-2024-10-14"

[package.metadata.docs.rs]
all-features = true
Expand All @@ -77,26 +62,26 @@ std = ["alloc"]
__internal_use_only_features_that_work_on_stable = ["alloc", "derive", "simd", "std"]

[dependencies]
zerocopy-derive = { version = "=0.8.5", path = "zerocopy-derive", optional = true }
zerocopy-derive = { version = "=0.9.0-alpha.0", 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.5", path = "zerocopy-derive" }
zerocopy-derive = { version = "=0.9.0-alpha.0", path = "zerocopy-derive" }

[dev-dependencies]
itertools = "0.11"
itertools = "0.13.0"
rand = { version = "0.8.5", default-features = false, features = ["small_rng"] }
rustversion = "1.0"
static_assertions = "1.1"
rustversion = "1.0.17"
static_assertions = "1.1.0"
testutil = { path = "testutil" }
# Pinned to a specific version so that the version used for local development
# and the version used in CI are guaranteed to be the same. Future versions
# sometimes change the output format slightly, so a version mismatch can cause
# CI test failures.
trybuild = { version = "=1.0.89", features = ["diff"] }
trybuild = { version = "=1.0.90", features = ["diff"] }
# In tests, unlike in production, zerocopy-derive is not optional
zerocopy-derive = { version = "=0.8.5", path = "zerocopy-derive" }
zerocopy-derive = { version = "=0.9.0-alpha.0", path = "zerocopy-derive" }
# TODO(#381) Remove this dependency once we have our own layout gadgets.
elain = "0.3.0"
59 changes: 28 additions & 31 deletions src/byteorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,33 +539,29 @@ example of how it can be used for parsing UDP packets.
}

impl<O: ByteOrder> $name<O> {
maybe_const_trait_bounded_fn! {
/// Constructs a new value, possibly performing an endianness
/// swap to guarantee that the returned value has endianness
/// `O`.
#[must_use = "has no side effects"]
#[inline(always)]
pub const fn new(n: $native) -> $name<O> {
let bytes = match O::ORDER {
Order::BigEndian => $to_be_fn(n),
Order::LittleEndian => $to_le_fn(n),
};
/// Constructs a new value, possibly performing an endianness
/// swap to guarantee that the returned value has endianness
/// `O`.
#[must_use = "has no side effects"]
#[inline(always)]
pub const fn new(n: $native) -> $name<O> {
let bytes = match O::ORDER {
Order::BigEndian => $to_be_fn(n),
Order::LittleEndian => $to_le_fn(n),
};

$name(bytes, PhantomData)
}
$name(bytes, PhantomData)
}

maybe_const_trait_bounded_fn! {
/// Returns the value as a primitive type, possibly performing
/// an endianness swap to guarantee that the return value has
/// the endianness of the native platform.
#[must_use = "has no side effects"]
#[inline(always)]
pub const fn get(self) -> $native {
match O::ORDER {
Order::BigEndian => $from_be_fn(self.0),
Order::LittleEndian => $from_le_fn(self.0),
}
/// Returns the value as a primitive type, possibly performing
/// an endianness swap to guarantee that the return value has
/// the endianness of the native platform.
#[must_use = "has no side effects"]
#[inline(always)]
pub const fn get(self) -> $native {
match O::ORDER {
Order::BigEndian => $from_be_fn(self.0),
Order::LittleEndian => $from_le_fn(self.0),
}
}

Expand Down Expand Up @@ -971,6 +967,7 @@ module!(network_endian, NetworkEndian, "network-endian");
module!(native_endian, NativeEndian, "native-endian");

#[cfg(any(test, kani))]
#[allow(clippy::missing_const_for_fn)]
mod tests {
use super::*;

Expand Down Expand Up @@ -1057,8 +1054,8 @@ mod tests {
/// themselves. This method is like `assert_eq!`, but it treats NaN
/// values as equal.
fn assert_eq_or_nan(self, other: Self) {
let slf = (!self.is_nan()).then(|| self);
let other = (!other.is_nan()).then(|| other);
let slf = (!self.is_nan()).then_some(self);
let other = (!other.is_nan()).then_some(other);
assert_eq!(slf, other);
}
}
Expand Down Expand Up @@ -1088,8 +1085,8 @@ mod tests {
/// themselves. This method is like `assert_eq!`, but it treats NaN
/// values as equal.
fn assert_eq_or_nan(self, other: Self) {
let slf = (!self.get().is_nan()).then(|| self);
let other = (!other.get().is_nan()).then(|| other);
let slf = (!self.get().is_nan()).then_some(self);
let other = (!other.get().is_nan()).then_some(other);
assert_eq!(slf, other);
}
}
Expand Down Expand Up @@ -1396,11 +1393,11 @@ mod tests {
// For `f32` and `f64`, NaN values are not considered equal to
// themselves. We store `Option<f32>`/`Option<f64>` and store
// NaN as `None` so they can still be compared.
let val_or_none = |t: T| (!T::Native::is_nan(t.get())).then(|| t.get());
let val_or_none = |t: T| (!T::Native::is_nan(t.get())).then_some(t.get());
let t_t_res = val_or_none(t_t_res);
let t_n_res = val_or_none(t_n_res);
let n_t_res = val_or_none(n_t_res);
let n_n_res = (!T::Native::is_nan(n_n_res)).then(|| n_n_res);
let n_n_res = (!T::Native::is_nan(n_n_res)).then_some(n_n_res);
assert_eq!(t_t_res, n_n_res);
assert_eq!(t_n_res, n_n_res);
assert_eq!(n_t_res, n_n_res);
Expand All @@ -1418,7 +1415,7 @@ mod tests {
// NaN as `None` so they can still be compared.
let t_t_res = val_or_none(t_t_res);
let t_n_res = val_or_none(t_n_res);
let n_t_res = (!T::Native::is_nan(n_t_res)).then(|| n_t_res);
let n_t_res = (!T::Native::is_nan(n_t_res)).then_some(n_t_res);
assert_eq!(t_t_res, n_n_res);
assert_eq!(t_n_res, n_n_res);
assert_eq!(n_t_res, n_n_res);
Expand Down
Loading
Loading