Skip to content

Commit 54da852

Browse files
committed
Resolve new Clippy lints
1 parent 8ca91c6 commit 54da852

File tree

9 files changed

+23
-49
lines changed

9 files changed

+23
-49
lines changed

bindgen/callbacks.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,16 @@ use std::fmt;
88

99
/// An enum to allow ignoring parsing of macros.
1010
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
11+
#[derive(Default)]
1112
pub enum MacroParsingBehavior {
1213
/// Ignore the macro, generating no code for it, or anything that depends on
1314
/// it.
1415
Ignore,
1516
/// The default behavior bindgen would have otherwise.
17+
#[default]
1618
Default,
1719
}
1820

19-
impl Default for MacroParsingBehavior {
20-
fn default() -> Self {
21-
MacroParsingBehavior::Default
22-
}
23-
}
2421

2522
/// A trait to allow configuring different kinds of types in different
2623
/// situations.

bindgen/clang.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use std::fs::OpenOptions;
1414
use std::hash::Hash;
1515
use std::hash::Hasher;
1616
use std::os::raw::{c_char, c_int, c_longlong, c_uint, c_ulong, c_ulonglong};
17-
use std::{mem, ptr, slice};
1817
use std::sync::OnceLock;
18+
use std::{mem, ptr, slice};
1919

2020
/// Type representing a clang attribute.
2121
///

bindgen/codegen/mod.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2608,7 +2608,7 @@ impl CodeGenerator for CompInfo {
26082608
ctx,
26092609
&canonical_ident,
26102610
flex_inner_ty,
2611-
&*generic_param_names,
2611+
&generic_param_names,
26122612
&impl_generics_labels,
26132613
));
26142614
}
@@ -3011,6 +3011,7 @@ impl Method {
30113011

30123012
/// A helper type that represents different enum variations.
30133013
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
3014+
#[derive(Default)]
30143015
pub enum EnumVariation {
30153016
/// The code for this enum will use a Rust enum. Note that creating this in unsafe code
30163017
/// (including FFI) with an invalid value will invoke undefined behaviour, whether or not
@@ -3027,6 +3028,7 @@ pub enum EnumVariation {
30273028
is_global: bool,
30283029
},
30293030
/// The code for this enum will use consts
3031+
#[default]
30303032
Consts,
30313033
/// The code for this enum will use a module containing consts
30323034
ModuleConsts,
@@ -3044,11 +3046,6 @@ impl EnumVariation {
30443046
}
30453047
}
30463048

3047-
impl Default for EnumVariation {
3048-
fn default() -> EnumVariation {
3049-
EnumVariation::Consts
3050-
}
3051-
}
30523049

30533050
impl fmt::Display for EnumVariation {
30543051
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -3758,10 +3755,12 @@ impl CodeGenerator for Enum {
37583755

37593756
/// Enum for the default type of macro constants.
37603757
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
3758+
#[derive(Default)]
37613759
pub enum MacroTypeVariation {
37623760
/// Use i32 or i64
37633761
Signed,
37643762
/// Use u32 or u64
3763+
#[default]
37653764
Unsigned,
37663765
}
37673766

@@ -3775,11 +3774,6 @@ impl fmt::Display for MacroTypeVariation {
37753774
}
37763775
}
37773776

3778-
impl Default for MacroTypeVariation {
3779-
fn default() -> MacroTypeVariation {
3780-
MacroTypeVariation::Unsigned
3781-
}
3782-
}
37833777

37843778
impl std::str::FromStr for MacroTypeVariation {
37853779
type Err = std::io::Error;
@@ -3802,8 +3796,10 @@ impl std::str::FromStr for MacroTypeVariation {
38023796

38033797
/// Enum for how aliases should be translated.
38043798
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
3799+
#[derive(Default)]
38053800
pub enum AliasVariation {
38063801
/// Convert to regular Rust alias
3802+
#[default]
38073803
TypeAlias,
38083804
/// Create a new type by wrapping the old type in a struct and using #[repr(transparent)]
38093805
NewType,
@@ -3823,11 +3819,6 @@ impl fmt::Display for AliasVariation {
38233819
}
38243820
}
38253821

3826-
impl Default for AliasVariation {
3827-
fn default() -> AliasVariation {
3828-
AliasVariation::TypeAlias
3829-
}
3830-
}
38313822

38323823
impl std::str::FromStr for AliasVariation {
38333824
type Err = std::io::Error;

bindgen/ir/analysis/has_vtable.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ use std::ops;
1010

1111
/// The result of the `HasVtableAnalysis` for an individual item.
1212
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
13+
#[derive(Default)]
1314
pub(crate) enum HasVtableResult {
1415
/// The item does not have a vtable pointer.
16+
#[default]
1517
No,
1618

1719
/// The item has a vtable and the actual vtable pointer is within this item.
@@ -22,11 +24,6 @@ pub(crate) enum HasVtableResult {
2224
BaseHasVtable,
2325
}
2426

25-
impl Default for HasVtableResult {
26-
fn default() -> Self {
27-
HasVtableResult::No
28-
}
29-
}
3027

3128
impl HasVtableResult {
3229
/// Take the least upper bound of `self` and `rhs`.

bindgen/ir/analysis/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,17 @@ pub(crate) trait MonotoneFramework: Sized + fmt::Debug {
126126
/// Whether an analysis's `constrain` function modified the incremental results
127127
/// or not.
128128
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
129+
#[derive(Default)]
129130
pub(crate) enum ConstrainResult {
130131
/// The incremental results were updated, and the fix-point computation
131132
/// should continue.
132133
Changed,
133134

134135
/// The incremental results were not updated.
136+
#[default]
135137
Same,
136138
}
137139

138-
impl Default for ConstrainResult {
139-
fn default() -> Self {
140-
ConstrainResult::Same
141-
}
142-
}
143140

144141
impl ops::BitOr for ConstrainResult {
145142
type Output = Self;

bindgen/ir/analysis/sizedness.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ use std::{cmp, ops};
2525
/// We initially assume that all types are `ZeroSized` and then update our
2626
/// understanding as we learn more about each type.
2727
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
28+
#[derive(Default)]
2829
pub(crate) enum SizednessResult {
2930
/// The type is zero-sized.
3031
///
3132
/// This means that if it is a C++ type, and is not being used as a base
3233
/// member, then we must add an `_address` byte to enforce the
3334
/// unique-address-per-distinct-object-instance rule.
35+
#[default]
3436
ZeroSized,
3537

3638
/// Whether this type is zero-sized or not depends on whether a type
@@ -62,11 +64,6 @@ pub(crate) enum SizednessResult {
6264
NonZeroSized,
6365
}
6466

65-
impl Default for SizednessResult {
66-
fn default() -> Self {
67-
SizednessResult::ZeroSized
68-
}
69-
}
7067

7168
impl SizednessResult {
7269
/// Take the least upper bound of `self` and `rhs`.

bindgen/ir/annotations.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ use crate::clang;
1010

1111
/// What kind of visibility modifier should be used for a struct or field?
1212
#[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Clone, Debug)]
13+
#[derive(Default)]
1314
pub enum FieldVisibilityKind {
1415
/// Fields are marked as private, i.e., struct Foo {bar: bool}
1516
Private,
1617
/// Fields are marked as crate public, i.e., struct Foo {pub(crate) bar: bool}
1718
PublicCrate,
1819
/// Fields are marked as public, i.e., struct Foo {pub bar: bool}
20+
#[default]
1921
Public,
2022
}
2123

@@ -44,11 +46,6 @@ impl std::fmt::Display for FieldVisibilityKind {
4446
}
4547
}
4648

47-
impl Default for FieldVisibilityKind {
48-
fn default() -> Self {
49-
FieldVisibilityKind::Public
50-
}
51-
}
5249

5350
/// What kind of accessor should we provide for a field?
5451
#[derive(Copy, PartialEq, Eq, Clone, Debug)]

bindgen/ir/derive.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,10 @@ pub(crate) trait CanDeriveOrd {
9393
/// Initially we assume that we can derive trait for all types and then
9494
/// update our understanding as we learn more about each type.
9595
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
96+
#[derive(Default)]
9697
pub enum CanDerive {
9798
/// Yes, we can derive automatically.
99+
#[default]
98100
Yes,
99101

100102
/// The only thing that stops us from automatically deriving is that
@@ -107,11 +109,6 @@ pub enum CanDerive {
107109
No,
108110
}
109111

110-
impl Default for CanDerive {
111-
fn default() -> CanDerive {
112-
CanDerive::Yes
113-
}
114-
}
115112

116113
impl CanDerive {
117114
/// Take the least upper bound of `self` and `rhs`.

bindgen/ir/item.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,8 +1807,9 @@ impl Item {
18071807
spelling: &str,
18081808
) -> bool {
18091809
static ANON_TYPE_PARAM_RE: OnceLock<regex::Regex> = OnceLock::new();
1810-
let anon_type_param_re = ANON_TYPE_PARAM_RE.get_or_init(||
1811-
regex::Regex::new(r"^type\-parameter\-\d+\-\d+$").unwrap());
1810+
let anon_type_param_re = ANON_TYPE_PARAM_RE.get_or_init(|| {
1811+
regex::Regex::new(r"^type\-parameter\-\d+\-\d+$").unwrap()
1812+
});
18121813

18131814
if refd.kind() != clang_sys::CXCursor_TemplateTypeParameter {
18141815
return false;

0 commit comments

Comments
 (0)