Skip to content

Commit 493fba9

Browse files
nyurikemilio
authored andcommitted
Fix trivially_copy_pass_by_ref lint
1 parent c704b14 commit 493fba9

File tree

6 files changed

+31
-30
lines changed

6 files changed

+31
-30
lines changed

bindgen/codegen/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -3188,14 +3188,14 @@ pub enum EnumVariation {
31883188
}
31893189

31903190
impl EnumVariation {
3191-
fn is_rust(&self) -> bool {
3192-
matches!(*self, EnumVariation::Rust { .. })
3191+
fn is_rust(self) -> bool {
3192+
matches!(self, EnumVariation::Rust { .. })
31933193
}
31943194

31953195
/// Both the `Const` and `ModuleConsts` variants will cause this to return
31963196
/// true.
3197-
fn is_const(&self) -> bool {
3198-
matches!(*self, EnumVariation::Consts | EnumVariation::ModuleConsts)
3197+
fn is_const(self) -> bool {
3198+
matches!(self, EnumVariation::Consts | EnumVariation::ModuleConsts)
31993199
}
32003200
}
32013201

@@ -5701,7 +5701,7 @@ pub(crate) mod utils {
57015701

57025702
pub(crate) fn fnsig_argument_type(
57035703
ctx: &BindgenContext,
5704-
ty: &TypeId,
5704+
ty: TypeId,
57055705
) -> syn::Type {
57065706
use super::ToPtr;
57075707

@@ -5753,7 +5753,7 @@ pub(crate) mod utils {
57535753
let mut unnamed_arguments = 0;
57545754
let mut args = args_iter
57555755
.map(|(name, ty)| {
5756-
let arg_ty = fnsig_argument_type(ctx, ty);
5756+
let arg_ty = fnsig_argument_type(ctx, *ty);
57575757

57585758
let arg_name = if let Some(ref name) = *name {
57595759
ctx.rust_mangle(name).into_owned()

bindgen/ir/analysis/derive.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ impl CannotDerive<'_> {
451451
}
452452

453453
impl DeriveTrait {
454-
fn not_by_name(&self, ctx: &BindgenContext, item: &Item) -> bool {
454+
fn not_by_name(self, ctx: &BindgenContext, item: &Item) -> bool {
455455
match self {
456456
DeriveTrait::Copy => ctx.no_copy_by_name(item),
457457
DeriveTrait::Debug => ctx.no_debug_by_name(item),
@@ -463,21 +463,21 @@ impl DeriveTrait {
463463
}
464464
}
465465

466-
fn consider_edge_comp(&self) -> EdgePredicate {
466+
fn consider_edge_comp(self) -> EdgePredicate {
467467
match self {
468468
DeriveTrait::PartialEqOrPartialOrd => consider_edge_default,
469469
_ => |kind| matches!(kind, EdgeKind::BaseMember | EdgeKind::Field),
470470
}
471471
}
472472

473-
fn consider_edge_typeref(&self) -> EdgePredicate {
473+
fn consider_edge_typeref(self) -> EdgePredicate {
474474
match self {
475475
DeriveTrait::PartialEqOrPartialOrd => consider_edge_default,
476476
_ => |kind| kind == EdgeKind::TypeReference,
477477
}
478478
}
479479

480-
fn consider_edge_tmpl_inst(&self) -> EdgePredicate {
480+
fn consider_edge_tmpl_inst(self) -> EdgePredicate {
481481
match self {
482482
DeriveTrait::PartialEqOrPartialOrd => consider_edge_default,
483483
_ => |kind| {
@@ -489,31 +489,31 @@ impl DeriveTrait {
489489
}
490490
}
491491

492-
fn can_derive_large_array(&self, ctx: &BindgenContext) -> bool {
492+
fn can_derive_large_array(self, ctx: &BindgenContext) -> bool {
493493
if ctx.options().rust_features().larger_arrays {
494494
!matches!(self, DeriveTrait::Default)
495495
} else {
496496
matches!(self, DeriveTrait::Copy)
497497
}
498498
}
499499

500-
fn can_derive_union(&self) -> bool {
500+
fn can_derive_union(self) -> bool {
501501
matches!(self, DeriveTrait::Copy)
502502
}
503503

504-
fn can_derive_compound_with_destructor(&self) -> bool {
504+
fn can_derive_compound_with_destructor(self) -> bool {
505505
!matches!(self, DeriveTrait::Copy)
506506
}
507507

508-
fn can_derive_compound_with_vtable(&self) -> bool {
508+
fn can_derive_compound_with_vtable(self) -> bool {
509509
!matches!(self, DeriveTrait::Default)
510510
}
511511

512-
fn can_derive_compound_forward_decl(&self) -> bool {
512+
fn can_derive_compound_forward_decl(self) -> bool {
513513
matches!(self, DeriveTrait::Copy | DeriveTrait::Debug)
514514
}
515515

516-
fn can_derive_incomplete_array(&self) -> bool {
516+
fn can_derive_incomplete_array(self) -> bool {
517517
!matches!(
518518
self,
519519
DeriveTrait::Copy |
@@ -522,7 +522,7 @@ impl DeriveTrait {
522522
)
523523
}
524524

525-
fn can_derive_fnptr(&self, f: &FunctionSig) -> CanDerive {
525+
fn can_derive_fnptr(self, f: &FunctionSig) -> CanDerive {
526526
match (self, f.function_pointers_can_derive()) {
527527
(DeriveTrait::Copy | DeriveTrait::Default, _) | (_, true) => {
528528
trace!(" function pointer can derive {self}");
@@ -539,8 +539,8 @@ impl DeriveTrait {
539539
}
540540
}
541541

542-
fn can_derive_vector(&self) -> CanDerive {
543-
if *self == DeriveTrait::PartialEqOrPartialOrd {
542+
fn can_derive_vector(self) -> CanDerive {
543+
if self == DeriveTrait::PartialEqOrPartialOrd {
544544
// FIXME: vectors always can derive PartialEq, but they should
545545
// not derive PartialOrd:
546546
// https://github.com/rust-lang-nursery/packed_simd/issues/48
@@ -552,8 +552,8 @@ impl DeriveTrait {
552552
}
553553
}
554554

555-
fn can_derive_pointer(&self) -> CanDerive {
556-
if *self == DeriveTrait::Default {
555+
fn can_derive_pointer(self) -> CanDerive {
556+
if self == DeriveTrait::Default {
557557
trace!(" pointer cannot derive Default");
558558
CanDerive::No
559559
} else {
@@ -562,7 +562,7 @@ impl DeriveTrait {
562562
}
563563
}
564564

565-
fn can_derive_simple(&self, kind: &TypeKind) -> CanDerive {
565+
fn can_derive_simple(self, kind: &TypeKind) -> CanDerive {
566566
match (self, kind) {
567567
// === Default ===
568568
(

bindgen/ir/comp.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,16 @@ pub(crate) enum MethodKind {
5656

5757
impl MethodKind {
5858
/// Is this a destructor method?
59-
pub(crate) fn is_destructor(&self) -> bool {
59+
pub(crate) fn is_destructor(self) -> bool {
6060
matches!(
61-
*self,
61+
self,
6262
MethodKind::Destructor | MethodKind::VirtualDestructor { .. }
6363
)
6464
}
6565

6666
/// Is this a pure virtual method?
67-
pub(crate) fn is_pure_virtual(&self) -> bool {
68-
match *self {
67+
pub(crate) fn is_pure_virtual(self) -> bool {
68+
match self {
6969
MethodKind::Virtual { pure_virtual } |
7070
MethodKind::VirtualDestructor { pure_virtual } => pure_virtual,
7171
_ => false,

bindgen/ir/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ impl From<ItemId> for usize {
198198

199199
impl ItemId {
200200
/// Get a numeric representation of this ID.
201-
pub(crate) fn as_usize(&self) -> usize {
202-
(*self).into()
201+
pub(crate) fn as_usize(self) -> usize {
202+
self.into()
203203
}
204204
}
205205

bindgen/ir/function.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,8 @@ pub(crate) enum ClangAbi {
247247

248248
impl ClangAbi {
249249
/// Returns whether this Abi is known or not.
250-
fn is_unknown(&self) -> bool {
251-
matches!(*self, ClangAbi::Unknown(..))
250+
fn is_unknown(self) -> bool {
251+
matches!(self, ClangAbi::Unknown(..))
252252
}
253253
}
254254

bindgen/ir/item.rs

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ impl DebugOnlyItemSet {
103103
DebugOnlyItemSet
104104
}
105105

106+
#[allow(clippy::trivially_copy_pass_by_ref)]
106107
fn contains(&self, _id: &ItemId) -> bool {
107108
false
108109
}

0 commit comments

Comments
 (0)