From ae22feb07dd7455a7375d77431b15d52bce753b0 Mon Sep 17 00:00:00 2001 From: Luthaf Date: Wed, 22 May 2024 12:36:20 +0200 Subject: [PATCH] Fix new clippy warnings --- soa-derive-internal/src/input.rs | 11 ----------- soa-derive-internal/src/ptr.rs | 3 +++ soa-derive-internal/src/refs.rs | 1 + soa-derive-internal/src/vec.rs | 3 +++ tests/index.rs | 12 ++++++------ tests/ptr.rs | 1 - 6 files changed, 13 insertions(+), 18 deletions(-) diff --git a/soa-derive-internal/src/input.rs b/soa-derive-internal/src/input.rs index 4466696..faa0fac 100644 --- a/soa-derive-internal/src/input.rs +++ b/soa-derive-internal/src/input.rs @@ -192,7 +192,6 @@ impl Input { pub(crate) trait TokenStreamIterator: Iterator { fn concat_by(self, f: impl Fn(proc_macro2::TokenStream, proc_macro2::TokenStream) -> proc_macro2::TokenStream) -> proc_macro2::TokenStream; - fn concat(self) -> proc_macro2::TokenStream; } impl> TokenStreamIterator for T { @@ -206,22 +205,12 @@ impl> TokenStreamIterator for T { None => quote!{}, } } - - fn concat(self) -> proc_macro2::TokenStream { - self.concat_by(|a, b| quote! { #a #b }) - } } #[cfg(test)] mod tests { use super::*; - #[test] - fn concat() { - let token_streams = vec![quote!{a}, quote!{b}, quote!{c}]; - assert_eq!(token_streams.into_iter().concat().to_string(), "a b c"); - } - #[test] fn concat_by() { let token_streams = vec![quote!{a}, quote!{b}, quote!{c}]; diff --git a/soa-derive-internal/src/ptr.rs b/soa-derive-internal/src/ptr.rs index 1f9f927..48627d6 100644 --- a/soa-derive-internal/src/ptr.rs +++ b/soa-derive-internal/src/ptr.rs @@ -303,6 +303,7 @@ pub fn derive(input: &Input) -> TokenStream { /// Similar to [`*mut T::write()`](https://doc.rust-lang.org/std/primitive.pointer.html#method.write), /// with the same safety caveats. + #[allow(clippy::forget_non_drop)] pub unsafe fn write(self, val: #name) { unsafe { #(self.#fields_names.write(::std::ptr::read(&val.#fields_names));)* @@ -314,6 +315,7 @@ pub fn derive(input: &Input) -> TokenStream { /// Similar to [`*mut T::write_volatile()`](https://doc.rust-lang.org/std/primitive.pointer.html#method.write_volatile), /// with the same safety caveats. + #[allow(clippy::forget_non_drop)] pub unsafe fn write_volatile(self, val: #name) { unsafe { #(self.#fields_names.write_volatile(::std::ptr::read(&val.#fields_names));)* @@ -325,6 +327,7 @@ pub fn derive(input: &Input) -> TokenStream { /// Similar to [`*mut T::write_unaligned()`](https://doc.rust-lang.org/std/primitive.pointer.html#method.write_unaligned), /// with the same safety caveats. + #[allow(clippy::forget_non_drop)] pub unsafe fn write_unaligned(self, val: #name) { unsafe { #(self.#fields_names.write_unaligned(::std::ptr::read(&val.#fields_names));)* diff --git a/soa-derive-internal/src/refs.rs b/soa-derive-internal/src/refs.rs index 874b7aa..9ab05b5 100644 --- a/soa-derive-internal/src/refs.rs +++ b/soa-derive-internal/src/refs.rs @@ -158,6 +158,7 @@ pub fn derive(input: &Input) -> TokenStream { } /// Similar to [`std::mem::replace()`](https://doc.rust-lang.org/std/mem/fn.replace.html). + #[allow(clippy::forget_non_drop)] pub fn replace(&mut self, val: #name) -> #name { #( let field = unsafe { ::std::ptr::read(&val.#fields_names) }; diff --git a/soa-derive-internal/src/vec.rs b/soa-derive-internal/src/vec.rs index 2437a0f..8ae8307 100644 --- a/soa-derive-internal/src/vec.rs +++ b/soa-derive-internal/src/vec.rs @@ -149,6 +149,7 @@ pub fn derive(input: &Input) -> TokenStream { /// Similar to [` #[doc = #vec_name_str] /// ::push()`](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.push). + #[allow(clippy::forget_non_drop)] pub fn push(&mut self, value: #name) { // We need to use ptr read/write instead of moving out of the // fields in case the value struct implements Drop. @@ -193,6 +194,7 @@ pub fn derive(input: &Input) -> TokenStream { /// Similar to [` #[doc = #vec_name_str] /// ::insert()`](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.insert). + #[allow(clippy::forget_non_drop)] pub fn insert(&mut self, index: usize, element: #name) { if index > self.len() { panic!("index out of bounds: the len is {} but the index is {}", self.len(), index); @@ -209,6 +211,7 @@ pub fn derive(input: &Input) -> TokenStream { } /// Similar to [`std::mem::replace()`](https://doc.rust-lang.org/std/mem/fn.replace.html). + #[allow(clippy::forget_non_drop)] pub fn replace(&mut self, index: usize, element: #name) -> #name { if index > self.len() { panic!("index out of bounds: the len is {} but the index is {}", self.len(), index); diff --git a/tests/index.rs b/tests/index.rs index e8bb2e3..aa81360 100644 --- a/tests/index.rs +++ b/tests/index.rs @@ -26,8 +26,8 @@ fn index_vec_with_usize() { soa.push(particle.clone()); // SoAIndex - assert_eq!(soa.get(0).unwrap().name, &aos.get(0).unwrap().name); - assert_eq!(soa.get(0).unwrap().mass, &aos.get(0).unwrap().mass); + assert_eq!(soa.get(0).unwrap().name, &aos.first().unwrap().name); + assert_eq!(soa.get(0).unwrap().mass, &aos.first().unwrap().mass); assert_eq!(aos.get(1), None); assert_eq!(soa.get(1), None); @@ -64,7 +64,7 @@ fn index_vec_with_usize() { #[test] fn index_vec_with_ranges() { - let particles = vec![ + let particles = [ Particle::new(String::from("Cl"), 1.0), Particle::new(String::from("Na"), 2.0), Particle::new(String::from("Br"), 3.0), @@ -142,8 +142,8 @@ fn index_slice_with_usize() { let aos_slice = aos.as_slice(); let soa_slice = soa.as_slice(); - assert_eq!(soa_slice.get(0).unwrap().name, &aos_slice.get(0).unwrap().name); - assert_eq!(soa_slice.get(0).unwrap().mass, &aos_slice.get(0).unwrap().mass); + assert_eq!(soa_slice.get(0).unwrap().name, &aos_slice.first().unwrap().name); + assert_eq!(soa_slice.get(0).unwrap().mass, &aos_slice.first().unwrap().mass); assert_eq!(aos_slice.get(1), None); assert_eq!(soa_slice.get(1), None); @@ -183,7 +183,7 @@ fn index_slice_with_usize() { #[test] fn index_slice_with_ranges() { - let particles = vec![ + let particles = [ Particle::new(String::from("Cl"), 1.0), Particle::new(String::from("Na"), 2.0), Particle::new(String::from("Br"), 3.0), diff --git a/tests/ptr.rs b/tests/ptr.rs index 20fe11f..d7e6817 100644 --- a/tests/ptr.rs +++ b/tests/ptr.rs @@ -163,6 +163,5 @@ fn write() { assert_eq!(vec.data[0], 4); } - // std::mem::forget(vec); assert_eq!(DROP_COUNTER.load(Ordering::SeqCst), 1); }