Skip to content

Improve continuous integration checks (rustfmt, rustdoc, clippy) #9

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

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
56 changes: 39 additions & 17 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,52 @@ jobs:
runs-on: ${{ matrix.os }}-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- run: rustup default stable
- run: cargo check
- run: cargo test
- run: rustup default nightly
- run: cargo test --all-features
- uses: actions/checkout@v4
- run: rustup default stable
- run: cargo check
- run: cargo test
- run: rustup default nightly
- run: cargo test --all-features
cross-test:
strategy:
matrix:
target: [
"x86_64-unknown-linux-gnu", # 64-bits, little-endian
"i686-unknown-linux-gnu", # 32-bits, little-endian
"mips-unknown-linux-gnu", # 32-bits, big-endian
"mips64-unknown-linux-gnuabi64" # 64-bits, big-endian
]
"x86_64-unknown-linux-gnu", # 64-bits, little-endian
"i686-unknown-linux-gnu", # 32-bits, little-endian
"mips-unknown-linux-gnu", # 32-bits, big-endian
"mips64-unknown-linux-gnuabi64", # 64-bits, big-endian
]
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- name: install miri
run: rustup toolchain add nightly --no-self-update --component miri && rustup default nightly
- run: |
cargo miri test --target=${{ matrix.target }} --all-features
env:
- uses: actions/checkout@v4
- name: install miri
run: rustup toolchain add nightly --no-self-update --component miri && rustup default nightly
- run: |
cargo miri test --target=${{ matrix.target }} --all-features
env:
MIRIFLAGS: -Zmiri-strict-provenance
RUSTDOCFLAGS: ${{ env.RUSTDOCFLAGS }} -Z randomize-layout
RUSTFLAGS: ${{ env.RUSTFLAGS }} -Z randomize-layout
fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: rustup update stable && rustup default stable
- run: rustup component add rustfmt
- run: cargo fmt --all --check
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: rustup update stable && rustup default stable
- run: cargo doc --workspace --document-private-items --no-deps
env:
RUSTDOCFLAGS: -D warnings
clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: rustup update stable && rustup default stable
- run: rustup component add clippy
- run: cargo clippy --workspace --all-targets --no-deps
4 changes: 2 additions & 2 deletions src/int_overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
///
/// That's a long way to say that this should be used in areas where overflow
/// is a bug but overflow checking is too slow.
pub trait DebugStrictAdd {
pub(crate) trait DebugStrictAdd {
/// See [`DebugStrictAdd`].
fn debug_strict_add(self, other: Self) -> Self;
}
Expand All @@ -37,7 +37,7 @@ macro_rules! impl_debug_strict_add {
}

/// See [`DebugStrictAdd`].
pub trait DebugStrictSub {
pub(crate) trait DebugStrictSub {
/// See [`DebugStrictAdd`].
fn debug_strict_sub(self, other: Self) -> Self;
}
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! A stable hashing algorithm used by rustc

#![cfg_attr(feature = "nightly", feature(hasher_prefixfree_extras))]
#![deny(clippy::missing_safety_doc)]
#![deny(unsafe_op_in_unsafe_fn)]
#![deny(unreachable_pub)]

mod int_overflow;
mod sip128;
Expand Down
8 changes: 4 additions & 4 deletions src/sip128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,13 +408,13 @@ impl SipHasher128 {

state.v2 ^= 0xee;
Sip13Rounds::d_rounds(&mut state);
let _0 = state.v0 ^ state.v1 ^ state.v2 ^ state.v3;
let l = state.v0 ^ state.v1 ^ state.v2 ^ state.v3;

state.v1 ^= 0xdd;
Sip13Rounds::d_rounds(&mut state);
let _1 = state.v0 ^ state.v1 ^ state.v2 ^ state.v3;
let h = state.v0 ^ state.v1 ^ state.v2 ^ state.v3;

[_0, _1]
[l, h]
}
}

Expand Down Expand Up @@ -523,7 +523,7 @@ impl Hasher for SipHasher128 {
}

fn finish(&self) -> u64 {
let mut buf = self.buf.clone();
let mut buf = self.buf;
let [a, b] = unsafe {
SipHasher128::finish128_inner(self.nbuf, &mut buf, self.state, self.processed)
};
Expand Down
41 changes: 21 additions & 20 deletions src/sip128/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,26 @@ fn test_siphash_1_3_test_vector() {

let mut input: Vec<u8> = Vec::new();

for i in 0..64 {
#[allow(clippy::identity_op)]
for (i, v) in TEST_VECTOR.iter().enumerate() {
let out = hash_with(SipHasher128::new_with_keys(k0, k1), &Bytes(&input[..]));
let expected = [
((TEST_VECTOR[i][0] as u64) << 0)
| ((TEST_VECTOR[i][1] as u64) << 8)
| ((TEST_VECTOR[i][2] as u64) << 16)
| ((TEST_VECTOR[i][3] as u64) << 24)
| ((TEST_VECTOR[i][4] as u64) << 32)
| ((TEST_VECTOR[i][5] as u64) << 40)
| ((TEST_VECTOR[i][6] as u64) << 48)
| ((TEST_VECTOR[i][7] as u64) << 56),
((TEST_VECTOR[i][8] as u64) << 0)
| ((TEST_VECTOR[i][9] as u64) << 8)
| ((TEST_VECTOR[i][10] as u64) << 16)
| ((TEST_VECTOR[i][11] as u64) << 24)
| ((TEST_VECTOR[i][12] as u64) << 32)
| ((TEST_VECTOR[i][13] as u64) << 40)
| ((TEST_VECTOR[i][14] as u64) << 48)
| ((TEST_VECTOR[i][15] as u64) << 56),
((v[0] as u64) << 0)
| ((v[1] as u64) << 8)
| ((v[2] as u64) << 16)
| ((v[3] as u64) << 24)
| ((v[4] as u64) << 32)
| ((v[5] as u64) << 40)
| ((v[6] as u64) << 48)
| ((v[7] as u64) << 56),
((v[8] as u64) << 0)
| ((v[9] as u64) << 8)
| ((v[10] as u64) << 16)
| ((v[11] as u64) << 24)
| ((v[12] as u64) << 32)
| ((v[13] as u64) << 40)
| ((v[14] as u64) << 48)
| ((v[15] as u64) << 56),
];

assert_eq!(out.0, expected);
Expand All @@ -128,21 +129,21 @@ fn test_siphash_1_3_test_vector() {
#[cfg(target_arch = "arm")]
fn test_hash_usize() {
let val = 0xdeadbeef_deadbeef_u64;
assert!(hash(&(val as u64)) != hash(&(val as usize)));
assert!(hash(&val) != hash(&(val as usize)));
assert_eq!(hash(&(val as u32)), hash(&(val as usize)));
}
#[test]
#[cfg(target_arch = "x86_64")]
fn test_hash_usize() {
let val = 0xdeadbeef_deadbeef_u64;
assert_eq!(hash(&(val as u64)), hash(&(val as usize)));
assert_eq!(hash(&val), hash(&(val as usize)));
assert!(hash(&(val as u32)) != hash(&(val as usize)));
}
#[test]
#[cfg(target_arch = "x86")]
fn test_hash_usize() {
let val = 0xdeadbeef_deadbeef_u64;
assert!(hash(&(val as u64)) != hash(&(val as usize)));
assert!(hash(&val) != hash(&(val as usize)));
assert_eq!(hash(&(val as u32)), hash(&(val as usize)));
}

Expand Down
3 changes: 0 additions & 3 deletions src/stable_hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ impl<H: ExtendedHasher + Default> StableHasher<H> {
///
/// To be used with the [`Hasher`] implementation and [`StableHasher::finish`].
#[inline]
#[must_use]
pub fn new() -> Self {
Default::default()
}
Expand All @@ -136,7 +135,6 @@ impl<H: ExtendedHasher + Default> Default for StableHasher<H> {
///
/// To be used with the [`Hasher`] implementation and [`StableHasher::finish`].
#[inline]
#[must_use]
fn default() -> Self {
StableHasher {
state: Default::default(),
Expand All @@ -153,7 +151,6 @@ impl<H: ExtendedHasher> StableHasher<H> {
/// is not covered by this crate guarentees and will make the resulting hash
/// NOT platform independent.
#[inline]
#[must_use]
pub fn with_hasher(state: H) -> Self {
StableHasher { state }
}
Expand Down