aya-gen: fix clippy warnings

pull/29/head
Alessandro Decina 3 years ago
parent 0878c4505a
commit 1159741eda

@ -1,26 +1,22 @@
use bindgen::{self, Builder, EnumVariation}; use bindgen::{self, Builder, EnumVariation};
pub fn user_builder() -> Builder { pub fn user_builder() -> Builder {
let bindgen = bindgen::builder() bindgen::builder()
.layout_tests(false) .layout_tests(false)
.generate_comments(false) .generate_comments(false)
.prepend_enum_name(false) .prepend_enum_name(false)
.default_enum_style(EnumVariation::Rust { .default_enum_style(EnumVariation::Rust {
non_exhaustive: false, non_exhaustive: false,
}); })
bindgen
} }
pub fn bpf_builder() -> Builder { pub fn bpf_builder() -> Builder {
let bindgen = bindgen::builder() bindgen::builder()
.use_core() .use_core()
.ctypes_prefix("::aya_bpf_cty") .ctypes_prefix("::aya_bpf_cty")
.layout_tests(false) .layout_tests(false)
.generate_comments(false) .generate_comments(false)
.clang_arg("-Wno-unknown-attributes") .clang_arg("-Wno-unknown-attributes")
.default_enum_style(EnumVariation::ModuleConsts) .default_enum_style(EnumVariation::ModuleConsts)
.prepend_enum_name(false); .prepend_enum_name(false)
bindgen
} }

@ -46,8 +46,7 @@ pub fn generate<T: AsRef<str>>(
let bpf_probe_read = syn::parse_str::<syn::Path>("::aya_bpf::helpers::bpf_probe_read").unwrap(); let bpf_probe_read = syn::parse_str::<syn::Path>("::aya_bpf::helpers::bpf_probe_read").unwrap();
let getters = let getters =
generate_getters_for_items(&tree.items, |getter| read_getter(getter, &bpf_probe_read)); generate_getters_for_items(&tree.items, |getter| read_getter(getter, &bpf_probe_read));
let getters = let getters = rustfmt::format(&getters.to_string()).map_err(Error::Rustfmt)?;
rustfmt::format(&getters.to_string()).map_err(|io_error| Error::Rustfmt(io_error))?;
let bindings = format!("{}\n{}", bindings, getters); let bindings = format!("{}\n{}", bindings, getters);
@ -60,7 +59,7 @@ fn c_header_from_btf(path: &Path) -> Result<String, Error> {
.arg(path) .arg(path)
.args(&["format", "c"]) .args(&["format", "c"])
.output() .output()
.map_err(|io_error| Error::BpfTool(io_error))?; .map_err(Error::BpfTool)?;
if !output.status.success() { if !output.status.success() {
return Err(Error::BpfToolExit { return Err(Error::BpfToolExit {

@ -60,7 +60,7 @@ impl<'a> GetterList<'a> {
let sub_fields = self let sub_fields = self
.item_fields .item_fields
.get(field_ty_ident) .get(field_ty_ident)
.expect(&field_ty_ident.to_string()) .unwrap_or_else(|| panic!("{}", field_ty_ident.to_string()))
.1; .1;
getters.extend(self.getters(field_ident, sub_fields).drain(..).map( getters.extend(self.getters(field_ident, sub_fields).drain(..).map(
|mut getter| { |mut getter| {
@ -86,7 +86,7 @@ pub fn generate_getters_for_items(
gen_getter: impl Fn(&Getter<'_>) -> TokenStream, gen_getter: impl Fn(&Getter<'_>) -> TokenStream,
) -> TokenStream { ) -> TokenStream {
let mut tokens = TokenStream::new(); let mut tokens = TokenStream::new();
tokens.append_all(GetterList::new(&items).iter().map(|(item, getters)| { tokens.append_all(GetterList::new(items).iter().map(|(item, getters)| {
let getters = getters.iter().map(&gen_getter); let getters = getters.iter().map(&gen_getter);
let (ident, generics, _) = unpack_item(item).unwrap(); let (ident, generics, _) = unpack_item(item).unwrap();
quote! { quote! {

Loading…
Cancel
Save