From 1159741edae71a2b3a94929fbbe8321b59515946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alessandro=C2=A0Decina?= Date: Sun, 4 Jul 2021 01:03:18 +0000 Subject: [PATCH] aya-gen: fix clippy warnings --- aya-gen/src/bindgen.rs | 12 ++++-------- aya-gen/src/btf_types.rs | 5 ++--- aya-gen/src/getters.rs | 4 ++-- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/aya-gen/src/bindgen.rs b/aya-gen/src/bindgen.rs index 0f6ba8ec..137c25e0 100644 --- a/aya-gen/src/bindgen.rs +++ b/aya-gen/src/bindgen.rs @@ -1,26 +1,22 @@ use bindgen::{self, Builder, EnumVariation}; pub fn user_builder() -> Builder { - let bindgen = bindgen::builder() + bindgen::builder() .layout_tests(false) .generate_comments(false) .prepend_enum_name(false) .default_enum_style(EnumVariation::Rust { non_exhaustive: false, - }); - - bindgen + }) } pub fn bpf_builder() -> Builder { - let bindgen = bindgen::builder() + bindgen::builder() .use_core() .ctypes_prefix("::aya_bpf_cty") .layout_tests(false) .generate_comments(false) .clang_arg("-Wno-unknown-attributes") .default_enum_style(EnumVariation::ModuleConsts) - .prepend_enum_name(false); - - bindgen + .prepend_enum_name(false) } diff --git a/aya-gen/src/btf_types.rs b/aya-gen/src/btf_types.rs index 5387ef40..e5ece897 100644 --- a/aya-gen/src/btf_types.rs +++ b/aya-gen/src/btf_types.rs @@ -46,8 +46,7 @@ pub fn generate>( let bpf_probe_read = syn::parse_str::("::aya_bpf::helpers::bpf_probe_read").unwrap(); let getters = generate_getters_for_items(&tree.items, |getter| read_getter(getter, &bpf_probe_read)); - let getters = - rustfmt::format(&getters.to_string()).map_err(|io_error| Error::Rustfmt(io_error))?; + let getters = rustfmt::format(&getters.to_string()).map_err(Error::Rustfmt)?; let bindings = format!("{}\n{}", bindings, getters); @@ -60,7 +59,7 @@ fn c_header_from_btf(path: &Path) -> Result { .arg(path) .args(&["format", "c"]) .output() - .map_err(|io_error| Error::BpfTool(io_error))?; + .map_err(Error::BpfTool)?; if !output.status.success() { return Err(Error::BpfToolExit { diff --git a/aya-gen/src/getters.rs b/aya-gen/src/getters.rs index 4436e25a..8e0b45d8 100644 --- a/aya-gen/src/getters.rs +++ b/aya-gen/src/getters.rs @@ -60,7 +60,7 @@ impl<'a> GetterList<'a> { let sub_fields = self .item_fields .get(field_ty_ident) - .expect(&field_ty_ident.to_string()) + .unwrap_or_else(|| panic!("{}", field_ty_ident.to_string())) .1; getters.extend(self.getters(field_ident, sub_fields).drain(..).map( |mut getter| { @@ -86,7 +86,7 @@ pub fn generate_getters_for_items( gen_getter: impl Fn(&Getter<'_>) -> TokenStream, ) -> TokenStream { 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 (ident, generics, _) = unpack_item(item).unwrap(); quote! {