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};
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)
}

@ -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 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<String, Error> {
.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 {

@ -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! {

Loading…
Cancel
Save