Skip to content

Commit

Permalink
remove unused apis and clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fredszaq committed Jan 18, 2023
1 parent 3e24bea commit 49825d6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 58 deletions.
4 changes: 2 additions & 2 deletions ffi-convert-derive/src/asrust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
84 changes: 34 additions & 50 deletions ffi-convert-derive/src/utils.rs
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -28,29 +26,7 @@ pub fn parse_struct_fields(data: &syn::Data) -> Vec<Field> {
}
}

struct CReprOfConvertOverrideArgs {
pub convert: syn::Expr,
}

impl<'a> Parse for CReprOfConvertOverrideArgs {
fn parse(input: &ParseBuffer) -> Result<Self, syn::parse::Error> {
let convert = input.parse()?;
Ok(Self { convert })
}
}

struct TargetNameArgs {
pub name: syn::Ident,
}

impl<'a> Parse for TargetNameArgs {
fn parse(input: &ParseBuffer) -> Result<Self, syn::parse::Error> {
let name = input.parse()?;
Ok(Self { name })
}
}

#[derive(PartialEq, Debug)]
#[derive(PartialEq, Eq, Debug)]
pub enum TypeArrayOrTypePath {
TypeArray(syn::TypeArray),
TypePath(syn::TypePath),
Expand Down Expand Up @@ -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::<TypePath>("std::mod1::mod2::Foo").unwrap())
TypeArrayOrTypePath::TypePath(
syn::parse_str::<TypePath>("std::mod1::mod2::Foo").unwrap()
)
);
}

Expand All @@ -205,7 +183,9 @@ mod tests {

assert_eq!(
transformed_type_path,
TypeArrayOrTypePath::TypePath(syn::parse_str::<TypePath>("std::mod1::mod2::Foo").unwrap())
TypeArrayOrTypePath::TypePath(
syn::parse_str::<TypePath>("std::mod1::mod2::Foo").unwrap()
)
);
assert_eq!(extracted_type_param.unwrap().args.len(), 2)
}
Expand All @@ -220,7 +200,9 @@ mod tests {
assert!(extracted_type_params.is_none());
assert_eq!(
transformed_path,
TypeArrayOrTypePath::TypePath(syn::parse_str::<TypePath>("std::module1::module2::Hello").unwrap())
TypeArrayOrTypePath::TypePath(
syn::parse_str::<TypePath>("std::module1::module2::Hello").unwrap()
)
)
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions ffi-convert-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub struct CSauce {
volume: f32,
}

#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Topping {
pub amount: i32,
}
Expand All @@ -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<String>,
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions ffi-convert/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ impl CReprOf<Vec<String>> 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,
));
for p in y.iter() {
let _ = CString::from_raw_pointer(*p)?; // let's not panic if we fail here
}
};
}
Ok(())
}
}
Expand Down Expand Up @@ -230,7 +230,7 @@ impl<T> RawPointerConverter<CArray<T>> for CArray<T> {
/// assert_eq!(foo_converted, foo);
/// ```
#[repr(C)]
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CRange<T> {
pub start: T,
pub end: T,
Expand Down

0 comments on commit 49825d6

Please sign in to comment.