Skip to content

Commit 5be1453

Browse files
committed
Fix clippy warnings, add clippy to CI
1 parent 7fccf70 commit 5be1453

File tree

22 files changed

+434
-449
lines changed

22 files changed

+434
-449
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ jobs:
9494
uses: dtolnay/rust-toolchain@master
9595
with:
9696
toolchain: ${{ matrix.rust }}
97+
components: clippy
9798
- name: Use Cross
9899
if: matrix.os == 'ubuntu-latest' && matrix.target != ''
99100
run: |
@@ -117,6 +118,8 @@ jobs:
117118
run: lscpu
118119
- name: Basic build
119120
run: ${{ env.CARGO }} build --verbose $TARGET
121+
- name: Run clippy
122+
run: ${{ env.CARGO }} clippy --verbose $TARGET
120123
- name: Build docs
121124
run: ${{ env.CARGO }} doc --verbose $TARGET
122125
- name: Show byte order for debugging
@@ -130,7 +133,7 @@ jobs:
130133
- name: Run tests with miscellaneous features
131134
run: ${{ env.CARGO }} test --verbose --features logging
132135

133-
# Setup and run tests on the wasm32-wasi target via wasmtime.
136+
# Setup and run tests on the wasm32-wasip1 target via wasmtime.
134137
wasm:
135138
runs-on: ubuntu-latest
136139
env:
@@ -143,26 +146,29 @@ jobs:
143146
uses: dtolnay/rust-toolchain@master
144147
with:
145148
toolchain: stable
146-
- name: Add wasm32-wasi target
147-
run: rustup target add wasm32-wasi
149+
components: clippy
150+
- name: Add wasm32-wasip1 target
151+
run: rustup target add wasm32-wasip1
148152
- name: Download and install Wasmtime
149153
run: |
150-
echo "CARGO_BUILD_TARGET=wasm32-wasi" >> $GITHUB_ENV
154+
echo "CARGO_BUILD_TARGET=wasm32-wasip1" >> $GITHUB_ENV
151155
echo "RUSTFLAGS=-Ctarget-feature=+simd128" >> $GITHUB_ENV
152156
curl -LO https://github.com/bytecodealliance/wasmtime/releases/download/v$WASMTIME_VERSION/wasmtime-v$WASMTIME_VERSION-x86_64-linux.tar.xz
153157
tar xvf wasmtime-v$WASMTIME_VERSION-x86_64-linux.tar.xz
154158
echo `pwd`/wasmtime-v$WASMTIME_VERSION-x86_64-linux >> $GITHUB_PATH
155-
echo "CARGO_TARGET_WASM32_WASI_RUNNER=wasmtime run --wasm simd --" >> $GITHUB_ENV
159+
echo "CARGO_TARGET_WASM32_WASIP1_RUNNER=wasmtime run --wasm simd --" >> $GITHUB_ENV
156160
- name: Basic build
157161
run: cargo build --verbose
162+
- name: Run clippy
163+
run: cargo clippy --verbose --all-targets -- -Dwarnings
158164
- name: Run tests
159165
run: cargo test --verbose
160166
- name: Run with only 'alloc' enabled
161167
run: cargo test --verbose --no-default-features --features alloc
162168
- name: Run tests without any features enabled (core-only)
163169
run: cargo test --verbose --no-default-features
164170

165-
# Setup and run tests on the wasm32-wasi target via wasmtime, but without
171+
# Setup and run tests on the wasm32-wasip1 target via wasmtime, but without
166172
# simd128 enabled.
167173
wasm-no-simd128:
168174
runs-on: ubuntu-latest
@@ -176,18 +182,21 @@ jobs:
176182
uses: dtolnay/rust-toolchain@master
177183
with:
178184
toolchain: stable
179-
- name: Add wasm32-wasi target
180-
run: rustup target add wasm32-wasi
185+
components: clippy
186+
- name: Add wasm32-wasip1 target
187+
run: rustup target add wasm32-wasip1
181188
- name: Download and install Wasmtime
182189
run: |
183-
echo "CARGO_BUILD_TARGET=wasm32-wasi" >> $GITHUB_ENV
190+
echo "CARGO_BUILD_TARGET=wasm32-wasip1" >> $GITHUB_ENV
184191
echo "RUSTFLAGS=-Ctarget-feature=-simd128" >> $GITHUB_ENV
185192
curl -LO https://github.com/bytecodealliance/wasmtime/releases/download/v$WASMTIME_VERSION/wasmtime-v$WASMTIME_VERSION-x86_64-linux.tar.xz
186193
tar xvf wasmtime-v$WASMTIME_VERSION-x86_64-linux.tar.xz
187194
echo `pwd`/wasmtime-v$WASMTIME_VERSION-x86_64-linux >> $GITHUB_PATH
188-
echo "CARGO_TARGET_WASM32_WASI_RUNNER=wasmtime run --" >> $GITHUB_ENV
195+
echo "CARGO_TARGET_WASM32_WASIP1_RUNNER=wasmtime run --" >> $GITHUB_ENV
189196
- name: Basic build
190197
run: cargo build --verbose
198+
- name: Run clippy
199+
run: cargo clippy --verbose --all-targets -- -Dwarnings
191200
- name: Run tests
192201
run: cargo test --verbose
193202
- name: Run with only 'alloc' enabled
@@ -207,8 +216,11 @@ jobs:
207216
with:
208217
toolchain: stable
209218
targets: x86_64-unknown-none
219+
components: clippy
210220
- name: Build for x86_64-unknown-none with only 'alloc' enabled
211221
run: cargo build --verbose --no-default-features --features alloc --target x86_64-unknown-none
222+
- name: Run clippy for x86_64-unknown-linux-gnu without SSE
223+
run: cargo clippy --verbose --all-targets -- -Dwarnings
212224
- name: Run tests for x86_64-unknown-linux-gnu without SSE
213225
run: cargo test --verbose
214226
env:
@@ -270,8 +282,8 @@ jobs:
270282
uses: dtolnay/rust-toolchain@master
271283
with:
272284
toolchain: stable
273-
- name: Add wasm32-wasi target
274-
run: rustup target add wasm32-wasi
285+
- name: Add wasm32-wasip1 target
286+
run: rustup target add wasm32-wasip1
275287
- name: Download and install Wasmtime
276288
run: |
277289
# Note that we don't have to set CARGO_BUILD_TARGET and other

src/arch/aarch64/neon/memchr.rs

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ impl One {
142142
/// * Both `start` and `end` must be valid for reads.
143143
/// * Both `start` and `end` must point to an initialized value.
144144
/// * Both `start` and `end` must point to the same allocated object and
145-
/// must either be in bounds or at most one byte past the end of the
146-
/// allocated object.
145+
/// must either be in bounds or at most one byte past the end of the
146+
/// allocated object.
147147
/// * Both `start` and `end` must be _derived from_ a pointer to the same
148-
/// object.
148+
/// object.
149149
/// * The distance between `start` and `end` must not overflow `isize`.
150150
/// * The distance being in bounds must not rely on "wrapping around" the
151-
/// address space.
151+
/// address space.
152152
///
153153
/// Note that callers may pass a pair of pointers such that `start >= end`.
154154
/// In that case, `None` will always be returned.
@@ -186,13 +186,13 @@ impl One {
186186
/// * Both `start` and `end` must be valid for reads.
187187
/// * Both `start` and `end` must point to an initialized value.
188188
/// * Both `start` and `end` must point to the same allocated object and
189-
/// must either be in bounds or at most one byte past the end of the
190-
/// allocated object.
189+
/// must either be in bounds or at most one byte past the end of the
190+
/// allocated object.
191191
/// * Both `start` and `end` must be _derived from_ a pointer to the same
192-
/// object.
192+
/// object.
193193
/// * The distance between `start` and `end` must not overflow `isize`.
194194
/// * The distance being in bounds must not rely on "wrapping around" the
195-
/// address space.
195+
/// address space.
196196
///
197197
/// Note that callers may pass a pair of pointers such that `start >= end`.
198198
/// In that case, `None` will always be returned.
@@ -227,13 +227,13 @@ impl One {
227227
/// * Both `start` and `end` must be valid for reads.
228228
/// * Both `start` and `end` must point to an initialized value.
229229
/// * Both `start` and `end` must point to the same allocated object and
230-
/// must either be in bounds or at most one byte past the end of the
231-
/// allocated object.
230+
/// must either be in bounds or at most one byte past the end of the
231+
/// allocated object.
232232
/// * Both `start` and `end` must be _derived from_ a pointer to the same
233-
/// object.
233+
/// object.
234234
/// * The distance between `start` and `end` must not overflow `isize`.
235235
/// * The distance being in bounds must not rely on "wrapping around" the
236-
/// address space.
236+
/// address space.
237237
///
238238
/// Note that callers may pass a pair of pointers such that `start >= end`.
239239
/// In that case, `None` will always be returned.
@@ -490,13 +490,13 @@ impl Two {
490490
/// * Both `start` and `end` must be valid for reads.
491491
/// * Both `start` and `end` must point to an initialized value.
492492
/// * Both `start` and `end` must point to the same allocated object and
493-
/// must either be in bounds or at most one byte past the end of the
494-
/// allocated object.
493+
/// must either be in bounds or at most one byte past the end of the
494+
/// allocated object.
495495
/// * Both `start` and `end` must be _derived from_ a pointer to the same
496-
/// object.
496+
/// object.
497497
/// * The distance between `start` and `end` must not overflow `isize`.
498498
/// * The distance being in bounds must not rely on "wrapping around" the
499-
/// address space.
499+
/// address space.
500500
///
501501
/// Note that callers may pass a pair of pointers such that `start >= end`.
502502
/// In that case, `None` will always be returned.
@@ -534,13 +534,13 @@ impl Two {
534534
/// * Both `start` and `end` must be valid for reads.
535535
/// * Both `start` and `end` must point to an initialized value.
536536
/// * Both `start` and `end` must point to the same allocated object and
537-
/// must either be in bounds or at most one byte past the end of the
538-
/// allocated object.
537+
/// must either be in bounds or at most one byte past the end of the
538+
/// allocated object.
539539
/// * Both `start` and `end` must be _derived from_ a pointer to the same
540-
/// object.
540+
/// object.
541541
/// * The distance between `start` and `end` must not overflow `isize`.
542542
/// * The distance being in bounds must not rely on "wrapping around" the
543-
/// address space.
543+
/// address space.
544544
///
545545
/// Note that callers may pass a pair of pointers such that `start >= end`.
546546
/// In that case, `None` will always be returned.
@@ -776,13 +776,13 @@ impl Three {
776776
/// * Both `start` and `end` must be valid for reads.
777777
/// * Both `start` and `end` must point to an initialized value.
778778
/// * Both `start` and `end` must point to the same allocated object and
779-
/// must either be in bounds or at most one byte past the end of the
780-
/// allocated object.
779+
/// must either be in bounds or at most one byte past the end of the
780+
/// allocated object.
781781
/// * Both `start` and `end` must be _derived from_ a pointer to the same
782-
/// object.
782+
/// object.
783783
/// * The distance between `start` and `end` must not overflow `isize`.
784784
/// * The distance being in bounds must not rely on "wrapping around" the
785-
/// address space.
785+
/// address space.
786786
///
787787
/// Note that callers may pass a pair of pointers such that `start >= end`.
788788
/// In that case, `None` will always be returned.
@@ -822,13 +822,13 @@ impl Three {
822822
/// * Both `start` and `end` must be valid for reads.
823823
/// * Both `start` and `end` must point to an initialized value.
824824
/// * Both `start` and `end` must point to the same allocated object and
825-
/// must either be in bounds or at most one byte past the end of the
826-
/// allocated object.
825+
/// must either be in bounds or at most one byte past the end of the
826+
/// allocated object.
827827
/// * Both `start` and `end` must be _derived from_ a pointer to the same
828-
/// object.
828+
/// object.
829829
/// * The distance between `start` and `end` must not overflow `isize`.
830830
/// * The distance being in bounds must not rely on "wrapping around" the
831-
/// address space.
831+
/// address space.
832832
///
833833
/// Note that callers may pass a pair of pointers such that `start >= end`.
834834
/// In that case, `None` will always be returned.
@@ -986,45 +986,45 @@ mod tests {
986986
#[test]
987987
fn forward_two() {
988988
crate::tests::memchr::Runner::new(2).forward_iter(
989-
|haystack, needles| {
990-
let n1 = needles.get(0).copied()?;
991-
let n2 = needles.get(1).copied()?;
992-
Some(Two::new(n1, n2)?.iter(haystack).collect())
989+
|haystack, needles| match needles {
990+
&[n1, n2] => Some(Two::new(n1, n2)?.iter(haystack).collect()),
991+
_ => None,
993992
},
994993
)
995994
}
996995

997996
#[test]
998997
fn reverse_two() {
999998
crate::tests::memchr::Runner::new(2).reverse_iter(
1000-
|haystack, needles| {
1001-
let n1 = needles.get(0).copied()?;
1002-
let n2 = needles.get(1).copied()?;
1003-
Some(Two::new(n1, n2)?.iter(haystack).rev().collect())
999+
|haystack, needles| match needles {
1000+
&[n1, n2] => {
1001+
Some(Two::new(n1, n2)?.iter(haystack).rev().collect())
1002+
}
1003+
_ => None,
10041004
},
10051005
)
10061006
}
10071007

10081008
#[test]
10091009
fn forward_three() {
10101010
crate::tests::memchr::Runner::new(3).forward_iter(
1011-
|haystack, needles| {
1012-
let n1 = needles.get(0).copied()?;
1013-
let n2 = needles.get(1).copied()?;
1014-
let n3 = needles.get(2).copied()?;
1015-
Some(Three::new(n1, n2, n3)?.iter(haystack).collect())
1011+
|haystack, needles| match needles {
1012+
&[n1, n2, n3] => {
1013+
Some(Three::new(n1, n2, n3)?.iter(haystack).collect())
1014+
}
1015+
_ => None,
10161016
},
10171017
)
10181018
}
10191019

10201020
#[test]
10211021
fn reverse_three() {
10221022
crate::tests::memchr::Runner::new(3).reverse_iter(
1023-
|haystack, needles| {
1024-
let n1 = needles.get(0).copied()?;
1025-
let n2 = needles.get(1).copied()?;
1026-
let n3 = needles.get(2).copied()?;
1027-
Some(Three::new(n1, n2, n3)?.iter(haystack).rev().collect())
1023+
|haystack, needles| match needles {
1024+
&[n1, n2, n3] => Some(
1025+
Three::new(n1, n2, n3)?.iter(haystack).rev().collect(),
1026+
),
1027+
_ => None,
10281028
},
10291029
)
10301030
}

0 commit comments

Comments
 (0)