From 5f796f1aa4d211dca5a6cbc4b84ce581137912a8 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Wed, 8 Jan 2025 23:19:19 -0500 Subject: [PATCH] Fix `trivially_copy_pass_by_ref` lint --- Cargo.toml | 1 - bindgen/codegen/mod.rs | 12 ++++++------ bindgen/ir/analysis/derive.rs | 32 ++++++++++++++++---------------- bindgen/ir/comp.rs | 8 ++++---- bindgen/ir/context.rs | 4 ++-- bindgen/ir/function.rs | 4 ++-- bindgen/ir/item.rs | 1 + 7 files changed, 31 insertions(+), 31 deletions(-) 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/codegen/mod.rs b/bindgen/codegen/mod.rs index cf819950db..e081fd9569 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -3187,14 +3187,14 @@ pub enum EnumVariation { } impl EnumVariation { - fn is_rust(&self) -> bool { - matches!(*self, EnumVariation::Rust { .. }) + fn is_rust(self) -> bool { + matches!(self, EnumVariation::Rust { .. }) } /// Both the `Const` and `ModuleConsts` variants will cause this to return /// true. - fn is_const(&self) -> bool { - matches!(*self, EnumVariation::Consts | EnumVariation::ModuleConsts) + fn is_const(self) -> bool { + matches!(self, EnumVariation::Consts | EnumVariation::ModuleConsts) } } @@ -5700,7 +5700,7 @@ pub(crate) mod utils { pub(crate) fn fnsig_argument_type( ctx: &BindgenContext, - ty: &TypeId, + ty: TypeId, ) -> syn::Type { use super::ToPtr; @@ -5752,7 +5752,7 @@ pub(crate) mod utils { let mut unnamed_arguments = 0; let mut args = args_iter .map(|(name, ty)| { - let arg_ty = fnsig_argument_type(ctx, ty); + let arg_ty = fnsig_argument_type(ctx, *ty); let arg_name = if let Some(ref name) = *name { ctx.rust_mangle(name).into_owned() diff --git a/bindgen/ir/analysis/derive.rs b/bindgen/ir/analysis/derive.rs index 1643a91461..4b52653d2f 100644 --- a/bindgen/ir/analysis/derive.rs +++ b/bindgen/ir/analysis/derive.rs @@ -451,7 +451,7 @@ impl CannotDerive<'_> { } impl DeriveTrait { - fn not_by_name(&self, ctx: &BindgenContext, item: &Item) -> bool { + fn not_by_name(self, ctx: &BindgenContext, item: &Item) -> bool { match self { DeriveTrait::Copy => ctx.no_copy_by_name(item), DeriveTrait::Debug => ctx.no_debug_by_name(item), @@ -463,21 +463,21 @@ impl DeriveTrait { } } - fn consider_edge_comp(&self) -> EdgePredicate { + fn consider_edge_comp(self) -> EdgePredicate { match self { DeriveTrait::PartialEqOrPartialOrd => consider_edge_default, _ => |kind| matches!(kind, EdgeKind::BaseMember | EdgeKind::Field), } } - fn consider_edge_typeref(&self) -> EdgePredicate { + fn consider_edge_typeref(self) -> EdgePredicate { match self { DeriveTrait::PartialEqOrPartialOrd => consider_edge_default, _ => |kind| kind == EdgeKind::TypeReference, } } - fn consider_edge_tmpl_inst(&self) -> EdgePredicate { + fn consider_edge_tmpl_inst(self) -> EdgePredicate { match self { DeriveTrait::PartialEqOrPartialOrd => consider_edge_default, _ => |kind| { @@ -489,7 +489,7 @@ impl DeriveTrait { } } - fn can_derive_large_array(&self, ctx: &BindgenContext) -> bool { + fn can_derive_large_array(self, ctx: &BindgenContext) -> bool { if ctx.options().rust_features().larger_arrays { !matches!(self, DeriveTrait::Default) } else { @@ -497,23 +497,23 @@ impl DeriveTrait { } } - fn can_derive_union(&self) -> bool { + fn can_derive_union(self) -> bool { matches!(self, DeriveTrait::Copy) } - fn can_derive_compound_with_destructor(&self) -> bool { + fn can_derive_compound_with_destructor(self) -> bool { !matches!(self, DeriveTrait::Copy) } - fn can_derive_compound_with_vtable(&self) -> bool { + fn can_derive_compound_with_vtable(self) -> bool { !matches!(self, DeriveTrait::Default) } - fn can_derive_compound_forward_decl(&self) -> bool { + fn can_derive_compound_forward_decl(self) -> bool { matches!(self, DeriveTrait::Copy | DeriveTrait::Debug) } - fn can_derive_incomplete_array(&self) -> bool { + fn can_derive_incomplete_array(self) -> bool { !matches!( self, DeriveTrait::Copy | @@ -522,7 +522,7 @@ impl DeriveTrait { ) } - fn can_derive_fnptr(&self, f: &FunctionSig) -> CanDerive { + fn can_derive_fnptr(self, f: &FunctionSig) -> CanDerive { match (self, f.function_pointers_can_derive()) { (DeriveTrait::Copy, _) | (DeriveTrait::Default, _) | (_, true) => { trace!(" function pointer can derive {self}"); @@ -539,8 +539,8 @@ impl DeriveTrait { } } - fn can_derive_vector(&self) -> CanDerive { - if *self == DeriveTrait::PartialEqOrPartialOrd { + fn can_derive_vector(self) -> CanDerive { + if self == DeriveTrait::PartialEqOrPartialOrd { // FIXME: vectors always can derive PartialEq, but they should // not derive PartialOrd: // https://github.com/rust-lang-nursery/packed_simd/issues/48 @@ -552,8 +552,8 @@ impl DeriveTrait { } } - fn can_derive_pointer(&self) -> CanDerive { - if *self == DeriveTrait::Default { + fn can_derive_pointer(self) -> CanDerive { + if self == DeriveTrait::Default { trace!(" pointer cannot derive Default"); CanDerive::No } else { @@ -562,7 +562,7 @@ impl DeriveTrait { } } - fn can_derive_simple(&self, kind: &TypeKind) -> CanDerive { + fn can_derive_simple(self, kind: &TypeKind) -> CanDerive { match (self, kind) { // === Default === (DeriveTrait::Default, TypeKind::Void) | diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index 1dd074ba4d..15f9cb4655 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -56,16 +56,16 @@ pub(crate) enum MethodKind { impl MethodKind { /// Is this a destructor method? - pub(crate) fn is_destructor(&self) -> bool { + pub(crate) fn is_destructor(self) -> bool { matches!( - *self, + self, MethodKind::Destructor | MethodKind::VirtualDestructor { .. } ) } /// Is this a pure virtual method? - pub(crate) fn is_pure_virtual(&self) -> bool { - match *self { + pub(crate) fn is_pure_virtual(self) -> bool { + match self { MethodKind::Virtual { pure_virtual } | MethodKind::VirtualDestructor { pure_virtual } => pure_virtual, _ => false, diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 098dd25e59..6b47560e8c 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -198,8 +198,8 @@ impl From for usize { impl ItemId { /// Get a numeric representation of this ID. - pub(crate) fn as_usize(&self) -> usize { - (*self).into() + pub(crate) fn as_usize(self) -> usize { + self.into() } } diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index 2474ea839a..f5c06eccc8 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -247,8 +247,8 @@ pub(crate) enum ClangAbi { impl ClangAbi { /// Returns whether this Abi is known or not. - fn is_unknown(&self) -> bool { - matches!(*self, ClangAbi::Unknown(..)) + fn is_unknown(self) -> bool { + matches!(self, ClangAbi::Unknown(..)) } } diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index b131455849..1ba47442d4 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -103,6 +103,7 @@ impl DebugOnlyItemSet { DebugOnlyItemSet } + #[allow(clippy::trivially_copy_pass_by_ref)] fn contains(&self, _id: &ItemId) -> bool { false }