From ec708f83701764746db3b512825ad6affe707a07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikuro=E3=81=95=E3=81=84=E3=81=AA?= Date: Fri, 22 Sep 2023 00:15:26 +0900 Subject: [PATCH] refactor: Fix clippy warnings (#69) --- .github/workflows/rust.yml | 4 ++++ rich-sdl2-rust-sys/build.rs | 2 +- src/audio/buffer.rs | 6 ++++-- src/audio/queue.rs | 2 +- src/mixer/chunk/channel/pause.rs | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 5db11494..1202b2be 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -75,6 +75,10 @@ jobs: - name: Create docs if: matrix.os == 'ubuntu-latest' run: cargo +nightly doc --features vendor,nightly,vulkan,simd_allocator,ttf,mixer --no-deps + - name: Publish test + if: matrix.os == 'ubuntu-latest' + working-directory: ./rich-sdl2-rust-sys + run: cargo publish --dry-run --features vendor - uses: actions/upload-artifact@v3 if: matrix.os == 'ubuntu-latest' diff --git a/rich-sdl2-rust-sys/build.rs b/rich-sdl2-rust-sys/build.rs index 693f7a19..ecbb6db2 100644 --- a/rich-sdl2-rust-sys/build.rs +++ b/rich-sdl2-rust-sys/build.rs @@ -107,7 +107,7 @@ fn include_paths(target_os: &str) -> impl Iterator { .probe("sdl2") .into_iter() .flat_map(|sdl2| sdl2.include_paths) - .chain(std::env::var("SDL2_PATH").map(PathBuf::from).into_iter()), + .chain(std::env::var("SDL2_PATH").map(PathBuf::from)), ); } if cfg!(feature = "ttf") { diff --git a/src/audio/buffer.rs b/src/audio/buffer.rs index 2206e433..ca39191e 100644 --- a/src/audio/buffer.rs +++ b/src/audio/buffer.rs @@ -160,10 +160,12 @@ impl AudioBuffer { fn as_u8_slice(slice: &[T]) -> &[u8] { let size = std::mem::size_of::(); - unsafe { std::slice::from_raw_parts(slice.as_ptr().cast(), slice.len() * size) } + unsafe { std::slice::from_raw_parts(slice.as_ptr().cast(), std::mem::size_of_val(slice)) } } fn as_u8_slice_mut(slice: &mut [T]) -> &mut [u8] { let size = std::mem::size_of::(); - unsafe { std::slice::from_raw_parts_mut(slice.as_mut_ptr().cast(), slice.len() * size) } + unsafe { + std::slice::from_raw_parts_mut(slice.as_mut_ptr().cast(), std::mem::size_of_val(slice)) + } } diff --git a/src/audio/queue.rs b/src/audio/queue.rs index ff6e6ae7..4b8029c3 100644 --- a/src/audio/queue.rs +++ b/src/audio/queue.rs @@ -23,7 +23,7 @@ impl<'device> QueuedAudio<'device> { /// /// Returns `Err` if failed to queue `data`. pub fn queue(&self, data: &[T]) -> Result<()> { - let size = data.len() * std::mem::size_of::(); + let size = std::mem::size_of_val(data); let ret = unsafe { bind::SDL_QueueAudio(self.device.id, data.as_ptr().cast(), size as u32) }; if ret < 0 { diff --git a/src/mixer/chunk/channel/pause.rs b/src/mixer/chunk/channel/pause.rs index f6804f08..7bc536d2 100644 --- a/src/mixer/chunk/channel/pause.rs +++ b/src/mixer/chunk/channel/pause.rs @@ -8,7 +8,7 @@ pub struct Pauser<'channel>(i32, PhantomData<&'channel mut Channel<'channel>>); impl<'channel> Pauser<'channel> { /// Pauses playing on the [`Channel`], or `None` if it is free. - pub fn pause(channel: &'channel mut Channel<'channel>) -> Option { + pub fn pause(channel: &'channel Channel<'channel>) -> Option { if channel.0 == -1 { return None; }