Skip to content

Commit 4a8bdd9

Browse files
committed
Resolve new Clippy lints
1 parent 8ca91c6 commit 4a8bdd9

File tree

9 files changed

+23
-67
lines changed

9 files changed

+23
-67
lines changed

bindgen/callbacks.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,16 @@ pub use crate::ir::int::IntKind;
77
use std::fmt;
88

99
/// An enum to allow ignoring parsing of macros.
10-
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
10+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)]
1111
pub enum MacroParsingBehavior {
1212
/// Ignore the macro, generating no code for it, or anything that depends on
1313
/// it.
1414
Ignore,
1515
/// The default behavior bindgen would have otherwise.
16+
#[default]
1617
Default,
1718
}
1819

19-
impl Default for MacroParsingBehavior {
20-
fn default() -> Self {
21-
MacroParsingBehavior::Default
22-
}
23-
}
24-
2520
/// A trait to allow configuring different kinds of types in different
2621
/// situations.
2722
pub trait ParseCallbacks: fmt::Debug {

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 & 22 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
}
@@ -3010,7 +3010,7 @@ impl Method {
30103010
}
30113011

30123012
/// A helper type that represents different enum variations.
3013-
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
3013+
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
30143014
pub enum EnumVariation {
30153015
/// The code for this enum will use a Rust enum. Note that creating this in unsafe code
30163016
/// (including FFI) with an invalid value will invoke undefined behaviour, whether or not
@@ -3027,6 +3027,7 @@ pub enum EnumVariation {
30273027
is_global: bool,
30283028
},
30293029
/// The code for this enum will use consts
3030+
#[default]
30303031
Consts,
30313032
/// The code for this enum will use a module containing consts
30323033
ModuleConsts,
@@ -3044,12 +3045,6 @@ impl EnumVariation {
30443045
}
30453046
}
30463047

3047-
impl Default for EnumVariation {
3048-
fn default() -> EnumVariation {
3049-
EnumVariation::Consts
3050-
}
3051-
}
3052-
30533048
impl fmt::Display for EnumVariation {
30543049
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30553050
let s = match self {
@@ -3757,11 +3752,12 @@ impl CodeGenerator for Enum {
37573752
}
37583753

37593754
/// Enum for the default type of macro constants.
3760-
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
3755+
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
37613756
pub enum MacroTypeVariation {
37623757
/// Use i32 or i64
37633758
Signed,
37643759
/// Use u32 or u64
3760+
#[default]
37653761
Unsigned,
37663762
}
37673763

@@ -3775,12 +3771,6 @@ impl fmt::Display for MacroTypeVariation {
37753771
}
37763772
}
37773773

3778-
impl Default for MacroTypeVariation {
3779-
fn default() -> MacroTypeVariation {
3780-
MacroTypeVariation::Unsigned
3781-
}
3782-
}
3783-
37843774
impl std::str::FromStr for MacroTypeVariation {
37853775
type Err = std::io::Error;
37863776

@@ -3801,9 +3791,10 @@ impl std::str::FromStr for MacroTypeVariation {
38013791
}
38023792

38033793
/// Enum for how aliases should be translated.
3804-
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
3794+
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
38053795
pub enum AliasVariation {
38063796
/// Convert to regular Rust alias
3797+
#[default]
38073798
TypeAlias,
38083799
/// Create a new type by wrapping the old type in a struct and using #[repr(transparent)]
38093800
NewType,
@@ -3823,12 +3814,6 @@ impl fmt::Display for AliasVariation {
38233814
}
38243815
}
38253816

3826-
impl Default for AliasVariation {
3827-
fn default() -> AliasVariation {
3828-
AliasVariation::TypeAlias
3829-
}
3830-
}
3831-
38323817
impl std::str::FromStr for AliasVariation {
38333818
type Err = std::io::Error;
38343819

bindgen/ir/analysis/has_vtable.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ use std::cmp;
99
use std::ops;
1010

1111
/// The result of the `HasVtableAnalysis` for an individual item.
12-
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
12+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Default)]
1313
pub(crate) enum HasVtableResult {
1414
/// The item does not have a vtable pointer.
15+
#[default]
1516
No,
1617

1718
/// The item has a vtable and the actual vtable pointer is within this item.
@@ -22,12 +23,6 @@ pub(crate) enum HasVtableResult {
2223
BaseHasVtable,
2324
}
2425

25-
impl Default for HasVtableResult {
26-
fn default() -> Self {
27-
HasVtableResult::No
28-
}
29-
}
30-
3126
impl HasVtableResult {
3227
/// Take the least upper bound of `self` and `rhs`.
3328
pub(crate) fn join(self, rhs: Self) -> Self {

bindgen/ir/analysis/mod.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,22 +125,17 @@ pub(crate) trait MonotoneFramework: Sized + fmt::Debug {
125125

126126
/// Whether an analysis's `constrain` function modified the incremental results
127127
/// or not.
128-
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
128+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Default)]
129129
pub(crate) enum ConstrainResult {
130130
/// The incremental results were updated, and the fix-point computation
131131
/// should continue.
132132
Changed,
133133

134134
/// The incremental results were not updated.
135+
#[default]
135136
Same,
136137
}
137138

138-
impl Default for ConstrainResult {
139-
fn default() -> Self {
140-
ConstrainResult::Same
141-
}
142-
}
143-
144139
impl ops::BitOr for ConstrainResult {
145140
type Output = Self;
146141

bindgen/ir/analysis/sizedness.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ use std::{cmp, ops};
2424
///
2525
/// We initially assume that all types are `ZeroSized` and then update our
2626
/// understanding as we learn more about each type.
27-
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
27+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Default)]
2828
pub(crate) enum SizednessResult {
2929
/// The type is zero-sized.
3030
///
3131
/// This means that if it is a C++ type, and is not being used as a base
3232
/// member, then we must add an `_address` byte to enforce the
3333
/// unique-address-per-distinct-object-instance rule.
34+
#[default]
3435
ZeroSized,
3536

3637
/// Whether this type is zero-sized or not depends on whether a type
@@ -62,12 +63,6 @@ pub(crate) enum SizednessResult {
6263
NonZeroSized,
6364
}
6465

65-
impl Default for SizednessResult {
66-
fn default() -> Self {
67-
SizednessResult::ZeroSized
68-
}
69-
}
70-
7166
impl SizednessResult {
7267
/// Take the least upper bound of `self` and `rhs`.
7368
pub(crate) fn join(self, rhs: Self) -> Self {

bindgen/ir/annotations.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ use std::str::FromStr;
99
use crate::clang;
1010

1111
/// What kind of visibility modifier should be used for a struct or field?
12-
#[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Clone, Debug)]
12+
#[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Clone, Debug, Default)]
1313
pub enum FieldVisibilityKind {
1414
/// Fields are marked as private, i.e., struct Foo {bar: bool}
1515
Private,
1616
/// Fields are marked as crate public, i.e., struct Foo {pub(crate) bar: bool}
1717
PublicCrate,
1818
/// Fields are marked as public, i.e., struct Foo {pub bar: bool}
19+
#[default]
1920
Public,
2021
}
2122

@@ -44,12 +45,6 @@ impl std::fmt::Display for FieldVisibilityKind {
4445
}
4546
}
4647

47-
impl Default for FieldVisibilityKind {
48-
fn default() -> Self {
49-
FieldVisibilityKind::Public
50-
}
51-
}
52-
5348
/// What kind of accessor should we provide for a field?
5449
#[derive(Copy, PartialEq, Eq, Clone, Debug)]
5550
pub(crate) enum FieldAccessorKind {

bindgen/ir/derive.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,10 @@ pub(crate) trait CanDeriveOrd {
9292
///
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.
95-
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
95+
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
9696
pub enum CanDerive {
9797
/// Yes, we can derive automatically.
98+
#[default]
9899
Yes,
99100

100101
/// The only thing that stops us from automatically deriving is that
@@ -107,12 +108,6 @@ pub enum CanDerive {
107108
No,
108109
}
109110

110-
impl Default for CanDerive {
111-
fn default() -> CanDerive {
112-
CanDerive::Yes
113-
}
114-
}
115-
116111
impl CanDerive {
117112
/// Take the least upper bound of `self` and `rhs`.
118113
pub(crate) fn join(self, rhs: Self) -> Self {

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)