Skip to content

Commit

Permalink
Fix clippy warnings, add clippy to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
purplesyringa committed Jul 29, 2024
1 parent 7fccf70 commit 9d2b52f
Show file tree
Hide file tree
Showing 22 changed files with 432 additions and 447 deletions.
32 changes: 22 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ jobs:
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
components: clippy
- name: Use Cross
if: matrix.os == 'ubuntu-latest' && matrix.target != ''
run: |
Expand All @@ -117,6 +118,8 @@ jobs:
run: lscpu
- name: Basic build
run: ${{ env.CARGO }} build --verbose $TARGET
- name: Run clippy
run: ${{ env.CARGO }} clippy --verbose $TARGET
- name: Build docs
run: ${{ env.CARGO }} doc --verbose $TARGET
- name: Show byte order for debugging
Expand All @@ -130,7 +133,7 @@ jobs:
- name: Run tests with miscellaneous features
run: ${{ env.CARGO }} test --verbose --features logging

# Setup and run tests on the wasm32-wasi target via wasmtime.
# Setup and run tests on the wasm32-wasip1 target via wasmtime.
wasm:
runs-on: ubuntu-latest
env:
Expand All @@ -143,26 +146,29 @@ jobs:
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- name: Add wasm32-wasi target
run: rustup target add wasm32-wasi
components: clippy
- name: Add wasm32-wasip1 target
run: rustup target add wasm32-wasip1
- name: Download and install Wasmtime
run: |
echo "CARGO_BUILD_TARGET=wasm32-wasi" >> $GITHUB_ENV
echo "CARGO_BUILD_TARGET=wasm32-wasip1" >> $GITHUB_ENV
echo "RUSTFLAGS=-Ctarget-feature=+simd128" >> $GITHUB_ENV
curl -LO https://github.com/bytecodealliance/wasmtime/releases/download/v$WASMTIME_VERSION/wasmtime-v$WASMTIME_VERSION-x86_64-linux.tar.xz
tar xvf wasmtime-v$WASMTIME_VERSION-x86_64-linux.tar.xz
echo `pwd`/wasmtime-v$WASMTIME_VERSION-x86_64-linux >> $GITHUB_PATH
echo "CARGO_TARGET_WASM32_WASI_RUNNER=wasmtime run --wasm simd --" >> $GITHUB_ENV
- name: Basic build
run: cargo build --verbose
- name: Run clippy
run: cargo clippy --verbose --all-targets -- -Dwarnings
- name: Run tests
run: cargo test --verbose
- name: Run with only 'alloc' enabled
run: cargo test --verbose --no-default-features --features alloc
- name: Run tests without any features enabled (core-only)
run: cargo test --verbose --no-default-features

# Setup and run tests on the wasm32-wasi target via wasmtime, but without
# Setup and run tests on the wasm32-wasip1 target via wasmtime, but without
# simd128 enabled.
wasm-no-simd128:
runs-on: ubuntu-latest
Expand All @@ -176,18 +182,21 @@ jobs:
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- name: Add wasm32-wasi target
run: rustup target add wasm32-wasi
components: clippy
- name: Add wasm32-wasip1 target
run: rustup target add wasm32-wasip1
- name: Download and install Wasmtime
run: |
echo "CARGO_BUILD_TARGET=wasm32-wasi" >> $GITHUB_ENV
echo "CARGO_BUILD_TARGET=wasm32-wasip1" >> $GITHUB_ENV
echo "RUSTFLAGS=-Ctarget-feature=-simd128" >> $GITHUB_ENV
curl -LO https://github.com/bytecodealliance/wasmtime/releases/download/v$WASMTIME_VERSION/wasmtime-v$WASMTIME_VERSION-x86_64-linux.tar.xz
tar xvf wasmtime-v$WASMTIME_VERSION-x86_64-linux.tar.xz
echo `pwd`/wasmtime-v$WASMTIME_VERSION-x86_64-linux >> $GITHUB_PATH
echo "CARGO_TARGET_WASM32_WASI_RUNNER=wasmtime run --" >> $GITHUB_ENV
- name: Basic build
run: cargo build --verbose
- name: Run clippy
run: cargo clippy --verbose --all-targets -- -Dwarnings
- name: Run tests
run: cargo test --verbose
- name: Run with only 'alloc' enabled
Expand All @@ -207,8 +216,11 @@ jobs:
with:
toolchain: stable
targets: x86_64-unknown-none
components: clippy
- name: Build for x86_64-unknown-none with only 'alloc' enabled
run: cargo build --verbose --no-default-features --features alloc --target x86_64-unknown-none
- name: Run clippy for x86_64-unknown-linux-gnu without SSE
run: cargo clippy --verbose --all-targets -- -Dwarnings
- name: Run tests for x86_64-unknown-linux-gnu without SSE
run: cargo test --verbose
env:
Expand Down Expand Up @@ -270,8 +282,8 @@ jobs:
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- name: Add wasm32-wasi target
run: rustup target add wasm32-wasi
- name: Add wasm32-wasip1 target
run: rustup target add wasm32-wasip1
- name: Download and install Wasmtime
run: |
# Note that we don't have to set CARGO_BUILD_TARGET and other
Expand Down
92 changes: 46 additions & 46 deletions src/arch/aarch64/neon/memchr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ impl One {
/// * Both `start` and `end` must be valid for reads.
/// * Both `start` and `end` must point to an initialized value.
/// * Both `start` and `end` must point to the same allocated object and
/// must either be in bounds or at most one byte past the end of the
/// allocated object.
/// must either be in bounds or at most one byte past the end of the
/// allocated object.
/// * Both `start` and `end` must be _derived from_ a pointer to the same
/// object.
/// object.
/// * The distance between `start` and `end` must not overflow `isize`.
/// * The distance being in bounds must not rely on "wrapping around" the
/// address space.
/// address space.
///
/// Note that callers may pass a pair of pointers such that `start >= end`.
/// In that case, `None` will always be returned.
Expand Down Expand Up @@ -186,13 +186,13 @@ impl One {
/// * Both `start` and `end` must be valid for reads.
/// * Both `start` and `end` must point to an initialized value.
/// * Both `start` and `end` must point to the same allocated object and
/// must either be in bounds or at most one byte past the end of the
/// allocated object.
/// must either be in bounds or at most one byte past the end of the
/// allocated object.
/// * Both `start` and `end` must be _derived from_ a pointer to the same
/// object.
/// object.
/// * The distance between `start` and `end` must not overflow `isize`.
/// * The distance being in bounds must not rely on "wrapping around" the
/// address space.
/// address space.
///
/// Note that callers may pass a pair of pointers such that `start >= end`.
/// In that case, `None` will always be returned.
Expand Down Expand Up @@ -227,13 +227,13 @@ impl One {
/// * Both `start` and `end` must be valid for reads.
/// * Both `start` and `end` must point to an initialized value.
/// * Both `start` and `end` must point to the same allocated object and
/// must either be in bounds or at most one byte past the end of the
/// allocated object.
/// must either be in bounds or at most one byte past the end of the
/// allocated object.
/// * Both `start` and `end` must be _derived from_ a pointer to the same
/// object.
/// object.
/// * The distance between `start` and `end` must not overflow `isize`.
/// * The distance being in bounds must not rely on "wrapping around" the
/// address space.
/// address space.
///
/// Note that callers may pass a pair of pointers such that `start >= end`.
/// In that case, `None` will always be returned.
Expand Down Expand Up @@ -490,13 +490,13 @@ impl Two {
/// * Both `start` and `end` must be valid for reads.
/// * Both `start` and `end` must point to an initialized value.
/// * Both `start` and `end` must point to the same allocated object and
/// must either be in bounds or at most one byte past the end of the
/// allocated object.
/// must either be in bounds or at most one byte past the end of the
/// allocated object.
/// * Both `start` and `end` must be _derived from_ a pointer to the same
/// object.
/// object.
/// * The distance between `start` and `end` must not overflow `isize`.
/// * The distance being in bounds must not rely on "wrapping around" the
/// address space.
/// address space.
///
/// Note that callers may pass a pair of pointers such that `start >= end`.
/// In that case, `None` will always be returned.
Expand Down Expand Up @@ -534,13 +534,13 @@ impl Two {
/// * Both `start` and `end` must be valid for reads.
/// * Both `start` and `end` must point to an initialized value.
/// * Both `start` and `end` must point to the same allocated object and
/// must either be in bounds or at most one byte past the end of the
/// allocated object.
/// must either be in bounds or at most one byte past the end of the
/// allocated object.
/// * Both `start` and `end` must be _derived from_ a pointer to the same
/// object.
/// object.
/// * The distance between `start` and `end` must not overflow `isize`.
/// * The distance being in bounds must not rely on "wrapping around" the
/// address space.
/// address space.
///
/// Note that callers may pass a pair of pointers such that `start >= end`.
/// In that case, `None` will always be returned.
Expand Down Expand Up @@ -776,13 +776,13 @@ impl Three {
/// * Both `start` and `end` must be valid for reads.
/// * Both `start` and `end` must point to an initialized value.
/// * Both `start` and `end` must point to the same allocated object and
/// must either be in bounds or at most one byte past the end of the
/// allocated object.
/// must either be in bounds or at most one byte past the end of the
/// allocated object.
/// * Both `start` and `end` must be _derived from_ a pointer to the same
/// object.
/// object.
/// * The distance between `start` and `end` must not overflow `isize`.
/// * The distance being in bounds must not rely on "wrapping around" the
/// address space.
/// address space.
///
/// Note that callers may pass a pair of pointers such that `start >= end`.
/// In that case, `None` will always be returned.
Expand Down Expand Up @@ -822,13 +822,13 @@ impl Three {
/// * Both `start` and `end` must be valid for reads.
/// * Both `start` and `end` must point to an initialized value.
/// * Both `start` and `end` must point to the same allocated object and
/// must either be in bounds or at most one byte past the end of the
/// allocated object.
/// must either be in bounds or at most one byte past the end of the
/// allocated object.
/// * Both `start` and `end` must be _derived from_ a pointer to the same
/// object.
/// object.
/// * The distance between `start` and `end` must not overflow `isize`.
/// * The distance being in bounds must not rely on "wrapping around" the
/// address space.
/// address space.
///
/// Note that callers may pass a pair of pointers such that `start >= end`.
/// In that case, `None` will always be returned.
Expand Down Expand Up @@ -986,45 +986,45 @@ mod tests {
#[test]
fn forward_two() {
crate::tests::memchr::Runner::new(2).forward_iter(
|haystack, needles| {
let n1 = needles.get(0).copied()?;
let n2 = needles.get(1).copied()?;
Some(Two::new(n1, n2)?.iter(haystack).collect())
|haystack, needles| match needles {
&[n1, n2] => Some(Two::new(n1, n2)?.iter(haystack).collect()),
_ => None,
},
)
}

#[test]
fn reverse_two() {
crate::tests::memchr::Runner::new(2).reverse_iter(
|haystack, needles| {
let n1 = needles.get(0).copied()?;
let n2 = needles.get(1).copied()?;
Some(Two::new(n1, n2)?.iter(haystack).rev().collect())
|haystack, needles| match needles {
&[n1, n2] => {
Some(Two::new(n1, n2)?.iter(haystack).rev().collect())
}
_ => None,
},
)
}

#[test]
fn forward_three() {
crate::tests::memchr::Runner::new(3).forward_iter(
|haystack, needles| {
let n1 = needles.get(0).copied()?;
let n2 = needles.get(1).copied()?;
let n3 = needles.get(2).copied()?;
Some(Three::new(n1, n2, n3)?.iter(haystack).collect())
|haystack, needles| match needles {
&[n1, n2, n3] => {
Some(Three::new(n1, n2, n3)?.iter(haystack).collect())
}
_ => None,
},
)
}

#[test]
fn reverse_three() {
crate::tests::memchr::Runner::new(3).reverse_iter(
|haystack, needles| {
let n1 = needles.get(0).copied()?;
let n2 = needles.get(1).copied()?;
let n3 = needles.get(2).copied()?;
Some(Three::new(n1, n2, n3)?.iter(haystack).rev().collect())
|haystack, needles| match needles {
&[n1, n2, n3] => Some(
Three::new(n1, n2, n3)?.iter(haystack).rev().collect(),
),
_ => None,
},
)
}
Expand Down
Loading

0 comments on commit 9d2b52f

Please sign in to comment.