diff --git a/Cargo.toml b/Cargo.toml index 248c041378..691294df44 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -87,7 +87,6 @@ wildcard_imports = "allow" borrow_as_ptr = "allow" match_same_arms = "allow" trivially_copy_pass_by_ref = "allow" -needless_pass_by_value = "allow" unused_self = "allow" # Theese seem to be ok to ignore for now diff --git a/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs b/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs index b48d2d7c19..74af110d00 100644 --- a/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs +++ b/bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs @@ -76,10 +76,10 @@ pub fn test_item_discovery_callback() { ), ]); - compare_item_caches(info.borrow().clone(), expected); + compare_item_caches(&info.borrow(), &expected); } -pub fn compare_item_caches(generated: ItemCache, expected: ItemCache) { +pub fn compare_item_caches(generated: &ItemCache, expected: &ItemCache) { // We can't use a simple Eq::eq comparison because of two reasons: // - anonymous structs/unions will have a final name generated by bindgen which may change // if the header file or the bindgen logic is altered @@ -89,8 +89,8 @@ pub fn compare_item_caches(generated: ItemCache, expected: ItemCache) { compare_item_info( expected_item, generated_item, - &expected, - &generated, + expected, + generated, ) }); diff --git a/bindgen-tests/tests/quickchecking/src/lib.rs b/bindgen-tests/tests/quickchecking/src/lib.rs index 2f0b575c3f..7567a3bea6 100644 --- a/bindgen-tests/tests/quickchecking/src/lib.rs +++ b/bindgen-tests/tests/quickchecking/src/lib.rs @@ -37,7 +37,7 @@ static CONTEXT: Mutex = Mutex::new(Context { output_path: None }); // Passes fuzzed header to the `csmith-fuzzing/predicate.py` script, returns // output of the associated command. fn run_predicate_script( - header: fuzzers::HeaderC, + header: &fuzzers::HeaderC, ) -> Result> { let dir = Builder::new().prefix("bindgen_prop").tempdir()?; let header_path = dir.path().join("prop_test.h"); @@ -77,8 +77,9 @@ fn run_predicate_script( // Generatable property. Pass generated headers off to run through the // `csmith-fuzzing/predicate.py` script. Success is measured by the success // status of that command. +#[allow(clippy::needless_pass_by_value)] fn bindgen_prop(header: fuzzers::HeaderC) -> TestResult { - match run_predicate_script(header) { + match run_predicate_script(&header) { Ok(o) => TestResult::from_bool(o.status.success()), Err(e) => { println!("{e:?}"); diff --git a/bindgen/codegen/dyngen.rs b/bindgen/codegen/dyngen.rs index 6bdea51eff..410cc0d6cb 100644 --- a/bindgen/codegen/dyngen.rs +++ b/bindgen/codegen/dyngen.rs @@ -75,7 +75,7 @@ impl DynamicItems { pub(crate) fn get_tokens( &self, - lib_ident: Ident, + lib_ident: &Ident, ctx: &BindgenContext, ) -> TokenStream { let struct_members = &self.struct_members; @@ -130,15 +130,15 @@ impl DynamicItems { #[allow(clippy::too_many_arguments)] pub(crate) fn push_func( &mut self, - ident: Ident, + ident: &Ident, abi: ClangAbi, is_variadic: bool, is_required: bool, - args: Vec, - args_identifiers: Vec, - ret: TokenStream, - ret_ty: TokenStream, - attributes: Vec, + args: &[TokenStream], + args_identifiers: &[TokenStream], + ret: &TokenStream, + ret_ty: &TokenStream, + attributes: &[TokenStream], ctx: &BindgenContext, ) { if !is_variadic { @@ -205,8 +205,8 @@ impl DynamicItems { pub fn push_var( &mut self, - ident: Ident, - ty: TokenStream, + ident: &Ident, + ty: &TokenStream, is_required: bool, wrap_unsafe_ops: bool, ) { diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index 812b6b6458..7b09ed7cfb 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -52,7 +52,7 @@ pub(crate) mod attributes { } } - pub(crate) fn doc(comment: String) -> TokenStream { + pub(crate) fn doc(comment: &str) -> TokenStream { if comment.is_empty() { quote!() } else { diff --git a/bindgen/codegen/impl_debug.rs b/bindgen/codegen/impl_debug.rs index 319c89b58e..058a73bd13 100644 --- a/bindgen/codegen/impl_debug.rs +++ b/bindgen/codegen/impl_debug.rs @@ -130,7 +130,7 @@ impl<'a> ImplDebug<'a> for Item { fn debug_print( name: &str, - name_ident: proc_macro2::TokenStream, + name_ident: &proc_macro2::TokenStream, ) -> Option<(String, Vec)> { Some(( format!("{name}: {{:?}}"), @@ -154,13 +154,13 @@ impl<'a> ImplDebug<'a> for Item { TypeKind::ObjCInterface(..) | TypeKind::ObjCId | TypeKind::Comp(..) | - TypeKind::ObjCSel => debug_print(name, quote! { #name_ident }), + TypeKind::ObjCSel => debug_print(name, "e! { #name_ident }), TypeKind::TemplateInstantiation(ref inst) => { if inst.is_opaque(ctx, self) { Some((format!("{name}: opaque"), vec![])) } else { - debug_print(name, quote! { #name_ident }) + debug_print(name, "e! { #name_ident }) } } @@ -177,7 +177,7 @@ impl<'a> ImplDebug<'a> for Item { ctx.options().rust_features().larger_arrays { // The simple case - debug_print(name, quote! { #name_ident }) + debug_print(name, "e! { #name_ident }) } else if ctx.options().use_core { // There is no String in core; reducing field visibility to avoid breaking // no_std setups. @@ -233,7 +233,7 @@ impl<'a> ImplDebug<'a> for Item { { Some((format!("{name}: FunctionPointer"), vec![])) } - _ => debug_print(name, quote! { #name_ident }), + _ => debug_print(name, "e! { #name_ident }), } } diff --git a/bindgen/codegen/impl_partialeq.rs b/bindgen/codegen/impl_partialeq.rs index 6c7b43959b..c2787967d8 100644 --- a/bindgen/codegen/impl_partialeq.rs +++ b/bindgen/codegen/impl_partialeq.rs @@ -76,7 +76,7 @@ fn gen_field( name: &str, ) -> proc_macro2::TokenStream { fn quote_equals( - name_ident: proc_macro2::Ident, + name_ident: &proc_macro2::Ident, ) -> proc_macro2::TokenStream { quote! { self.#name_ident == other.#name_ident } } @@ -100,7 +100,7 @@ fn gen_field( TypeKind::Comp(..) | TypeKind::Pointer(_) | TypeKind::Function(..) | - TypeKind::Opaque => quote_equals(name_ident), + TypeKind::Opaque => quote_equals(&name_ident), TypeKind::TemplateInstantiation(ref inst) => { if inst.is_opaque(ctx, ty_item) { @@ -108,7 +108,7 @@ fn gen_field( &self. #name_ident [..] == &other. #name_ident [..] } } else { - quote_equals(name_ident) + quote_equals(&name_ident) } } @@ -116,7 +116,7 @@ fn gen_field( if len <= RUST_DERIVE_IN_ARRAY_LIMIT || ctx.options().rust_features().larger_arrays { - quote_equals(name_ident) + quote_equals(&name_ident) } else { quote! { &self. #name_ident [..] == &other. #name_ident [..] diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index cf819950db..2d7e9383c0 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -677,7 +677,7 @@ impl CodeGenerator for Var { let mut attrs = vec![]; if let Some(comment) = item.comment(ctx) { - attrs.push(attributes::doc(comment)); + attrs.push(attributes::doc(&comment)); } let var_ty = self.ty(); @@ -815,8 +815,9 @@ impl CodeGenerator for Var { if ctx.options().dynamic_library_name.is_some() { result.dynamic_items().push_var( - canonical_ident, - self.ty() + &canonical_ident, + &self + .ty() .to_rust_ty_or_opaque(ctx, &()) .into_token_stream(), ctx.options().dynamic_link_require_all, @@ -886,7 +887,7 @@ impl CodeGenerator for Type { let rust_name = ctx.rust_ident(name); let mut tokens = if let Some(comment) = item.comment(ctx) { - attributes::doc(comment) + attributes::doc(&comment) } else { quote! {} }; @@ -1006,7 +1007,7 @@ impl CodeGenerator for Type { }); let mut tokens = if let Some(comment) = item.comment(ctx) { - attributes::doc(comment) + attributes::doc(&comment) } else { quote! {} }; @@ -1532,7 +1533,7 @@ impl FieldCodegen<'_> for FieldData { if ctx.options().generate_comments { if let Some(raw_comment) = self.comment() { let comment = ctx.options().process_comment(raw_comment); - field = attributes::doc(comment); + field = attributes::doc(&comment); } } @@ -1654,7 +1655,7 @@ impl Bitfield { fn extend_ctor_impl( &self, ctx: &BindgenContext, - param_name: proc_macro2::TokenStream, + param_name: &proc_macro2::TokenStream, mut ctor_impl: proc_macro2::TokenStream, ) -> proc_macro2::TokenStream { let bitfield_ty = ctx.resolve_type(self.ty()); @@ -1857,7 +1858,7 @@ impl FieldCodegen<'_> for BitfieldUnit { ctor_params.push(quote! { #param_name : #bitfield_ty }); - ctor_impl = bf.extend_ctor_impl(ctx, param_name, ctor_impl); + ctor_impl = bf.extend_ctor_impl(ctx, ¶m_name, ctor_impl); } let access_spec = access_specifier(unit_visibility); @@ -2409,7 +2410,7 @@ impl CodeGenerator for CompInfo { let mut needs_partialeq_impl = false; let needs_flexarray_impl = flex_array_generic.is_some(); if let Some(comment) = item.comment(ctx) { - attributes.push(attributes::doc(comment)); + attributes.push(attributes::doc(&comment)); } // if a type has both a "packed" attribute and an "align(N)" attribute, then check if the @@ -2764,7 +2765,7 @@ impl CodeGenerator for CompInfo { result.push(self.generate_flexarray( ctx, &canonical_ident, - flex_inner_ty, + flex_inner_ty.as_ref(), &generic_param_names, &impl_generics_labels, )); @@ -2859,7 +2860,7 @@ impl CompInfo { &self, ctx: &BindgenContext, canonical_ident: &Ident, - flex_inner_ty: Option, + flex_inner_ty: Option<&proc_macro2::TokenStream>, generic_param_names: &[Ident], impl_generics_labels: &proc_macro2::TokenStream, ) -> proc_macro2::TokenStream { @@ -3299,7 +3300,7 @@ impl<'a> EnumBuilder<'a> { fn new( name: &'a str, mut attrs: Vec, - repr: syn::Type, + repr: &syn::Type, enum_variation: EnumVariation, has_typedef: bool, ) -> Self { @@ -3368,7 +3369,7 @@ impl<'a> EnumBuilder<'a> { ctx: &BindgenContext, variant: &EnumVariant, mangling_prefix: Option<&str>, - rust_ty: syn::Type, + rust_ty: &syn::Type, result: &mut CodegenResult<'_>, is_ty_named: bool, ) -> Self { @@ -3387,7 +3388,7 @@ impl<'a> EnumBuilder<'a> { if ctx.options().generate_comments { if let Some(raw_comment) = variant.comment() { let comment = ctx.options().process_comment(raw_comment); - doc = attributes::doc(comment); + doc = attributes::doc(&comment); } } @@ -3480,7 +3481,7 @@ impl<'a> EnumBuilder<'a> { fn build( self, ctx: &BindgenContext, - rust_ty: syn::Type, + rust_ty: &syn::Type, result: &mut CodegenResult<'_>, ) -> proc_macro2::TokenStream { match self { @@ -3679,7 +3680,7 @@ impl CodeGenerator for Enum { }; if let Some(comment) = item.comment(ctx) { - attrs.push(attributes::doc(comment)); + attrs.push(attributes::doc(&comment)); } if item.must_use(ctx) { @@ -3746,7 +3747,7 @@ impl CodeGenerator for Enum { // value. variant_name: &Ident, referenced_name: &Ident, - enum_rust_ty: syn::Type, + enum_rust_ty: &syn::Type, result: &mut CodegenResult<'_>, ) { let constant_name = if enum_.name().is_some() { @@ -3770,7 +3771,7 @@ impl CodeGenerator for Enum { let has_typedef = ctx.is_enum_typedef_combo(item.id()); let mut builder = - EnumBuilder::new(&name, attrs, repr, variation, has_typedef); + EnumBuilder::new(&name, attrs, &repr, variation, has_typedef); // A map where we keep a value -> variant relation. let mut seen_values = HashMap::<_, Ident>::default(); @@ -3846,7 +3847,7 @@ impl CodeGenerator for Enum { &ident, &Ident::new(&mangled_name, Span::call_site()), existing_variant_name, - enum_rust_ty.clone(), + &enum_rust_ty, result, ); } @@ -3855,7 +3856,7 @@ impl CodeGenerator for Enum { ctx, variant, constant_mangling_prefix, - enum_rust_ty.clone(), + &enum_rust_ty, result, enum_ty.name().is_some(), ); @@ -3866,7 +3867,7 @@ impl CodeGenerator for Enum { ctx, variant, constant_mangling_prefix, - enum_rust_ty.clone(), + &enum_rust_ty, result, enum_ty.name().is_some(), ); @@ -3897,7 +3898,7 @@ impl CodeGenerator for Enum { &ident, &mangled_name, &variant_name, - enum_rust_ty.clone(), + &enum_rust_ty, result, ); } @@ -3907,7 +3908,7 @@ impl CodeGenerator for Enum { } } - let item = builder.build(ctx, enum_rust_ty, result); + let item = builder.build(ctx, &enum_rust_ty, result); result.push(item); } } @@ -4609,7 +4610,7 @@ impl CodeGenerator for Function { } if let Some(comment) = item.comment(ctx) { - attributes.push(attributes::doc(comment)); + attributes.push(attributes::doc(&comment)); } let abi = match signature.abi(ctx, Some(name)) { @@ -4738,15 +4739,15 @@ impl CodeGenerator for Function { utils::fnsig_argument_identifiers(ctx, signature); let ret_ty = utils::fnsig_return_ty(ctx, signature); result.dynamic_items().push_func( - ident, + &ident, abi, signature.is_variadic(), ctx.options().dynamic_link_require_all, - args, - args_identifiers, - ret, - ret_ty, - attributes, + &args, + &args_identifiers, + &ret, + &ret_ty, + &attributes, ctx, ); } else { @@ -5160,7 +5161,7 @@ pub(crate) fn codegen( if let Some(ref lib_name) = context.options().dynamic_library_name { let lib_ident = context.rust_ident(lib_name); let dynamic_items_tokens = - result.dynamic_items().get_tokens(lib_ident, context); + result.dynamic_items().get_tokens(&lib_ident, context); result.push(dynamic_items_tokens); } diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 9e22e37ce6..2431be673e 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -363,7 +363,7 @@ impl Builder { }) .collect::>(); - Bindings::generate(self.options, input_unsaved_files) + Bindings::generate(self.options, &input_unsaved_files) } /// Preprocess and dump the input header files to disk. @@ -729,7 +729,7 @@ impl Bindings { /// Generate bindings for the given options. pub(crate) fn generate( mut options: BindgenOptions, - input_unsaved_files: Vec, + input_unsaved_files: &[clang::UnsavedFile], ) -> Result { ensure_libclang_is_loaded(); @@ -886,7 +886,7 @@ impl Bindings { debug!("Fixed-up options: {options:?}"); let time_phases = options.time_phases; - let mut context = BindgenContext::new(options, &input_unsaved_files); + let mut context = BindgenContext::new(options, input_unsaved_files); if is_host_build { debug_assert_eq!(