Skip to content

Commit

Permalink
Fix Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog committed Mar 3, 2024
1 parent 2b636ec commit c6d4151
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
toolchain: ${{matrix.rust}}
- uses: Swatinem/rust-cache@v2
- run: cargo build --all-features -p audio -p audio-core -p audio-generator -p ste
if: matrix.rust == 'stable'
if: matrix.rust != 'stable'
- run: cargo test --all-features --all-targets -p audio -p audio-core -p audio-generator -p ste
if: matrix.rust == 'stable'
- run: cargo test --no-default-features --all-targets -p audio -p audio-core -p audio-generator
Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@1.68
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- run: cargo clippy --all-targets -p audio -p audio-core -p audio-generator -p ste -- -D warnings
Expand Down
19 changes: 7 additions & 12 deletions audio/src/channel/interleaved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ impl<'a, T> InterleavedChannelMut<'a, T> {
}

/// Get the given frame if it's in bound.
pub fn into_mut(self, frame: usize) -> Option<&'a mut T> {
pub fn into_mut(mut self, frame: usize) -> Option<&'a mut T> {
if frame < len!(self) {
if mem::size_of::<T>() == 0 {
Some(unsafe { &mut *(self.ptr.as_ptr() as *mut _) })
Some(unsafe { self.ptr.as_mut() })
} else {
let add = frame.saturating_mul(self.step);
Some(unsafe { &mut *(self.ptr.as_ptr() as *mut T).add(add) })
Some(unsafe { &mut *self.ptr.as_ptr().add(add) })
}
} else {
None
Expand All @@ -171,10 +171,10 @@ impl<'a, T> InterleavedChannelMut<'a, T> {
pub fn get_mut(&mut self, n: usize) -> Option<&mut T> {
if n < len!(self) {
if mem::size_of::<T>() == 0 {
Some(unsafe { &mut *(self.ptr.as_ptr() as *mut _) })
Some(unsafe { self.ptr.as_mut() })
} else {
let add = n.saturating_mul(self.step);
Some(unsafe { &mut *(self.ptr.as_ptr() as *mut T).add(add) })
Some(unsafe { &mut *self.ptr.as_ptr().add(add) })
}
} else {
None
Expand Down Expand Up @@ -233,12 +233,7 @@ where

impl<T> Clone for InterleavedChannel<'_, T> {
fn clone(&self) -> Self {
Self {
ptr: self.ptr,
end: self.end,
step: self.step,
_marker: marker::PhantomData,
}
*self
}
}

Expand Down Expand Up @@ -355,7 +350,7 @@ unsafe fn align_iterable_mut<T>(
(ptr, end)
} else {
let ptr = ptr.add(offset);
let end = ptr.wrapping_add(len) as *mut T;
let end = ptr.wrapping_add(len);
(ptr, end)
};

Expand Down
4 changes: 0 additions & 4 deletions audio/src/channel/interleaved/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ macro_rules! iterator {
// non-null end pointer. The call to `next_unchecked!` is safe
// since we check if the iterator is empty first.
unsafe {
assert!(!self.ptr.as_ptr().is_null());

if mem::size_of::<T>() != 0 {
assert!(!self.end.is_null());
}
Expand Down Expand Up @@ -191,8 +189,6 @@ macro_rules! iterator {
// The call to `next_back_unchecked!` is safe since we check if the iterator is
// empty first.
unsafe {
assert!(!self.ptr.as_ptr().is_null());

if mem::size_of::<T>() != 0 {
assert!(!self.end.is_null());
}
Expand Down
8 changes: 4 additions & 4 deletions audio/src/channel/interleaved/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn test_interleaved_channel_mut() {

let c1 = unsafe {
InterleavedChannelMut::new_unchecked(
ptr::NonNull::new_unchecked(buf.as_mut_ptr() as *mut u32),
ptr::NonNull::new_unchecked(buf.as_mut_ptr()),
buf.len(),
0,
2,
Expand All @@ -43,7 +43,7 @@ fn test_interleaved_channel_mut() {

let c2 = unsafe {
InterleavedChannelMut::new_unchecked(
ptr::NonNull::new_unchecked(buf.as_mut_ptr() as *mut u32),
ptr::NonNull::new_unchecked(buf.as_mut_ptr()),
buf.len(),
1,
2,
Expand All @@ -60,7 +60,7 @@ fn test_interleaved_channel_mut_iter() {

let mut c1 = unsafe {
InterleavedChannelMut::new_unchecked(
ptr::NonNull::new_unchecked(buf.as_mut_ptr() as *mut u32),
ptr::NonNull::new_unchecked(buf.as_mut_ptr()),
buf.len(),
0,
2,
Expand All @@ -69,7 +69,7 @@ fn test_interleaved_channel_mut_iter() {

let c2 = unsafe {
InterleavedChannelMut::new_unchecked(
ptr::NonNull::new_unchecked(buf.as_mut_ptr() as *mut u32),
ptr::NonNull::new_unchecked(buf.as_mut_ptr()),
buf.len(),
1,
2,
Expand Down
7 changes: 1 addition & 6 deletions audio/src/frame/interleaved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ pub(crate) struct RawInterleaved<T> {
impl<T> Clone for RawInterleaved<T> {
#[inline]
fn clone(&self) -> Self {
Self {
ptr: self.ptr,
len: self.len,
channels: self.channels,
frames: self.frames,
}
*self
}
}

Expand Down
7 changes: 1 addition & 6 deletions audio/src/frame/sequential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ pub(crate) struct RawSequential<T> {
impl<T> Clone for RawSequential<T> {
#[inline]
fn clone(&self) -> Self {
Self {
ptr: self.ptr,
len: self.len,
channels: self.channels,
frames: self.frames,
}
*self
}
}

Expand Down

0 comments on commit c6d4151

Please sign in to comment.