Skip to content

Commit

Permalink
Resolve new Clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
GKFX authored and emilio committed Apr 27, 2024
1 parent 5aa9c71 commit 12215f5
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 67 deletions.
9 changes: 2 additions & 7 deletions bindgen/callbacks.rs
Expand Up @@ -7,21 +7,16 @@ pub use crate::ir::int::IntKind;
use std::fmt;

/// An enum to allow ignoring parsing of macros.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)]
pub enum MacroParsingBehavior {
/// Ignore the macro, generating no code for it, or anything that depends on
/// it.
Ignore,
/// The default behavior bindgen would have otherwise.
#[default]
Default,
}

impl Default for MacroParsingBehavior {
fn default() -> Self {
MacroParsingBehavior::Default
}
}

/// A trait to allow configuring different kinds of types in different
/// situations.
pub trait ParseCallbacks: fmt::Debug {
Expand Down
2 changes: 1 addition & 1 deletion bindgen/clang.rs
Expand Up @@ -14,8 +14,8 @@ use std::fs::OpenOptions;
use std::hash::Hash;
use std::hash::Hasher;
use std::os::raw::{c_char, c_int, c_longlong, c_uint, c_ulong, c_ulonglong};
use std::{mem, ptr, slice};
use std::sync::OnceLock;
use std::{mem, ptr, slice};

/// Type representing a clang attribute.
///
Expand Down
29 changes: 7 additions & 22 deletions bindgen/codegen/mod.rs
Expand Up @@ -2608,7 +2608,7 @@ impl CodeGenerator for CompInfo {
ctx,
&canonical_ident,
flex_inner_ty,
&*generic_param_names,
&generic_param_names,
&impl_generics_labels,
));
}
Expand Down Expand Up @@ -3010,7 +3010,7 @@ impl Method {
}

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

impl Default for EnumVariation {
fn default() -> EnumVariation {
EnumVariation::Consts
}
}

impl fmt::Display for EnumVariation {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = match self {
Expand Down Expand Up @@ -3757,11 +3752,12 @@ impl CodeGenerator for Enum {
}

/// Enum for the default type of macro constants.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
pub enum MacroTypeVariation {
/// Use i32 or i64
Signed,
/// Use u32 or u64
#[default]
Unsigned,
}

Expand All @@ -3775,12 +3771,6 @@ impl fmt::Display for MacroTypeVariation {
}
}

impl Default for MacroTypeVariation {
fn default() -> MacroTypeVariation {
MacroTypeVariation::Unsigned
}
}

impl std::str::FromStr for MacroTypeVariation {
type Err = std::io::Error;

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

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

impl Default for AliasVariation {
fn default() -> AliasVariation {
AliasVariation::TypeAlias
}
}

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

Expand Down
9 changes: 2 additions & 7 deletions bindgen/ir/analysis/has_vtable.rs
Expand Up @@ -9,9 +9,10 @@ use std::cmp;
use std::ops;

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

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

impl Default for HasVtableResult {
fn default() -> Self {
HasVtableResult::No
}
}

impl HasVtableResult {
/// Take the least upper bound of `self` and `rhs`.
pub(crate) fn join(self, rhs: Self) -> Self {
Expand Down
9 changes: 2 additions & 7 deletions bindgen/ir/analysis/mod.rs
Expand Up @@ -125,22 +125,17 @@ pub(crate) trait MonotoneFramework: Sized + fmt::Debug {

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

/// The incremental results were not updated.
#[default]
Same,
}

impl Default for ConstrainResult {
fn default() -> Self {
ConstrainResult::Same
}
}

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

Expand Down
9 changes: 2 additions & 7 deletions bindgen/ir/analysis/sizedness.rs
Expand Up @@ -24,13 +24,14 @@ use std::{cmp, ops};
///
/// We initially assume that all types are `ZeroSized` and then update our
/// understanding as we learn more about each type.
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Default)]
pub(crate) enum SizednessResult {
/// The type is zero-sized.
///
/// This means that if it is a C++ type, and is not being used as a base
/// member, then we must add an `_address` byte to enforce the
/// unique-address-per-distinct-object-instance rule.
#[default]
ZeroSized,

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

impl Default for SizednessResult {
fn default() -> Self {
SizednessResult::ZeroSized
}
}

impl SizednessResult {
/// Take the least upper bound of `self` and `rhs`.
pub(crate) fn join(self, rhs: Self) -> Self {
Expand Down
9 changes: 2 additions & 7 deletions bindgen/ir/annotations.rs
Expand Up @@ -9,13 +9,14 @@ use std::str::FromStr;
use crate::clang;

/// What kind of visibility modifier should be used for a struct or field?
#[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Clone, Debug)]
#[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Clone, Debug, Default)]
pub enum FieldVisibilityKind {
/// Fields are marked as private, i.e., struct Foo {bar: bool}
Private,
/// Fields are marked as crate public, i.e., struct Foo {pub(crate) bar: bool}
PublicCrate,
/// Fields are marked as public, i.e., struct Foo {pub bar: bool}
#[default]
Public,
}

Expand Down Expand Up @@ -44,12 +45,6 @@ impl std::fmt::Display for FieldVisibilityKind {
}
}

impl Default for FieldVisibilityKind {
fn default() -> Self {
FieldVisibilityKind::Public
}
}

/// What kind of accessor should we provide for a field?
#[derive(Copy, PartialEq, Eq, Clone, Debug)]
pub(crate) enum FieldAccessorKind {
Expand Down
9 changes: 2 additions & 7 deletions bindgen/ir/derive.rs
Expand Up @@ -92,9 +92,10 @@ pub(crate) trait CanDeriveOrd {
///
/// Initially we assume that we can derive trait for all types and then
/// update our understanding as we learn more about each type.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Default)]
pub enum CanDerive {
/// Yes, we can derive automatically.
#[default]
Yes,

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

impl Default for CanDerive {
fn default() -> CanDerive {
CanDerive::Yes
}
}

impl CanDerive {
/// Take the least upper bound of `self` and `rhs`.
pub(crate) fn join(self, rhs: Self) -> Self {
Expand Down
5 changes: 3 additions & 2 deletions bindgen/ir/item.rs
Expand Up @@ -1807,8 +1807,9 @@ impl Item {
spelling: &str,
) -> bool {
static ANON_TYPE_PARAM_RE: OnceLock<regex::Regex> = OnceLock::new();
let anon_type_param_re = ANON_TYPE_PARAM_RE.get_or_init(||
regex::Regex::new(r"^type\-parameter\-\d+\-\d+$").unwrap());
let anon_type_param_re = ANON_TYPE_PARAM_RE.get_or_init(|| {
regex::Regex::new(r"^type\-parameter\-\d+\-\d+$").unwrap()
});

if refd.kind() != clang_sys::CXCursor_TemplateTypeParameter {
return false;
Expand Down

0 comments on commit 12215f5

Please sign in to comment.