Skip to content

Commit

Permalink
Lower our MWRV to 1.59.0
Browse files Browse the repository at this point in the history
TODO: Populate commit message with details about updated infrastructure
in this commit (notably, testutil crate's use of MSRV vs MWRV and CI's
passing of --ignore-rust-version)

Makes progress on #554
  • Loading branch information
joshlf committed Jan 24, 2024
1 parent 8c38c06 commit a816e0f
Show file tree
Hide file tree
Showing 130 changed files with 68 additions and 55 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ jobs:
key: "${{ matrix.target }}"

- name: Check
run: ./cargo.sh +${{ matrix.toolchain }} check --package ${{ matrix.crate }} --target ${{ matrix.target }} ${{ matrix.features }} --verbose
run: ./cargo.sh +${{ matrix.toolchain }} check --package ${{ matrix.crate }} --target ${{ matrix.target }} ${{ matrix.features }} --ignore-rust-version --verbose

- name: Build
run: ./cargo.sh +${{ matrix.toolchain }} build --package ${{ matrix.crate }} --target ${{ matrix.target }} ${{ matrix.features }} --verbose
run: ./cargo.sh +${{ matrix.toolchain }} build --package ${{ matrix.crate }} --target ${{ matrix.target }} ${{ matrix.features }} --ignore-rust-version --verbose

# When building tests for the i686 target, we need certain libraries which
# are not installed by default; `gcc-multilib` includes these libraries.
Expand All @@ -158,6 +158,7 @@ jobs:
--package ${{ matrix.crate }} \
--target ${{ matrix.target }} \
${{ matrix.features }} \
--ignore-rust-version \
--verbose \
-- \
--skip ui
Expand All @@ -184,6 +185,7 @@ jobs:
--package ${{ matrix.crate }} \
--target ${{ matrix.target }} \
${{ matrix.features }} \
--ignore-rust-version \
--verbose \
ui
Expand Down Expand Up @@ -212,7 +214,8 @@ jobs:
miri test \
--package ${{ matrix.crate }} \
--target ${{ matrix.target }} \
${{ matrix.features }}
${{ matrix.features }} \
--ignore-rust-version
done
# Only nightly has a working Miri, so we skip installing on all other
# toolchains.
Expand All @@ -222,7 +225,7 @@ jobs:
if: matrix.toolchain == 'nightly' && matrix.target != 'riscv64gc-unknown-linux-gnu' && matrix.target != 'wasm32-wasi'

- name: Clippy check
run: ./cargo.sh +${{ matrix.toolchain }} clippy --package ${{ matrix.crate }} --target ${{ matrix.target }} ${{ matrix.features }} --tests --verbose
run: ./cargo.sh +${{ matrix.toolchain }} clippy --package ${{ matrix.crate }} --target ${{ matrix.target }} ${{ matrix.features }} --ignore-rust-version --tests --verbose
# Clippy improves the accuracy of lints over time, and fixes bugs. Only
# running Clippy on nightly allows us to avoid having to write code which
# is compatible with older versions of Clippy, which sometimes requires
Expand All @@ -241,7 +244,7 @@ jobs:
METADATA_DOCS_RS_RUSTDOC_ARGS="$(cargo metadata --format-version 1 | \
jq -r ".packages[] | select(.name == \"zerocopy\").metadata.docs.rs.\"rustdoc-args\".[]" | tr '\n' ' ')"
export RUSTDOCFLAGS="${{ matrix.toolchain == 'nightly' && '-Z unstable-options --document-hidden-items' || '' }} $RUSTDOCFLAGS $METADATA_DOCS_RS_RUSTDOC_ARGS"
./cargo.sh +${{ matrix.toolchain }} doc --document-private-items --package ${{ matrix.crate }} ${{ matrix.features }}
./cargo.sh +${{ matrix.toolchain }} doc --document-private-items --package ${{ matrix.crate }} ${{ matrix.features }} --ignore-rust-version
# Check semver compatibility with the most recently-published version on
# crates.io. We do this in the matrix rather than in its own job so that it
Expand Down
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ rustdoc-args = ["--cfg", "doc_cfg", "--generate-link-to-definition"]
# The versions of the stable and nightly compiler toolchains to use in CI.
pinned-stable = "1.75.0"
pinned-nightly = "nightly-2024-01-11"
minimum-working-rust-version = "1.60.0"
minimum-working-rust-version = "1.59.0"

[package.metadata.playground]
features = ["__internal_use_only_features_that_work_on_stable"]
Expand All @@ -59,6 +59,10 @@ zerocopy-derive = { version = "=0.8.0-alpha.2", path = "zerocopy-derive" }
[dev-dependencies]
assert_matches = "1.5"
itertools = "0.11"
# We don't use this directly, but trybuild does. On the MWRV toolchain, the
# version resolver fails to select any version for once_cell unless we
# depend on it directly.
once_cell = "=1.9"
rand = { version = "0.8.5", features = ["small_rng"] }
rustversion = "1.0"
static_assertions = "1.1"
Expand All @@ -67,7 +71,7 @@ testutil = { path = "testutil" }
# 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.85", features = ["diff"] }
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" }
# TODO(#381) Remove this dependency once we have our own layout gadgets.
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ impl DstLayout {
None => Self::MIN_ALIGN,
};

assert!(align.is_power_of_two());
assert!(align.get().is_power_of_two());

DstLayout { align, size_info: SizeInfo::Sized { _size: 0 } }
}
Expand Down Expand Up @@ -542,7 +542,7 @@ impl DstLayout {
None => Self::THEORETICAL_MAX_ALIGN,
};

assert!(max_align.is_power_of_two());
assert!(max_align.get().is_power_of_two());

// We use Kani to prove that this method is robust to future increases
// in Rust's maximum allowed alignment. However, if such a change ever
Expand Down
4 changes: 2 additions & 2 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ macro_rules! unsafe_impl {
=> $trait:ident for $ty:ty $(; |$candidate:ident $(: MaybeAligned<$ref_repr:ty>)? $(: Maybe<$ptr_repr:ty>)?| $is_bit_valid:expr)?
) => {
$(#[$attr])*
unsafe impl<$(const $constname: $constty,)* $($tyvar $(: $(? $optbound +)* $($bound +)*)?),*> $trait for $ty {
unsafe impl<$($tyvar $(: $(? $optbound +)* $($bound +)*)?),* $(, const $constname: $constty,)*> $trait for $ty {
unsafe_impl!(@method $trait $(; |$candidate: $(MaybeAligned<$ref_repr>)? $(Maybe<$ptr_repr>)?| $is_bit_valid)?);
}
};
Expand Down Expand Up @@ -341,7 +341,7 @@ macro_rules! impl_known_layout {
use core::ptr::NonNull;

// SAFETY: Delegates safety to `DstLayout::for_type`.
unsafe impl<$(const $constvar : $constty,)? $($tyvar $(: ?$optbound)?)?> KnownLayout for $ty {
unsafe impl<$($tyvar $(: ?$optbound)?)? $(, const $constvar : $constty)?> KnownLayout for $ty {
#[allow(clippy::missing_inline_in_public_items)]
fn only_derive_is_allowed_to_implement_this_trait() where Self: Sized {}

Expand Down
7 changes: 4 additions & 3 deletions src/pointer/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ mod def {
}
}

#[allow(unreachable_pub)] // This is a false positive on our MSRV toolchain.
pub use def::Ptr;

/// Used to define the system of [invariants][invariant] of `Ptr`.
Expand Down Expand Up @@ -1088,7 +1089,7 @@ mod tests {

// - If `size_of::<T>() == 0`, `N == 4`
// - Else, `N == 4 * size_of::<T>()`
fn test<const N: usize, T: ?Sized + KnownLayout + FromBytes>() {
fn test<T: ?Sized + KnownLayout + FromBytes, const N: usize>() {
let mut bytes = [MaybeUninit::<u8>::uninit(); N];
let initialized = [MaybeUninit::new(0u8); N];
for start in 0..=bytes.len() {
Expand Down Expand Up @@ -1183,11 +1184,11 @@ mod tests {
$({
const S: usize = core::mem::size_of::<$ty>();
const N: usize = if S == 0 { 4 } else { S * 4 };
test::<N, $ty>();
test::<$ty, N>();
// We don't support casting into DSTs whose trailing slice
// element is a ZST.
if S > 0 {
test::<N, [$ty]>();
test::<[$ty], N>();
}
// TODO: Test with a slice DST once we have any that
// implement `KnownLayout + FromBytes`.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
29 changes: 15 additions & 14 deletions testutil/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_version::{Channel, Version};
use std::error::Error;

struct PinnedVersions {
msrv: String,
mwrv: String,
stable: String,
nightly: String,
}
Expand All @@ -34,28 +34,29 @@ impl PinnedVersions {
.into_iter()
.find(|pkg| pkg.name == "zerocopy")
.ok_or("no `zerocopy` package found; are we in a workspace?")?;
let msrv = pkg
.rust_version
.as_ref()
.ok_or("failed to find msrv: no `rust-version` key present")?
.to_string();
// let msrv = pkg
// .rust_version
// .as_ref()
// .ok_or("failed to find msrv: no `rust-version` key present")?
// .to_string();
let extract = |version_name, key| -> Result<String, String> {
let value = pkg.metadata.pointer(&format!("/ci/{key}")).ok_or_else(|| {
format!("failed to find {version_name}: no `metadata.ci.{key}` key present")
})?;
value.as_str().map(str::to_string).ok_or_else(|| format!("failed to find {version_name}: key `metadata.ci.{key}` (contents: {value:?}) failed to parse as JSON string"))
};
let mwrv = extract("stable", "minimum-working-rust-version")?;
let stable = extract("stable", "pinned-stable")?;
let nightly = extract("nightly", "pinned-nightly")?;
Ok(PinnedVersions { msrv, stable, nightly })
Ok(PinnedVersions { mwrv, stable, nightly })
}
}

#[derive(Debug)]
pub enum ToolchainVersion {
/// The version listed as our MSRV (ie, the `package.rust-version` key in
/// The version listed as our MWRV (ie, the `package.rust-version` key in
/// `Cargo.toml`).
PinnedMsrv,
PinnedMwrv,
/// The stable version pinned in CI.
PinnedStable,
/// The nightly version pinned in CI
Expand Down Expand Up @@ -109,7 +110,7 @@ impl ToolchainVersion {
};

Ok(match s {
s if s == pinned_versions.msrv => ToolchainVersion::PinnedMsrv,
s if s == pinned_versions.mwrv => ToolchainVersion::PinnedMwrv,
s if s == pinned_versions.stable => ToolchainVersion::PinnedStable,
s if s == pinned_nightly_adjusted => ToolchainVersion::PinnedNightly,
_ if current.channel == Channel::Stable => ToolchainVersion::OtherStable,
Expand All @@ -134,15 +135,15 @@ impl ToolchainVersion {
/// error messages are not stable, and sometimes change between Rust
/// versions. Thus, we maintain one set of UI tests for each Rust version
/// that we test in CI, and we pin to specific versions in CI (a specific
/// MSRV, a specific stable version, and a specific date of the nightly
/// MWRV, a specific stable version, and a specific date of the nightly
/// compiler). Updating those pinned versions may also require updating
/// these tests.
/// - `tests/ui-nightly` - Contains the source of truth for our UI test
/// source files (`.rs`), and contains `.err` and `.out` files for nightly
/// - `tests/ui-stable` - Contains symlinks to the `.rs` files in
/// `tests/ui-nightly`, and contains `.err` and `.out` files for stable
/// - `tests/ui-msrv` - Contains symlinks to the `.rs` files in
/// `tests/ui-nightly`, and contains `.err` and `.out` files for MSRV
/// - `tests/ui-mwrv` - Contains symlinks to the `.rs` files in
/// `tests/ui-nightly`, and contains `.err` and `.out` files for MWRV
pub fn get_ui_source_files_dirname_and_maybe_print_warning(&self) -> &'static str {
if matches!(self, ToolchainVersion::OtherStable | ToolchainVersion::OtherNightly) {
// This will be eaten by the test harness and only displayed on
Expand All @@ -151,7 +152,7 @@ impl ToolchainVersion {
}

match self {
ToolchainVersion::PinnedMsrv => "ui-msrv",
ToolchainVersion::PinnedMwrv => "ui-mwrv",
ToolchainVersion::PinnedStable | ToolchainVersion::OtherStable => "ui-stable",
ToolchainVersion::PinnedNightly | ToolchainVersion::OtherNightly => "ui-nightly",
}
Expand Down
6 changes: 5 additions & 1 deletion zerocopy-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ quote = "1.0.10"
syn = "2.0.31"

[dev-dependencies]
# We don't use this directly, but trybuild does. On the MWRV toolchain, the
# version resolver fails to select any version for once_cell unless we
# depend on it directly.
once_cell = "=1.9"
static_assertions = "1.1"
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.85", features = ["diff"] }
trybuild = { version = "=1.0.89", features = ["diff"] }
zerocopy = { path = "../", features = ["derive"] }
4 changes: 2 additions & 2 deletions zerocopy-derive/tests/enum_known_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ assert_impl_all!(Baz: KnownLayout);

#[derive(KnownLayout)]
#[repr(C)]
enum WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + KnownLayout>
enum WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + KnownLayout, const N: usize>
where
'a: 'b,
'b: 'a,
Expand All @@ -43,4 +43,4 @@ where
Variant([T; N], PhantomData<&'a &'b ()>),
}

assert_impl_all!(WithParams<'static, 'static, 42, u8>: KnownLayout);
assert_impl_all!(WithParams<'static, 'static, u8, 42>: KnownLayout);
4 changes: 2 additions & 2 deletions zerocopy-derive/tests/enum_no_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ assert_impl_all!(Baz: NoCell);

#[derive(NoCell)]
#[repr(C)]
enum WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + NoCell>
enum WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + NoCell, const N: usize>
where
'a: 'b,
'b: 'a,
Expand All @@ -47,4 +47,4 @@ where
UnsafeCell(PhantomData<UnsafeCell<()>>, &'a UnsafeCell<()>),
}

assert_impl_all!(WithParams<'static, 'static, 42, u8>: NoCell);
assert_impl_all!(WithParams<'static, 'static, u8, 42>: NoCell);
4 changes: 2 additions & 2 deletions zerocopy-derive/tests/struct_from_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ assert_impl_all!(TypeParams<'static, [AU16], IntoIter<()>>: FromBytes);

#[derive(FromZeros, FromBytes)]
#[repr(transparent)]
struct WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + FromBytes>(
struct WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + FromBytes, const N: usize>(
[T; N],
PhantomData<&'a &'b ()>,
)
Expand All @@ -76,4 +76,4 @@ where
'b: 'a,
T: 'a + 'b + FromBytes;

assert_impl_all!(WithParams<'static, 'static, 42, u8>: FromBytes);
assert_impl_all!(WithParams<'static, 'static, u8, 42>: FromBytes);
4 changes: 2 additions & 2 deletions zerocopy-derive/tests/struct_from_zeros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ assert_impl_all!(TypeParams<'static, [AU16], IntoIter<()>>: FromZeros);

#[derive(FromZeros)]
#[repr(transparent)]
struct WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + FromZeros>(
struct WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + FromZeros, const N: usize>(
[T; N],
PhantomData<&'a &'b ()>,
)
Expand All @@ -74,4 +74,4 @@ where
'b: 'a,
T: 'a + 'b + FromZeros;

assert_impl_all!(WithParams<'static, 'static, 42, u8>: FromZeros);
assert_impl_all!(WithParams<'static, 'static, u8, 42>: FromZeros);
4 changes: 2 additions & 2 deletions zerocopy-derive/tests/struct_known_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ assert_impl_all!(TypeParams<'static, AU16, IntoIter<()>>: KnownLayout);

#[derive(KnownLayout)]
#[repr(C)]
struct WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + KnownLayout>(
struct WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + KnownLayout, const N: usize>(
[T; N],
PhantomData<&'a &'b ()>,
)
Expand All @@ -62,4 +62,4 @@ where
'b: 'a,
T: 'a + 'b + KnownLayout;

assert_impl_all!(WithParams<'static, 'static, 42, u8>: KnownLayout);
assert_impl_all!(WithParams<'static, 'static, u8, 42>: KnownLayout);
4 changes: 2 additions & 2 deletions zerocopy-derive/tests/struct_no_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ assert_impl_all!(WithAssocType<UnsafeCell<u8>>: NoCell);

#[derive(NoCell)]
#[repr(C)]
struct WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + NoCell>(
struct WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + NoCell, const N: usize>(
[T; N],
PhantomData<&'a &'b ()>,
PhantomData<UnsafeCell<()>>,
Expand All @@ -98,4 +98,4 @@ where
'b: 'a,
T: 'a + 'b + NoCell;

assert_impl_all!(WithParams<'static, 'static, 42, u8>: NoCell);
assert_impl_all!(WithParams<'static, 'static, u8, 42>: NoCell);
4 changes: 2 additions & 2 deletions zerocopy-derive/tests/struct_to_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ assert_impl_all!(Unsized: IntoBytes);

#[derive(IntoBytes)]
#[repr(transparent)]
struct WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + IntoBytes>(
struct WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + IntoBytes, const N: usize>(
[T; N],
PhantomData<&'a &'b ()>,
)
Expand All @@ -158,4 +158,4 @@ where
'b: 'a,
T: 'a + 'b + IntoBytes;

assert_impl_all!(WithParams<'static, 'static, 42, u8>: IntoBytes);
assert_impl_all!(WithParams<'static, 'static, u8, 42>: IntoBytes);
4 changes: 2 additions & 2 deletions zerocopy-derive/tests/struct_try_from_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ assert_impl_all!(TypeParams<'static, [AU16], IntoIter<()>>: TryFromBytes);

#[derive(TryFromBytes, FromZeros, FromBytes)]
#[repr(transparent)]
struct WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + TryFromBytes>(
struct WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + TryFromBytes, const N: usize>(
PhantomData<&'a &'b ()>,
[T],
)
Expand All @@ -142,7 +142,7 @@ where
'b: 'a,
T: 'a + 'b + TryFromBytes;

assert_impl_all!(WithParams<'static, 'static, 42, u8>: TryFromBytes);
assert_impl_all!(WithParams<'static, 'static, u8, 42>: TryFromBytes);

#[derive(Debug, PartialEq, Eq, TryFromBytes, KnownLayout)]
#[repr(C, packed)]
Expand Down
4 changes: 2 additions & 2 deletions zerocopy-derive/tests/struct_unaligned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ assert_impl_all!(TypeParams<'static, [u8], IntoIter<()>>: Unaligned);

#[derive(Unaligned)]
#[repr(transparent)]
struct WithParams<'a: 'b, 'b: 'a, const N: usize, T: 'a + 'b + Unaligned>(
struct WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + Unaligned, const N: usize>(
[T; N],
PhantomData<&'a &'b ()>,
)
Expand All @@ -97,4 +97,4 @@ where
'b: 'a,
T: 'a + 'b + Unaligned;

assert_impl_all!(WithParams<'static, 'static, 42, u8>: Unaligned);
assert_impl_all!(WithParams<'static, 'static, u8, 42>: Unaligned);
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit a816e0f

Please sign in to comment.