Skip to content

Commit

Permalink
Fix CI build, introduce justfile
Browse files Browse the repository at this point in the history
  • Loading branch information
paholg committed Feb 18, 2025
1 parent 21c7d60 commit 88280ba
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 30 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,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
Expand All @@ -90,7 +90,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
24 changes: 24 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Run all CI checks except those that require different platforms
test-local: lint test
@just test --features const-generics

# 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}}
24 changes: 17 additions & 7 deletions src/bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,28 @@ impl BitXor<B1> 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(), <Test as Bit>::to_u8());
type Test = <<$Lhs as $op>::Output as $crate::Same<$Answer>>::Output;
assert_eq!(
<$Answer as $crate::Bit>::to_u8(),
<Test as $crate::Bit>::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(), <Test as Bit>::to_u8());
type Test = <<$Lhs as $op<$Rhs>>::Output as $crate::Same<$Answer>>::Output;
assert_eq!(
<$Answer as $crate::Bit>::to_u8(),
<Test as $crate::Bit>::to_u8()
);
}};
}

Expand Down Expand Up @@ -318,7 +328,7 @@ impl Max<B1> for B1 {
}

#[cfg(test)]
mod tests {
mod bit_creation_tests {
#[test]
fn bit_creation() {
{
Expand Down
14 changes: 1 addition & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]

Expand Down Expand Up @@ -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")]
Expand Down
7 changes: 6 additions & 1 deletion src/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ pub trait Trim {
pub type TrimOut<A> = <A as Trim>::Output;

/// Gets rid of all zeros until it hits a one.
// ONLY IMPLEMENT FOR INVERTED NUMBERS!
pub trait TrimTrailingZeros {
type Output;
Expand Down Expand Up @@ -395,6 +394,7 @@ use crate::{Equal, False, Greater, Less, True};
pub trait IsLessPrivate<Rhs, Cmp> {
type Output: Bit;

#[allow(clippy::wrong_self_convention)]
fn is_less_private(self, _: Rhs, _: Cmp) -> Self::Output;
}

Expand Down Expand Up @@ -426,6 +426,7 @@ impl<A, B> IsLessPrivate<B, Greater> for A {
pub trait IsEqualPrivate<Rhs, Cmp> {
type Output: Bit;

#[allow(clippy::wrong_self_convention)]
fn is_equal_private(self, _: Rhs, _: Cmp) -> Self::Output;
}

Expand Down Expand Up @@ -457,6 +458,7 @@ impl<A, B> IsEqualPrivate<B, Greater> for A {
pub trait IsGreaterPrivate<Rhs, Cmp> {
type Output: Bit;

#[allow(clippy::wrong_self_convention)]
fn is_greater_private(self, _: Rhs, _: Cmp) -> Self::Output;
}

Expand Down Expand Up @@ -488,6 +490,7 @@ impl<A, B> IsGreaterPrivate<B, Greater> for A {
pub trait IsLessOrEqualPrivate<Rhs, Cmp> {
type Output: Bit;

#[allow(clippy::wrong_self_convention)]
fn is_less_or_equal_private(self, _: Rhs, _: Cmp) -> Self::Output;
}

Expand Down Expand Up @@ -519,6 +522,7 @@ impl<A, B> IsLessOrEqualPrivate<B, Greater> for A {
pub trait IsNotEqualPrivate<Rhs, Cmp> {
type Output: Bit;

#[allow(clippy::wrong_self_convention)]
fn is_not_equal_private(self, _: Rhs, _: Cmp) -> Self::Output;
}

Expand Down Expand Up @@ -550,6 +554,7 @@ impl<A, B> IsNotEqualPrivate<B, Greater> for A {
pub trait IsGreaterOrEqualPrivate<Rhs, Cmp> {
type Output: Bit;

#[allow(clippy::wrong_self_convention)]
fn is_greater_or_equal_private(self, _: Rhs, _: Cmp) -> Self::Output;
}

Expand Down
7 changes: 7 additions & 0 deletions src/type_operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ pub trait Cmp<Rhs = Self> {
}

/// 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;
Expand Down Expand Up @@ -355,6 +356,7 @@ pub trait IsLess<Rhs = Self> {
/// 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;
}

Expand All @@ -377,6 +379,7 @@ pub trait IsEqual<Rhs = Self> {
/// 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;
}

Expand All @@ -399,6 +402,7 @@ pub trait IsGreater<Rhs = Self> {
/// 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;
}

Expand All @@ -421,6 +425,7 @@ pub trait IsLessOrEqual<Rhs = Self> {
/// 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;
}

Expand All @@ -443,6 +448,7 @@ pub trait IsNotEqual<Rhs = Self> {
/// 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;
}

Expand All @@ -465,6 +471,7 @@ pub trait IsGreaterOrEqual<Rhs = Self> {
/// 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;
}

Expand Down
13 changes: 10 additions & 3 deletions src/uint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,7 @@ where
type Output = Shleft<UInt<UInt<U, B>, B0>, Sub1<UInt<Ur, Br>>>;
#[inline]
fn shl(self, rhs: UInt<Ur, Br>) -> Self::Output {
#[allow(clippy::suspicious_arithmetic_impl)]
(UInt { msb: self, lsb: B0 }).shl(rhs - B1)
}
}
Expand Down Expand Up @@ -985,6 +986,7 @@ where
type Output = Shright<U, Sub1<UInt<Ur, Br>>>;
#[inline]
fn shr(self, rhs: UInt<Ur, Br>) -> Self::Output {
#[allow(clippy::suspicious_arithmetic_impl)]
self.msb.shr(rhs - B1)
}
}
Expand Down Expand Up @@ -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>;
Expand Down Expand Up @@ -1706,8 +1712,8 @@ where
{
type Output = PrivateDivQuot<UInt<Ul, Bl>, UInt<Ur, Br>, U0, U0, Sub1<Length<UInt<Ul, Bl>>>>;
#[inline]
#[cfg_attr(feature = "cargo-clippy", allow(clippy::suspicious_arithmetic_impl))]
fn div(self, rhs: UInt<Ur, Br>) -> Self::Output {
#[allow(clippy::suspicious_arithmetic_impl)]
().private_div_quotient(self, rhs, U0::new(), U0::new(), self.len() - B1)
}
}
Expand Down Expand Up @@ -1735,6 +1741,7 @@ where
type Output = PrivateDivRem<UInt<Ul, Bl>, UInt<Ur, Br>, U0, U0, Sub1<Length<UInt<Ul, Bl>>>>;
#[inline]
fn rem(self, rhs: UInt<Ur, Br>) -> Self::Output {
#[allow(clippy::suspicious_arithmetic_impl)]
().private_div_remainder(self, rhs, UTerm, UTerm, self.len() - B1)
}
}
Expand Down

0 comments on commit 88280ba

Please sign in to comment.