From 38b5759e88200726b50b8f98389447aa9ae2ba24 Mon Sep 17 00:00:00 2001 From: "Mayeul@Zama" <69792125+mayeul-zama@users.noreply.github.com> Date: Fri, 6 Sep 2024 16:33:00 +0200 Subject: [PATCH] chore(all): fix new lints --- apps/trivium/src/lib.rs | 2 ++ .../fhe_strings/server_key/pattern/mod.rs | 6 +++--- tfhe/src/c_api/buffer.rs | 18 +++++++++++++----- .../traits/contiguous_entity_container.rs | 8 ++++---- tfhe/src/lib.rs | 5 ++--- utils/tfhe-versionable-derive/src/lib.rs | 7 ++++--- utils/tfhe-versionable/src/lib.rs | 8 +++++--- utils/tfhe-versionable/tests/types.rs | 6 +++--- 8 files changed, 36 insertions(+), 24 deletions(-) diff --git a/apps/trivium/src/lib.rs b/apps/trivium/src/lib.rs index 5b362d7636..74d8e83924 100644 --- a/apps/trivium/src/lib.rs +++ b/apps/trivium/src/lib.rs @@ -1,3 +1,5 @@ +#![allow(clippy::too_long_first_doc_paragraph)] + mod static_deque; mod kreyvium; diff --git a/tfhe/examples/fhe_strings/server_key/pattern/mod.rs b/tfhe/examples/fhe_strings/server_key/pattern/mod.rs index 8c6a46dc57..54c91267bf 100644 --- a/tfhe/examples/fhe_strings/server_key/pattern/mod.rs +++ b/tfhe/examples/fhe_strings/server_key/pattern/mod.rs @@ -61,7 +61,7 @@ impl ServerKey { str: &'a FheString, pat: &'a FheString, null: Option<&'a FheAsciiChar>, - ) -> (CharIter, CharIter, Range) { + ) -> (CharIter<'a>, CharIter<'a>, Range) { let pat_len = pat.chars().len(); let str_len = str.chars().len(); @@ -138,7 +138,7 @@ impl ServerKey { &'a self, str: &'a FheString, pat: &str, - ) -> (CharIter, String, Range) { + ) -> (CharIter<'a>, String, Range) { let pat_len = pat.len(); let str_len = str.chars().len(); @@ -165,7 +165,7 @@ impl ServerKey { str: &'a FheString, pat: &'a FheString, null: Option<&'a FheAsciiChar>, - ) -> (CharIter, CharIter, Range) { + ) -> (CharIter<'a>, CharIter<'a>, Range) { let pat_len = pat.chars().len(); let str_len = str.chars().len(); diff --git a/tfhe/src/c_api/buffer.rs b/tfhe/src/c_api/buffer.rs index e45d8e1587..703fb31e16 100644 --- a/tfhe/src/c_api/buffer.rs +++ b/tfhe/src/c_api/buffer.rs @@ -168,7 +168,9 @@ mod test { destructor: Some(custom_destroy_vec_u8_buffer), }; - let res = unsafe { destroy_dynamic_buffer(&mut dynamic_buffer as *mut DynamicBuffer) }; + let res = unsafe { + destroy_dynamic_buffer(std::ptr::from_mut::(&mut dynamic_buffer)) + }; assert_eq!(res, 0); assert!(dynamic_buffer.pointer.is_null()); @@ -176,7 +178,9 @@ mod test { assert!(dynamic_buffer.destructor.is_none()); assert!(dynamic_buffer.pointer.is_null()); - let res = unsafe { destroy_dynamic_buffer(&mut dynamic_buffer as *mut DynamicBuffer) }; + let res = unsafe { + destroy_dynamic_buffer(std::ptr::from_mut::(&mut dynamic_buffer)) + }; // Same as free in C, destroy on a NULL pointer does nothing assert_eq!(res, 0); assert!(dynamic_buffer.pointer.is_null()); @@ -185,10 +189,12 @@ mod test { let mut some_u8 = 0u8; - dynamic_buffer.pointer = &mut some_u8 as *mut u8; + dynamic_buffer.pointer = std::ptr::from_mut::(&mut some_u8); assert!(dynamic_buffer.destructor.is_none()); - let res = unsafe { destroy_dynamic_buffer(&mut dynamic_buffer as *mut DynamicBuffer) }; + let res = unsafe { + destroy_dynamic_buffer(std::ptr::from_mut::(&mut dynamic_buffer)) + }; assert_eq!(res, 1); } @@ -198,7 +204,9 @@ mod test { let mut dynamic_buffer: DynamicBuffer = vec.clone().into(); - let res = unsafe { destroy_dynamic_buffer(&mut dynamic_buffer as *mut DynamicBuffer) }; + let res = unsafe { + destroy_dynamic_buffer(std::ptr::from_mut::(&mut dynamic_buffer)) + }; assert_eq!(res, 0); assert!(dynamic_buffer.pointer.is_null()); diff --git a/tfhe/src/core_crypto/commons/traits/contiguous_entity_container.rs b/tfhe/src/core_crypto/commons/traits/contiguous_entity_container.rs index 55ffeb16eb..93b5697a7a 100644 --- a/tfhe/src/core_crypto/commons/traits/contiguous_entity_container.rs +++ b/tfhe/src/core_crypto/commons/traits/contiguous_entity_container.rs @@ -254,7 +254,7 @@ pub trait ContiguousEntityContainer: AsRef<[Self::Element]> { fn par_chunks<'this>( &'this self, chunk_size: usize, - ) -> ParallelChunksWrappingLendingIterator<'_, Self::Element, Self::SelfView<'_>> + ) -> ParallelChunksWrappingLendingIterator<'this, Self::Element, Self::SelfView<'this>> where Self::Element: Sync, Self::SelfView<'this>: Send, @@ -275,7 +275,7 @@ pub trait ContiguousEntityContainer: AsRef<[Self::Element]> { fn par_chunks_exact<'this>( &'this self, chunk_size: usize, - ) -> ParallelChunksExactWrappingLendingIterator<'_, Self::Element, Self::SelfView<'_>> + ) -> ParallelChunksExactWrappingLendingIterator<'this, Self::Element, Self::SelfView<'this>> where Self::Element: Sync, Self::SelfView<'this>: Send, @@ -457,7 +457,7 @@ pub trait ContiguousEntityContainerMut: ContiguousEntityContainer + AsMut<[Self: fn par_chunks_mut<'this>( &'this mut self, chunk_size: usize, - ) -> ParallelChunksWrappingLendingIteratorMut<'_, Self::Element, Self::SelfMutView<'_>> + ) -> ParallelChunksWrappingLendingIteratorMut<'this, Self::Element, Self::SelfMutView<'this>> where Self::Element: Sync + Send, Self::SelfMutView<'this>: Send, @@ -478,7 +478,7 @@ pub trait ContiguousEntityContainerMut: ContiguousEntityContainer + AsMut<[Self: fn par_chunks_exact_mut<'this>( &'this mut self, chunk_size: usize, - ) -> ParallelChunksExactWrappingLendingIteratorMut<'_, Self::Element, Self::SelfMutView<'_>> + ) -> ParallelChunksExactWrappingLendingIteratorMut<'this, Self::Element, Self::SelfMutView<'this>> where Self::Element: Sync + Send, Self::SelfMutView<'this>: Send, diff --git a/tfhe/src/lib.rs b/tfhe/src/lib.rs index 5cee53e31b..0758e7557a 100644 --- a/tfhe/src/lib.rs +++ b/tfhe/src/lib.rs @@ -31,9 +31,8 @@ #![allow(clippy::float_cmp)] // 7 #![allow(clippy::bool_to_int_with_if)] // 6 #![allow(clippy::unsafe_derive_deserialize)] // 1 -#![allow(clippy::cast_possible_wrap)] -// 1 - +#![allow(clippy::cast_possible_wrap)] // 1 +#![allow(clippy::too_long_first_doc_paragraph)] // These pedantic lints are deemed to bring too little value therefore they are allowed (which are // their natural state anyways, being pedantic lints) diff --git a/utils/tfhe-versionable-derive/src/lib.rs b/utils/tfhe-versionable-derive/src/lib.rs index 1b9dead2f2..c2410d037c 100644 --- a/utils/tfhe-versionable-derive/src/lib.rs +++ b/utils/tfhe-versionable-derive/src/lib.rs @@ -129,9 +129,10 @@ pub fn derive_versions_dispatch(input: TokenStream) -> TokenStream { .into() } -/// This derives the `Versionize` and `Unversionize` trait for the target type. This macro -/// has a mandatory attribute parameter, which is the name of the versioned enum for this type. -/// This enum can be anywhere in the code but should be in scope. +/// This derives the `Versionize` and `Unversionize` trait for the target type. +/// +/// This macro has a mandatory attribute parameter, which is the name of the versioned enum for this +/// type. This enum can be anywhere in the code but should be in scope. #[proc_macro_derive(Versionize, attributes(versionize))] pub fn derive_versionize(input: TokenStream) -> TokenStream { let input = parse_macro_input!(input as DeriveInput); diff --git a/utils/tfhe-versionable/src/lib.rs b/utils/tfhe-versionable/src/lib.rs index 45f7d625a0..1f54902eef 100644 --- a/utils/tfhe-versionable/src/lib.rs +++ b/utils/tfhe-versionable/src/lib.rs @@ -49,6 +49,7 @@ pub trait VersionizeOwned { } /// This trait is used as a proxy to be more felxible when deriving Versionize for Vec. +/// /// This way, we can chose to skip versioning Vec if T is a native types but still versionize in /// a loop if T is a custom type. /// This is used as a workaround for feature(specialization) and to bypass the orphan rule. @@ -154,9 +155,10 @@ impl From for UnversionizeError { } } -/// This trait means that we can convert from a versioned enum into the target type. This trait -/// can only be implemented on Owned/static types, whereas `Versionize` can also be implemented -/// on reference types. +/// This trait means that we can convert from a versioned enum into the target type. +/// +/// This trait can only be implemented on Owned/static types, whereas `Versionize` can also be +/// implemented on reference types. pub trait Unversionize: VersionizeOwned + Sized { /// Creates an object from a versioned enum, and eventually upgrades from previous /// variants. diff --git a/utils/tfhe-versionable/tests/types.rs b/utils/tfhe-versionable/tests/types.rs index 1ef96a6ef2..57760e6b7e 100644 --- a/utils/tfhe-versionable/tests/types.rs +++ b/utils/tfhe-versionable/tests/types.rs @@ -59,9 +59,9 @@ fn test_types() { aligned_box: ABox::new(0, -98765), aligned_vec: AVec::from_slice(0, &[1, 2, 3, 4]), never: (), - tuple: (3.14, 2.71), - set: HashSet::from_iter([1, 2, 3].into_iter()), - map: HashMap::from_iter([('t', true), ('e', false), ('s', true)].into_iter()), + tuple: (std::f32::consts::PI, std::f64::consts::E), + set: HashSet::from_iter([1, 2, 3]), + map: HashMap::from_iter([('t', true), ('e', false), ('s', true)]), }; let mut ser = Vec::new();