Skip to content

Commit

Permalink
Fix trivially_copy_pass_by_ref lint
Browse files Browse the repository at this point in the history
  • Loading branch information
nyurik authored and emilio committed Jan 9, 2025
1 parent c69b7cd commit 191a97f
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 30 deletions.
12 changes: 6 additions & 6 deletions bindgen/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3188,14 +3188,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)
}
}

Expand Down Expand Up @@ -5701,7 +5701,7 @@ pub(crate) mod utils {

pub(crate) fn fnsig_argument_type(
ctx: &BindgenContext,
ty: &TypeId,
ty: TypeId,
) -> syn::Type {
use super::ToPtr;

Expand Down Expand Up @@ -5753,7 +5753,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()
Expand Down
32 changes: 16 additions & 16 deletions bindgen/ir/analysis/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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| {
Expand All @@ -489,31 +489,31 @@ 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 {
matches!(self, DeriveTrait::Copy)
}
}

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 |
Expand All @@ -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}");
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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 ===
(
Expand Down
8 changes: 4 additions & 4 deletions bindgen/ir/comp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions bindgen/ir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ impl From<ItemId> 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()
}
}

Expand Down
4 changes: 2 additions & 2 deletions bindgen/ir/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(..))
}
}

Expand Down
1 change: 1 addition & 0 deletions bindgen/ir/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ impl DebugOnlyItemSet {
DebugOnlyItemSet
}

#[allow(clippy::trivially_copy_pass_by_ref)]
fn contains(&self, _id: &ItemId) -> bool {
false
}
Expand Down

0 comments on commit 191a97f

Please sign in to comment.