Skip to content

Commit

Permalink
chore(all): fix new lints
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeul-zama committed Sep 6, 2024
1 parent 54bb3e5 commit 61f9066
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 24 deletions.
2 changes: 2 additions & 0 deletions apps/trivium/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::too_long_first_doc_paragraph)]

mod static_deque;

mod kreyvium;
Expand Down
6 changes: 3 additions & 3 deletions tfhe/examples/fhe_strings/server_key/pattern/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl ServerKey {
str: &'a FheString,
pat: &'a FheString,
null: Option<&'a FheAsciiChar>,
) -> (CharIter, CharIter, Range<usize>) {
) -> (CharIter<'a>, CharIter<'a>, Range<usize>) {
let pat_len = pat.chars().len();
let str_len = str.chars().len();

Expand Down Expand Up @@ -138,7 +138,7 @@ impl ServerKey {
&'a self,
str: &'a FheString,
pat: &str,
) -> (CharIter, String, Range<usize>) {
) -> (CharIter<'a>, String, Range<usize>) {
let pat_len = pat.len();
let str_len = str.chars().len();

Expand All @@ -165,7 +165,7 @@ impl ServerKey {
str: &'a FheString,
pat: &'a FheString,
null: Option<&'a FheAsciiChar>,
) -> (CharIter, CharIter, Range<usize>) {
) -> (CharIter<'a>, CharIter<'a>, Range<usize>) {
let pat_len = pat.chars().len();
let str_len = str.chars().len();

Expand Down
18 changes: 13 additions & 5 deletions tfhe/src/c_api/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,19 @@ 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::<DynamicBuffer>(&mut dynamic_buffer))
};

assert_eq!(res, 0);
assert!(dynamic_buffer.pointer.is_null());
assert_eq!(dynamic_buffer.length, 0);
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::<DynamicBuffer>(&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());
Expand All @@ -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::<u8>(&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::<DynamicBuffer>(&mut dynamic_buffer))
};
assert_eq!(res, 1);
}

Expand All @@ -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::<DynamicBuffer>(&mut dynamic_buffer))
};

assert_eq!(res, 0);
assert!(dynamic_buffer.pointer.is_null());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions tfhe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 4 additions & 3 deletions utils/tfhe-versionable-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions utils/tfhe-versionable/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub trait VersionizeOwned {
}

/// This trait is used as a proxy to be more felxible when deriving Versionize for Vec<T>.
///
/// This way, we can chose to skip versioning Vec<T> 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.
Expand Down Expand Up @@ -154,9 +155,10 @@ impl From<Infallible> 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.
Expand Down
6 changes: 3 additions & 3 deletions utils/tfhe-versionable/tests/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 61f9066

Please sign in to comment.