diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 4ee1472c7..fc32192df 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -47,6 +47,9 @@ jobs: target: x86_64 steps: - uses: actions/checkout@v3 + - if: matrix.rust == '1.37.0' + # Rust 1.37 doesn't like modern lock files :( + run: rm Cargo.lock - uses: dtolnay/rust-toolchain@master with: toolchain: ${{ matrix.rust }} @@ -79,8 +82,8 @@ jobs: - uses: dtolnay/rust-toolchain@master with: toolchain: ${{ matrix.rust }} - - run: cargo test --verbose --features "strict" ${{ matrix.mb_const_generics }} - - run: cargo doc --features "strict" ${{ matrix.mb_const_generics }} + - uses: extractions/setup-just@v2 + - run: just test ${{ matrix.mb_const_generics }} lint: name: Lint @@ -90,7 +93,5 @@ jobs: - uses: dtolnay/rust-toolchain@nightly with: components: rustfmt, clippy - - run: cargo fmt --all -- --check - - run: cargo clippy -- -D warnings - # Allow deprecated because we test the no_std feature. - - run: cargo clippy --all-features -- -D warnings -A deprecated + - uses: extractions/setup-just@v2 + - run: just lint diff --git a/Cargo.lock b/Cargo.lock index 3d2f09196..c51aeac48 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "byte-slice-cast" @@ -22,43 +22,43 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "derive_more" -version = "0.99.17" +version = "0.99.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" +checksum = "3da29a38df43d6f156149c9b43ded5e018ddff2a855cf2cfd62e8cd7d079c69f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.98", ] [[package]] name = "equivalent" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "hashbrown" -version = "0.14.3" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" [[package]] name = "impl-trait-for-tuples" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11d7a9f6330b71fea57921c9b61c47ee6e84f72d394754eff6163ae67e7395eb" +checksum = "a0eb5a3343abf848c0984fe4604b2b105da9539376e24fc0a3b0007411ae4fd9" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.98", ] [[package]] name = "indexmap" -version = "2.2.6" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +checksum = "8c9c992b02b5b4c94ea26e32fe5bccb7aa7d9f390ab5c1221ff895bc7ea8b652" dependencies = [ "equivalent", "hashbrown", @@ -66,15 +66,15 @@ dependencies = [ [[package]] name = "memchr" -version = "2.7.1" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "945462a4b81e43c4e3ba96bd7b49d834c6f61198356aa858733bc4acf3cbe62e" [[package]] name = "parity-scale-codec" @@ -97,7 +97,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -112,18 +112,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.79" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" dependencies = [ "proc-macro2", ] @@ -149,7 +149,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -163,11 +163,22 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn" +version = "2.0.98" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36147f1a48ae0ec2b5b3bc5b537d267457555a10dc06f3dbc8cb11ba3006d3b1" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "toml_datetime" -version = "0.6.5" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" [[package]] name = "toml_edit" @@ -189,9 +200,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "a210d160f08b701c8721ba1c726c11662f877ea6b7094007e1ca9a1041945034" [[package]] name = "winnow" diff --git a/justfile b/justfile new file mode 100644 index 000000000..56bc57471 --- /dev/null +++ b/justfile @@ -0,0 +1,29 @@ +# Run all CI checks except those that require different platforms +test-local: lint test + @just test --features const-generics + +# Update lockfiles +up: + nix flake update + cargo update + +# Run all lints +lint: fmt clippy clippy-all + +# Check formatting +fmt: + cargo fmt --all -- --check + +# Clippy +clippy: + cargo clippy -- -D warnings + +# Clippy with all features +clippy-all: + # Allow deprecated because we test the no_std feature. + cargo clippy --all-features -- -D warnings -A deprecated + +# Run test +test *args: + cargo test --verbose --features "strict" {{args}} + cargo doc --features "strict" {{args}} diff --git a/src/bit.rs b/src/bit.rs index 4a098fe84..4e3f3e87e 100644 --- a/src/bit.rs +++ b/src/bit.rs @@ -184,18 +184,28 @@ impl BitXor for B1 { } } -#[cfg(tests)] -mod tests { +#[cfg(test)] +mod bit_op_tests { + use core::ops::{BitAnd, BitOr, BitXor, Not}; + + use crate::{B0, B1}; + // macro for testing operation results. Uses `Same` to ensure the types are equal and // not just the values they evaluate to. macro_rules! test_bit_op { ($op:ident $Lhs:ident = $Answer:ident) => {{ - type Test = <<$Lhs as $op>::Output as ::Same<$Answer>>::Output; - assert_eq!(<$Answer as Bit>::to_u8(), ::to_u8()); + type Test = <<$Lhs as $op>::Output as $crate::Same<$Answer>>::Output; + assert_eq!( + <$Answer as $crate::Bit>::to_u8(), + ::to_u8() + ); }}; ($Lhs:ident $op:ident $Rhs:ident = $Answer:ident) => {{ - type Test = <<$Lhs as $op<$Rhs>>::Output as ::Same<$Answer>>::Output; - assert_eq!(<$Answer as Bit>::to_u8(), ::to_u8()); + type Test = <<$Lhs as $op<$Rhs>>::Output as $crate::Same<$Answer>>::Output; + assert_eq!( + <$Answer as $crate::Bit>::to_u8(), + ::to_u8() + ); }}; } @@ -318,7 +328,7 @@ impl Max for B1 { } #[cfg(test)] -mod tests { +mod bit_creation_tests { #[test] fn bit_creation() { { diff --git a/src/lib.rs b/src/lib.rs index 49fb4bfad..189f2c902 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -47,18 +47,6 @@ #![warn(missing_docs)] #![cfg_attr(feature = "strict", deny(missing_docs))] #![cfg_attr(feature = "strict", deny(warnings))] -#![cfg_attr( - feature = "cargo-clippy", - allow( - clippy::len_without_is_empty, - clippy::many_single_char_names, - clippy::new_without_default, - clippy::suspicious_arithmetic_impl, - clippy::type_complexity, - clippy::wrong_self_convention, - ) -)] -#![cfg_attr(feature = "cargo-clippy", deny(clippy::missing_inline_in_public_items))] #![doc(html_root_url = "https://docs.rs/typenum/1.17.0")] #![cfg_attr(docsrs, feature(doc_auto_cfg, doc_cfg))] @@ -101,7 +89,7 @@ pub use crate::{ pub use consts::{ False, True, B0, B1, U0, U1, U2, *, - N1, N2, Z0, P1, P2, *, + N1, N2, Z0, P1, P2, }; #[cfg(feature = "const-generics")] diff --git a/src/private.rs b/src/private.rs index 97b2ad80f..4fe0144b5 100644 --- a/src/private.rs +++ b/src/private.rs @@ -41,7 +41,6 @@ pub trait Trim { pub type TrimOut = ::Output; /// Gets rid of all zeros until it hits a one. - // ONLY IMPLEMENT FOR INVERTED NUMBERS! pub trait TrimTrailingZeros { type Output; @@ -395,6 +394,7 @@ use crate::{Equal, False, Greater, Less, True}; pub trait IsLessPrivate { type Output: Bit; + #[allow(clippy::wrong_self_convention)] fn is_less_private(self, _: Rhs, _: Cmp) -> Self::Output; } @@ -426,6 +426,7 @@ impl IsLessPrivate for A { pub trait IsEqualPrivate { type Output: Bit; + #[allow(clippy::wrong_self_convention)] fn is_equal_private(self, _: Rhs, _: Cmp) -> Self::Output; } @@ -457,6 +458,7 @@ impl IsEqualPrivate for A { pub trait IsGreaterPrivate { type Output: Bit; + #[allow(clippy::wrong_self_convention)] fn is_greater_private(self, _: Rhs, _: Cmp) -> Self::Output; } @@ -488,6 +490,7 @@ impl IsGreaterPrivate for A { pub trait IsLessOrEqualPrivate { type Output: Bit; + #[allow(clippy::wrong_self_convention)] fn is_less_or_equal_private(self, _: Rhs, _: Cmp) -> Self::Output; } @@ -519,6 +522,7 @@ impl IsLessOrEqualPrivate for A { pub trait IsNotEqualPrivate { type Output: Bit; + #[allow(clippy::wrong_self_convention)] fn is_not_equal_private(self, _: Rhs, _: Cmp) -> Self::Output; } @@ -550,6 +554,7 @@ impl IsNotEqualPrivate for A { pub trait IsGreaterOrEqualPrivate { type Output: Bit; + #[allow(clippy::wrong_self_convention)] fn is_greater_or_equal_private(self, _: Rhs, _: Cmp) -> Self::Output; } diff --git a/src/type_operators.rs b/src/type_operators.rs index 7e852731d..4933a62dd 100644 --- a/src/type_operators.rs +++ b/src/type_operators.rs @@ -316,6 +316,7 @@ pub trait Cmp { } /// A **type operator** that gives the length of an `Array` or the number of bits in a `UInt`. +#[allow(clippy::len_without_is_empty)] pub trait Len { /// The length as a type-level unsigned integer. type Output: crate::Unsigned; @@ -355,6 +356,7 @@ pub trait IsLess { /// The type representing either `True` or `False` type Output: Bit; /// Method returning `True` or `False`. + #[allow(clippy::wrong_self_convention)] fn is_less(self, rhs: Rhs) -> Self::Output; } @@ -377,6 +379,7 @@ pub trait IsEqual { /// The type representing either `True` or `False` type Output: Bit; /// Method returning `True` or `False`. + #[allow(clippy::wrong_self_convention)] fn is_equal(self, rhs: Rhs) -> Self::Output; } @@ -399,6 +402,7 @@ pub trait IsGreater { /// The type representing either `True` or `False` type Output: Bit; /// Method returning `True` or `False`. + #[allow(clippy::wrong_self_convention)] fn is_greater(self, rhs: Rhs) -> Self::Output; } @@ -421,6 +425,7 @@ pub trait IsLessOrEqual { /// The type representing either `True` or `False` type Output: Bit; /// Method returning `True` or `False`. + #[allow(clippy::wrong_self_convention)] fn is_less_or_equal(self, rhs: Rhs) -> Self::Output; } @@ -443,6 +448,7 @@ pub trait IsNotEqual { /// The type representing either `True` or `False` type Output: Bit; /// Method returning `True` or `False`. + #[allow(clippy::wrong_self_convention)] fn is_not_equal(self, rhs: Rhs) -> Self::Output; } @@ -465,6 +471,7 @@ pub trait IsGreaterOrEqual { /// The type representing either `True` or `False` type Output: Bit; /// Method returning `True` or `False`. + #[allow(clippy::wrong_self_convention)] fn is_greater_or_equal(self, rhs: Rhs) -> Self::Output; } diff --git a/src/uint.rs b/src/uint.rs index d5241d3a3..df798db4e 100644 --- a/src/uint.rs +++ b/src/uint.rs @@ -915,6 +915,7 @@ where type Output = Shleft, B0>, Sub1>>; #[inline] fn shl(self, rhs: UInt) -> Self::Output { + #[allow(clippy::suspicious_arithmetic_impl)] (UInt { msb: self, lsb: B0 }).shl(rhs - B1) } } @@ -985,6 +986,7 @@ where type Output = Shright>>; #[inline] fn shr(self, rhs: UInt) -> Self::Output { + #[allow(clippy::suspicious_arithmetic_impl)] self.msb.shr(rhs - B1) } } @@ -1653,8 +1655,12 @@ fn test_set_bit() { // R -= D // Q[i] = 1 -#[cfg(tests)] -mod tests { +#[cfg(test)] +mod div_tests { + use crate::Unsigned; + + use super::SetBitOut; + macro_rules! test_div { ($a:ident / $b:ident = $c:ident) => {{ type R = Quot<$a, $b>; @@ -1706,8 +1712,8 @@ where { type Output = PrivateDivQuot, UInt, U0, U0, Sub1>>>; #[inline] - #[cfg_attr(feature = "cargo-clippy", allow(clippy::suspicious_arithmetic_impl))] fn div(self, rhs: UInt) -> Self::Output { + #[allow(clippy::suspicious_arithmetic_impl)] ().private_div_quotient(self, rhs, U0::new(), U0::new(), self.len() - B1) } } @@ -1735,6 +1741,7 @@ where type Output = PrivateDivRem, UInt, U0, U0, Sub1>>>; #[inline] fn rem(self, rhs: UInt) -> Self::Output { + #[allow(clippy::suspicious_arithmetic_impl)] ().private_div_remainder(self, rhs, UTerm, UTerm, self.len() - B1) } }