From 49825d657edd8a22a79a94abfaed63e6c92de823 Mon Sep 17 00:00:00 2001 From: Thibaut Lorrain Date: Wed, 18 Jan 2023 16:51:05 +0100 Subject: [PATCH] remove unused apis and clippy fixes --- ffi-convert-derive/src/asrust.rs | 4 +- ffi-convert-derive/src/utils.rs | 84 +++++++++++++------------------- ffi-convert-tests/src/lib.rs | 6 +-- ffi-convert/src/types.rs | 6 +-- 4 files changed, 42 insertions(+), 58 deletions(-) diff --git a/ffi-convert-derive/src/asrust.rs b/ffi-convert-derive/src/asrust.rs index f1891e4..a640ab8 100644 --- a/ffi-convert-derive/src/asrust.rs +++ b/ffi-convert-derive/src/asrust.rs @@ -20,12 +20,12 @@ pub fn impl_asrust_macro(input: &syn::DeriveInput) -> TokenStream { } = field; if field.levels_of_indirection > 1 && !field.is_nullable { - panic!(format!( + panic!( "The CReprOf, AsRust, and CDrop traits cannot be derived automatically: \ The field {} is a pointer field has too many levels of indirection \ ({} in this case). Please implements those traits manually.", field_name, field.levels_of_indirection - )) + ) } let mut conversion = if field.is_string { diff --git a/ffi-convert-derive/src/utils.rs b/ffi-convert-derive/src/utils.rs index 24b84fe..412f5d9 100644 --- a/ffi-convert-derive/src/utils.rs +++ b/ffi-convert-derive/src/utils.rs @@ -1,5 +1,3 @@ -use syn::parse::{Parse, ParseBuffer}; - pub fn parse_target_type(attrs: &[syn::Attribute]) -> syn::Path { let target_type_attribute = attrs .iter() @@ -28,29 +26,7 @@ pub fn parse_struct_fields(data: &syn::Data) -> Vec { } } -struct CReprOfConvertOverrideArgs { - pub convert: syn::Expr, -} - -impl<'a> Parse for CReprOfConvertOverrideArgs { - fn parse(input: &ParseBuffer) -> Result { - let convert = input.parse()?; - Ok(Self { convert }) - } -} - -struct TargetNameArgs { - pub name: syn::Ident, -} - -impl<'a> Parse for TargetNameArgs { - fn parse(input: &ParseBuffer) -> Result { - let name = input.parse()?; - Ok(Self { name }) - } -} - -#[derive(PartialEq, Debug)] +#[derive(PartialEq, Eq, Debug)] pub enum TypeArrayOrTypePath { TypeArray(syn::TypeArray), TypePath(syn::TypePath), @@ -192,7 +168,9 @@ mod tests { assert_eq!(extracted_type_param.unwrap().args.len(), 1); assert_eq!( transformed_type_path, - TypeArrayOrTypePath::TypePath(syn::parse_str::("std::mod1::mod2::Foo").unwrap()) + TypeArrayOrTypePath::TypePath( + syn::parse_str::("std::mod1::mod2::Foo").unwrap() + ) ); } @@ -205,7 +183,9 @@ mod tests { assert_eq!( transformed_type_path, - TypeArrayOrTypePath::TypePath(syn::parse_str::("std::mod1::mod2::Foo").unwrap()) + TypeArrayOrTypePath::TypePath( + syn::parse_str::("std::mod1::mod2::Foo").unwrap() + ) ); assert_eq!(extracted_type_param.unwrap().args.len(), 2) } @@ -220,7 +200,9 @@ mod tests { assert!(extracted_type_params.is_none()); assert_eq!( transformed_path, - TypeArrayOrTypePath::TypePath(syn::parse_str::("std::module1::module2::Hello").unwrap()) + TypeArrayOrTypePath::TypePath( + syn::parse_str::("std::module1::module2::Hello").unwrap() + ) ) } @@ -266,17 +248,18 @@ mod tests { assert_eq!(parsed_fields[0].is_string, false); assert_eq!(parsed_fields[1].is_string, false); - let field_type0 = if let TypeArrayOrTypePath::TypePath(type_path) = &parsed_fields[0].field_type { - type_path - } else { - panic!("unexpected type") - }; - let field_type1 = if let TypeArrayOrTypePath::TypePath(type_path) = &parsed_fields[1].field_type { - type_path - } else { - panic!("unexpected type") - }; - + let field_type0 = + if let TypeArrayOrTypePath::TypePath(type_path) = &parsed_fields[0].field_type { + type_path + } else { + panic!("unexpected type") + }; + let field_type1 = + if let TypeArrayOrTypePath::TypePath(type_path) = &parsed_fields[1].field_type { + type_path + } else { + panic!("unexpected type") + }; let parsed_path_0 = field_type0.path.clone(); let parsed_path_1 = field_type1.path.clone(); @@ -310,17 +293,18 @@ mod tests { assert_eq!(parsed_fields[0].is_string, false); assert_eq!(parsed_fields[1].is_string, false); - let field_type0 = if let TypeArrayOrTypePath::TypePath(type_path) = &parsed_fields[0].field_type { - type_path - } else { - panic!("unexpected type") - }; - let field_type1 = if let TypeArrayOrTypePath::TypePath(type_path) = &parsed_fields[1].field_type { - type_path - } else { - panic!("unexpected type") - }; - + let field_type0 = + if let TypeArrayOrTypePath::TypePath(type_path) = &parsed_fields[0].field_type { + type_path + } else { + panic!("unexpected type") + }; + let field_type1 = + if let TypeArrayOrTypePath::TypePath(type_path) = &parsed_fields[1].field_type { + type_path + } else { + panic!("unexpected type") + }; let parsed_path_0 = field_type0.path.clone(); let parsed_path_1 = field_type1.path.clone(); diff --git a/ffi-convert-tests/src/lib.rs b/ffi-convert-tests/src/lib.rs index 8547bdf..588c674 100644 --- a/ffi-convert-tests/src/lib.rs +++ b/ffi-convert-tests/src/lib.rs @@ -95,7 +95,7 @@ pub struct CSauce { volume: f32, } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct Topping { pub amount: i32, } @@ -107,7 +107,7 @@ pub struct CTopping { amount: i32, } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct Layer { pub number: i32, pub subtitle: Option, @@ -122,7 +122,7 @@ pub struct CLayer { subtitle: *const libc::c_char, } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct Dummy { pub count: i32, pub describe: String, diff --git a/ffi-convert/src/types.rs b/ffi-convert/src/types.rs index d937e13..65171b5 100644 --- a/ffi-convert/src/types.rs +++ b/ffi-convert/src/types.rs @@ -62,7 +62,7 @@ impl CReprOf> for CStringArray { impl CDrop for CStringArray { fn do_drop(&mut self) -> Result<(), CDropError> { - let _ = unsafe { + unsafe { let y = Box::from_raw(std::slice::from_raw_parts_mut( self.data as *mut *mut libc::c_char, self.size, @@ -70,7 +70,7 @@ impl CDrop for CStringArray { for p in y.iter() { let _ = CString::from_raw_pointer(*p)?; // let's not panic if we fail here } - }; + } Ok(()) } } @@ -230,7 +230,7 @@ impl RawPointerConverter> for CArray { /// assert_eq!(foo_converted, foo); /// ``` #[repr(C)] -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct CRange { pub start: T, pub end: T,