From 6c72f91c09d46b8fd4958b7274eccdc359523fd0 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Mon, 28 Oct 2024 18:32:28 +0100 Subject: [PATCH 1/2] Revert "fix: revert MSRV changes (#789)" This reverts commit 4a657340c3cd78ad858189b4366b851a61246b72. --- .github/workflows/ci.yml | 10 +++--- Cargo.toml | 2 +- README.md | 2 +- clippy.toml | 2 +- crates/dyn-abi/src/coerce.rs | 3 +- crates/primitives/src/postgres.rs | 4 +-- crates/primitives/src/signed/errors.rs | 3 +- crates/sol-type-parser/src/error.rs | 3 +- crates/sol-type-parser/src/input.rs | 3 +- crates/sol-types/src/abi/encoder.rs | 20 +++++++---- crates/sol-types/src/impl_core.rs | 40 --------------------- crates/sol-types/src/types/error.rs | 6 ++-- crates/sol-types/src/types/interface/mod.rs | 8 ++--- crates/syn-solidity/tests/contracts.rs | 2 +- 14 files changed, 33 insertions(+), 75 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 57457dfb83..38a11d854b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: rust: [ "stable", "nightly", - "1.79", # MSRV + "1.81", # MSRV ] flags: [ # No features @@ -35,10 +35,10 @@ jobs: include: # MSRV features - os: "ubuntu-latest" - rust: "1.79" # MSRV + rust: "1.81" # MSRV flags: "--features json" - os: "windows-latest" - rust: "1.79" # MSRV + rust: "1.81" # MSRV flags: "--features json" # All features - os: "ubuntu-latest" @@ -57,10 +57,10 @@ jobs: cache-on-failure: true # Only run tests on latest stable and above - name: build - if: ${{ matrix.rust == '1.79' }} # MSRV + if: ${{ matrix.rust == '1.81' }} # MSRV run: cargo build --workspace ${{ matrix.flags }} - name: test - if: ${{ matrix.rust != '1.79' }} # MSRV + if: ${{ matrix.rust != '1.81' }} # MSRV run: cargo test --workspace ${{ matrix.flags }} miri: diff --git a/Cargo.toml b/Cargo.toml index 477ca5a711..1f3f18f45e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ resolver = "2" [workspace.package] version = "0.8.9" edition = "2021" -rust-version = "1.79" +rust-version = "1.81" authors = ["Alloy Contributors"] license = "MIT OR Apache-2.0" homepage = "https://github.com/alloy-rs/core" diff --git a/README.md b/README.md index da22c178d4..513eac9450 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ When updating this, also update: - .github/workflows/ci.yml --> -The current MSRV (minimum supported rust version) is 1.79. +The current MSRV (minimum supported rust version) is 1.81. Alloy will keep a rolling MSRV policy of **at least** two versions behind the latest stable release (so if the latest stable release is 1.58, we would diff --git a/clippy.toml b/clippy.toml index f1acf4b112..8c0bc009eb 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1 +1 @@ -msrv = "1.79" +msrv = "1.81" diff --git a/crates/dyn-abi/src/coerce.rs b/crates/dyn-abi/src/coerce.rs index 0d23acc5f8..4f9bd781c2 100644 --- a/crates/dyn-abi/src/coerce.rs +++ b/crates/dyn-abi/src/coerce.rs @@ -256,8 +256,7 @@ enum Error { EmptyHexStringWithoutPrefix, } -#[cfg(feature = "std")] -impl std::error::Error for Error {} +impl core::error::Error for Error {} impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/crates/primitives/src/postgres.rs b/crates/primitives/src/postgres.rs index 05fc29f508..ba1c9f25a2 100644 --- a/crates/primitives/src/postgres.rs +++ b/crates/primitives/src/postgres.rs @@ -63,7 +63,7 @@ pub enum ToSqlError { Overflow(usize, Type), } -impl std::error::Error for ToSqlError {} +impl core::error::Error for ToSqlError {} /// Convert to Postgres types. /// @@ -225,7 +225,7 @@ pub enum FromSqlError { ParseError(Type), } -impl std::error::Error for FromSqlError {} +impl core::error::Error for FromSqlError {} impl<'a, const BITS: usize, const LIMBS: usize> FromSql<'a> for Signed { fn accepts(ty: &Type) -> bool { diff --git a/crates/primitives/src/signed/errors.rs b/crates/primitives/src/signed/errors.rs index b41c7c80cb..72a303f7b1 100644 --- a/crates/primitives/src/signed/errors.rs +++ b/crates/primitives/src/signed/errors.rs @@ -48,8 +48,7 @@ impl fmt::Display for ParseSignedError { #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct BigIntConversionError; -#[cfg(feature = "std")] -impl std::error::Error for BigIntConversionError {} +impl core::error::Error for BigIntConversionError {} impl fmt::Display for BigIntConversionError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/crates/sol-type-parser/src/error.rs b/crates/sol-type-parser/src/error.rs index 3812fd0b93..2bd87c9d10 100644 --- a/crates/sol-type-parser/src/error.rs +++ b/crates/sol-type-parser/src/error.rs @@ -8,8 +8,7 @@ pub type Result = core::result::Result; #[derive(Clone, PartialEq, Eq)] pub struct Error(Repr); -#[cfg(feature = "std")] -impl std::error::Error for Error {} +impl core::error::Error for Error {} impl fmt::Debug for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/crates/sol-type-parser/src/input.rs b/crates/sol-type-parser/src/input.rs index 475304d6ed..6af47b2d48 100644 --- a/crates/sol-type-parser/src/input.rs +++ b/crates/sol-type-parser/src/input.rs @@ -18,8 +18,7 @@ impl fmt::Display for CustomError { } } -#[cfg(feature = "std")] -impl std::error::Error for CustomError {} +impl core::error::Error for CustomError {} pub type Input<'a> = winnow::Stateful<&'a str, RecursionCheck>; diff --git a/crates/sol-types/src/abi/encoder.rs b/crates/sol-types/src/abi/encoder.rs index 23fd77d8dd..c802f5798d 100644 --- a/crates/sol-types/src/abi/encoder.rs +++ b/crates/sol-types/src/abi/encoder.rs @@ -43,6 +43,12 @@ impl Encoder { } } + /// Return a reference to the encoded words. + #[inline] + pub fn words(&self) -> &[Word] { + &self.buf + } + /// Finish the encoding process, returning the encoded words. /// /// Use `into_bytes` instead to flatten the words into bytes. @@ -53,16 +59,18 @@ impl Encoder { self.buf } + /// Return a reference to the encoded bytes. + #[inline] + pub fn bytes(&self) -> &[u8] { + // SAFETY: `#[repr(transparent)] FixedBytes([u8; N])` + unsafe { &*(self.words() as *const [Word] as *const [[u8; 32]]) }.as_flattened() + } + /// Finish the encoding process, returning the encoded bytes. #[inline] pub fn into_bytes(self) -> Vec { - // TODO: remove once `Vec::into_flattened` is stabilized. - // unsafe { mem::transmute::, Vec<[u8; 32]>>(self.buf) }.into_flattened() - // SAFETY: `#[repr(transparent)] FixedBytes([u8; N])` - crate::impl_core::into_flattened::(unsafe { - mem::transmute::, Vec<[u8; 32]>>(self.buf) - }) + unsafe { mem::transmute::, Vec<[u8; 32]>>(self.finish()) }.into_flattened() } /// Determine the current suffix offset. diff --git a/crates/sol-types/src/impl_core.rs b/crates/sol-types/src/impl_core.rs index 505987d10d..4f6e114c26 100644 --- a/crates/sol-types/src/impl_core.rs +++ b/crates/sol-types/src/impl_core.rs @@ -1,16 +1,7 @@ //! Modified implementations of unstable libcore functions. -use alloc::vec::Vec; use core::mem::{self, MaybeUninit}; -trait Ext { - const IS_ZST: bool; -} - -impl Ext for T { - const IS_ZST: bool = mem::size_of::() == 0; -} - /// [`core::array::try_from_fn`] #[inline] pub(crate) fn try_from_fn(mut cb: F) -> Result<[T; N], E> @@ -88,34 +79,3 @@ pub(crate) unsafe fn array_assume_init(array: [MaybeUninit unsafe fn transpose(array: [MaybeUninit; N]) -> MaybeUninit<[T; N]> { mem::transmute_copy::<[MaybeUninit; N], MaybeUninit<[T; N]>>(&mem::ManuallyDrop::new(&array)) } - -// TODO(MSRV-1.80): remove -/// [`Vec::into_flattened`]. -#[inline] -pub(crate) fn into_flattened(vec: Vec<[T; N]>) -> Vec { - let (ptr, len, cap) = into_raw_parts(vec); - let (new_len, new_cap) = if T::IS_ZST { - (len.checked_mul(N).expect("vec len overflow"), usize::MAX) - } else { - // SAFETY: - // - `cap * N` cannot overflow because the allocation is already in - // the address space. - // - Each `[T; N]` has `N` valid elements, so there are `len * N` - // valid elements in the allocation. - unsafe { (len.checked_mul(N).unwrap_unchecked(), cap.checked_mul(N).unwrap_unchecked()) } - }; - // SAFETY: - // - `ptr` was allocated by `self` - // - `ptr` is well-aligned because `[T; N]` has the same alignment as `T`. - // - `new_cap` refers to the same sized allocation as `cap` because - // `new_cap * size_of::()` == `cap * size_of::<[T; N]>()` - // - `len` <= `cap`, so `len * N` <= `cap * N`. - unsafe { Vec::from_raw_parts(ptr.cast(), new_len, new_cap) } -} - -/// [`Vec::into_raw_parts`] -#[inline(always)] -fn into_raw_parts(vec: Vec) -> (*mut T, usize, usize) { - let mut me = mem::ManuallyDrop::new(vec); - (me.as_mut_ptr(), me.len(), me.capacity()) -} diff --git a/crates/sol-types/src/types/error.rs b/crates/sol-types/src/types/error.rs index 25046d568f..4ffbd003ee 100644 --- a/crates/sol-types/src/types/error.rs +++ b/crates/sol-types/src/types/error.rs @@ -103,8 +103,7 @@ impl fmt::Display for Revert { } } -#[cfg(feature = "std")] -impl std::error::Error for Revert {} +impl core::error::Error for Revert {} impl AsRef for Revert { #[inline] @@ -264,8 +263,7 @@ impl fmt::Display for Panic { } } -#[cfg(feature = "std")] -impl std::error::Error for Panic {} +impl core::error::Error for Panic {} impl SolError for Panic { type Parameters<'a> = (crate::sol_data::Uint<256>,); diff --git a/crates/sol-types/src/types/interface/mod.rs b/crates/sol-types/src/types/interface/mod.rs index 0491748be0..a054cf1e3b 100644 --- a/crates/sol-types/src/types/interface/mod.rs +++ b/crates/sol-types/src/types/interface/mod.rs @@ -2,9 +2,6 @@ use crate::{alloc::string::ToString, Error, Panic, Result, Revert, SolError}; use alloc::{string::String, vec::Vec}; use core::{convert::Infallible, fmt, iter::FusedIterator, marker::PhantomData}; -#[cfg(feature = "std")] -use std::error::Error as StdError; - mod event; pub use event::SolEventInterface; @@ -211,10 +208,9 @@ impl fmt::Display for ContractError { } } -#[cfg(feature = "std")] -impl StdError for ContractError { +impl core::error::Error for ContractError { #[inline] - fn source(&self) -> Option<&(dyn StdError + 'static)> { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { Self::CustomError(error) => Some(error), Self::Panic(panic) => Some(panic), diff --git a/crates/syn-solidity/tests/contracts.rs b/crates/syn-solidity/tests/contracts.rs index c9fb26ea03..3b65b26164 100644 --- a/crates/syn-solidity/tests/contracts.rs +++ b/crates/syn-solidity/tests/contracts.rs @@ -100,7 +100,7 @@ impl Drop for GitPatcher<'_> { } } -fn parse_file(path: &Path) -> Result> { +fn parse_file(path: &Path) -> Result> { let solidity = fs::read_to_string(path)?; syn::parse_str(&solidity).map_err(Into::into) } From 9257553d053d5391b74de0ccdc1632b1c72d401d Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Wed, 6 Nov 2024 15:36:45 +0100 Subject: [PATCH 2/2] chore: remove unused dependencies --- Cargo.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1f3f18f45e..8fe345d4c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,8 +64,6 @@ cfg-if = "1.0.0" derive_more = { version = "1.0", default-features = false } hex-literal = "0.4" paste = "1.0" -num_enum = "0.7" -thiserror = "1.0" # crypto digest = "0.10"