Skip to content

Commit

Permalink
Lint using clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
michaellass committed Dec 28, 2021
1 parent 8a0e9a0 commit ecdaa50
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,17 @@ jobs:
- name: Setup
run: cargo miri setup
- name: Test
run: cargo miri test --verbose
run: cargo miri test --verbose

clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install rust
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
components: clippy
- name: Lint
run: cargo clippy --all-targets --all-features -- -D warnings
18 changes: 8 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl<T> AlignedBox<[T]> {
unsafe fn new_slice(
alignment: usize,
nelems: usize,
initializer: impl Fn(*mut T) -> (),
initializer: impl Fn(*mut T),
) -> std::result::Result<AlignedBox<[T]>, std::boxed::Box<dyn std::error::Error>> {
// Make sure the requested amount of Ts will fit into a slice.
let maxelems = (isize::MAX as usize) / std::mem::size_of::<T>();
Expand All @@ -206,7 +206,7 @@ impl<T> AlignedBox<[T]> {
// Initialize values. The caller must ensure that initializer does not expect valid
// values behind ptr.
for i in 0..nelems {
initializer(ptr.offset(i as isize));
initializer(ptr.add(i));
}

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

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

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

let b = AlignedBox::<[SomeVaryingDefault]>::slice_from_default(128, 1024).unwrap();
assert_eq!(SomeVaryingDefault::default().i, 1024);
let mut ctr = 0;
for i in b.iter() {
assert_eq!(i.i, ctr);
ctr += 1;
for (ctr, i) in b.iter().enumerate() {
assert_eq!(i.i, ctr as i32);
}
}

Expand Down

0 comments on commit ecdaa50

Please sign in to comment.