Skip to content

Commit ecdaa50

Browse files
committed
Lint using clippy
1 parent 8a0e9a0 commit ecdaa50

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,17 @@ jobs:
137137
- name: Setup
138138
run: cargo miri setup
139139
- name: Test
140-
run: cargo miri test --verbose
140+
run: cargo miri test --verbose
141+
142+
clippy:
143+
runs-on: ubuntu-latest
144+
steps:
145+
- uses: actions/checkout@v2
146+
- name: Install rust
147+
uses: actions-rs/toolchain@v1
148+
with:
149+
toolchain: nightly
150+
override: true
151+
components: clippy
152+
- name: Lint
153+
run: cargo clippy --all-targets --all-features -- -D warnings

src/lib.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl<T> AlignedBox<[T]> {
193193
unsafe fn new_slice(
194194
alignment: usize,
195195
nelems: usize,
196-
initializer: impl Fn(*mut T) -> (),
196+
initializer: impl Fn(*mut T),
197197
) -> std::result::Result<AlignedBox<[T]>, std::boxed::Box<dyn std::error::Error>> {
198198
// Make sure the requested amount of Ts will fit into a slice.
199199
let maxelems = (isize::MAX as usize) / std::mem::size_of::<T>();
@@ -206,7 +206,7 @@ impl<T> AlignedBox<[T]> {
206206
// Initialize values. The caller must ensure that initializer does not expect valid
207207
// values behind ptr.
208208
for i in 0..nelems {
209-
initializer(ptr.offset(i as isize));
209+
initializer(ptr.add(i));
210210
}
211211

212212
// SAFETY:
@@ -236,7 +236,7 @@ impl<T> AlignedBox<[T]> {
236236
unsafe fn realloc(
237237
&mut self,
238238
nelems: usize,
239-
initializer: impl Fn(*mut T) -> (),
239+
initializer: impl Fn(*mut T),
240240
) -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
241241
// Make sure the requested amount of Ts will fit into a slice.
242242
let maxelems = (isize::MAX as usize) / std::mem::size_of::<T>();
@@ -294,7 +294,7 @@ impl<T> AlignedBox<[T]> {
294294
// Initialize newly allocated values. The caller must ensure that
295295
// initializer does not expect valid values behind ptr.
296296
for i in old_nelems..nelems {
297-
initializer(new_ptr.offset(i as isize));
297+
initializer(new_ptr.add(i));
298298
}
299299

300300
// Create a new slice, a new Box and update layout.
@@ -572,9 +572,9 @@ mod tests {
572572
fn read_write() {
573573
let _m = SEQ_TEST_MUTEX.read().unwrap();
574574

575-
let mut b = AlignedBox::<[f32]>::slice_from_value(128, 1024, 3.1415).unwrap();
575+
let mut b = AlignedBox::<[f32]>::slice_from_value(128, 1024, std::f32::consts::PI).unwrap();
576576
for i in b.iter() {
577-
assert_eq!(*i, 3.1415);
577+
assert_eq!(*i, std::f32::consts::PI);
578578
}
579579
let mut ctr: f32 = 0.0;
580580
for i in b.iter_mut() {
@@ -609,10 +609,8 @@ mod tests {
609609

610610
let b = AlignedBox::<[SomeVaryingDefault]>::slice_from_default(128, 1024).unwrap();
611611
assert_eq!(SomeVaryingDefault::default().i, 1024);
612-
let mut ctr = 0;
613-
for i in b.iter() {
614-
assert_eq!(i.i, ctr);
615-
ctr += 1;
612+
for (ctr, i) in b.iter().enumerate() {
613+
assert_eq!(i.i, ctr as i32);
616614
}
617615
}
618616

0 commit comments

Comments
 (0)