Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix trivially_copy_pass_by_ref lint #3077

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions bindgen/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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()
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 ===
(DeriveTrait::Default, TypeKind::Void) |
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
Loading