Skip to content

Commit

Permalink
A few minor clippy lints
Browse files Browse the repository at this point in the history
* Fix `unnested_or_patterns`
* Do a few `match_same_arms`, but keep the lint disabled
  • Loading branch information
nyurik committed Jan 9, 2025
1 parent 59a43e1 commit 057c952
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 51 deletions.
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ ignored_unit_patterns = "allow"
implicit_hasher = "allow"
inconsistent_struct_constructor = "allow"
items_after_statements = "allow"
match_same_arms = "allow"
maybe_infinite_iter = "allow"
missing_errors_doc = "allow"
missing_panics_doc = "allow"
Expand All @@ -73,19 +74,16 @@ must_use_candidate = "allow"
ptr_as_ptr = "allow"
redundant_closure_for_method_calls = "allow"
return_self_not_must_use = "allow"
#should_panic_without_expect = "allow"
similar_names = "allow"
struct_excessive_bools = "allow"
struct_field_names = "allow"
unnecessary_wraps = "allow"
unnested_or_patterns = "allow"
unreadable_literal = "allow"
used_underscore_binding = "allow"
wildcard_imports = "allow"

# TODO
borrow_as_ptr = "allow"
match_same_arms = "allow"
trivially_copy_pass_by_ref = "allow"
needless_pass_by_value = "allow"
unused_self = "allow"
Expand Down
29 changes: 12 additions & 17 deletions bindgen-tests/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::char;
use std::env;
use std::ffi::OsStr;
use std::fs::{self, File};
use std::io::Write;
use std::path::{Path, PathBuf};
Expand All @@ -23,23 +22,19 @@ pub fn main() {
println!("cargo:rerun-if-changed=tests/headers");

for entry in entries {
match entry.path().extension().and_then(OsStr::to_str) {
Some("h") | Some("hpp") => {
let func = entry
.file_name()
.to_str()
.unwrap()
.replace(|c| !char::is_alphanumeric(c), "_")
.replace("__", "_")
.to_lowercase();
writeln!(
dst,
"test_header!(header_{func}, {:?});",
entry.path(),
)
// TODO: file_is_cpp() in bindgen/lib.rs checks for hpp,hxx,hh, and h++ - should this be consistent?
if entry.path().extension().map_or(false, |ext| {
ext.eq_ignore_ascii_case("h") || ext.eq_ignore_ascii_case("hpp")
}) {
let func = entry
.file_name()
.to_str()
.unwrap()
.replace(|c| !char::is_alphanumeric(c), "_")
.replace("__", "_")
.to_lowercase();
writeln!(dst, "test_header!(header_{func}, {:?});", entry.path())
.unwrap();
}
_ => {}
}
}

Expand Down
2 changes: 1 addition & 1 deletion bindgen/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3003,7 +3003,7 @@ impl Method {
let cc = &ctx.options().codegen_config;
match self.kind() {
MethodKind::Constructor => cc.constructors(),
MethodKind::Destructor => cc.destructors(),
MethodKind::Destructor |
MethodKind::VirtualDestructor { .. } => cc.destructors(),
MethodKind::Static |
MethodKind::Normal |
Expand Down
27 changes: 16 additions & 11 deletions bindgen/ir/analysis/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ impl DeriveTrait {

fn can_derive_fnptr(&self, f: &FunctionSig) -> CanDerive {
match (self, f.function_pointers_can_derive()) {
(DeriveTrait::Copy, _) | (DeriveTrait::Default, _) | (_, true) => {
(DeriveTrait::Copy | DeriveTrait::Default, _) | (_, true) => {
trace!(" function pointer can derive {self}");
CanDerive::Yes
}
Expand Down Expand Up @@ -565,14 +565,17 @@ impl DeriveTrait {
fn can_derive_simple(&self, kind: &TypeKind) -> CanDerive {
match (self, kind) {
// === Default ===
(DeriveTrait::Default, TypeKind::Void) |
(DeriveTrait::Default, TypeKind::NullPtr) |
(DeriveTrait::Default, TypeKind::Enum(..)) |
(DeriveTrait::Default, TypeKind::Reference(..)) |
(DeriveTrait::Default, TypeKind::TypeParam) |
(DeriveTrait::Default, TypeKind::ObjCInterface(..)) |
(DeriveTrait::Default, TypeKind::ObjCId) |
(DeriveTrait::Default, TypeKind::ObjCSel) => {
(
DeriveTrait::Default,
TypeKind::Void |
TypeKind::NullPtr |
TypeKind::Enum(..) |
TypeKind::Reference(..) |
TypeKind::TypeParam |
TypeKind::ObjCInterface(..) |
TypeKind::ObjCId |
TypeKind::ObjCSel,
) => {
trace!(" types that always cannot derive Default");
CanDerive::No
}
Expand All @@ -582,8 +585,10 @@ impl DeriveTrait {
)
}
// === Hash ===
(DeriveTrait::Hash, TypeKind::Float(..)) |
(DeriveTrait::Hash, TypeKind::Complex(..)) => {
(
DeriveTrait::Hash,
TypeKind::Float(..) | TypeKind::Complex(..),
) => {
trace!(" float cannot derive Hash");
CanDerive::No
}
Expand Down
2 changes: 1 addition & 1 deletion bindgen/ir/analysis/has_float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl HasFloat<'_> {
EdgeKind::FunctionParameter |
EdgeKind::InnerType |
EdgeKind::InnerVar |
EdgeKind::Method => false,
EdgeKind::Method |
EdgeKind::Generic => false,
}
}
Expand Down
2 changes: 1 addition & 1 deletion bindgen/ir/analysis/has_type_param_in_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl HasTypeParameterInArray<'_> {
EdgeKind::FunctionParameter |
EdgeKind::InnerType |
EdgeKind::InnerVar |
EdgeKind::Method => false,
EdgeKind::Method |
EdgeKind::Generic => false,
}
}
Expand Down
8 changes: 4 additions & 4 deletions bindgen/ir/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,15 @@ pub(crate) struct FunctionSig {
fn get_abi(cc: CXCallingConv) -> ClangAbi {
use clang_sys::*;
match cc {
CXCallingConv_Default => ClangAbi::Known(Abi::C),
CXCallingConv_C => ClangAbi::Known(Abi::C),
CXCallingConv_Default | CXCallingConv_C => ClangAbi::Known(Abi::C),
CXCallingConv_X86StdCall => ClangAbi::Known(Abi::Stdcall),
CXCallingConv_X86FastCall => ClangAbi::Known(Abi::Fastcall),
CXCallingConv_X86ThisCall => ClangAbi::Known(Abi::ThisCall),
CXCallingConv_X86VectorCall => ClangAbi::Known(Abi::Vectorcall),
CXCallingConv_X86VectorCall | CXCallingConv_AArch64VectorCall => {
ClangAbi::Known(Abi::Vectorcall)
}
CXCallingConv_AAPCS => ClangAbi::Known(Abi::Aapcs),
CXCallingConv_X86_64Win64 => ClangAbi::Known(Abi::Win64),
CXCallingConv_AArch64VectorCall => ClangAbi::Known(Abi::Vectorcall),
other => ClangAbi::Unknown(other),
}
}
Expand Down
4 changes: 1 addition & 3 deletions bindgen/ir/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ impl IntKind {
SChar | Short | Int | Long | LongLong | I8 | I16 | I32 | I64 |
I128 => true,

Char { is_signed } => is_signed,

Custom { is_signed, .. } => is_signed,
Char { is_signed } | Custom { is_signed, .. } => is_signed,
}
}

Expand Down
20 changes: 10 additions & 10 deletions bindgen/ir/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,15 +1012,15 @@ impl Item {
FunctionKind::Method(MethodKind::Constructor) => {
cc.constructors()
}
FunctionKind::Method(MethodKind::Destructor) |
FunctionKind::Method(MethodKind::VirtualDestructor {
..
}) => cc.destructors(),
FunctionKind::Method(MethodKind::Static) |
FunctionKind::Method(MethodKind::Normal) |
FunctionKind::Method(MethodKind::Virtual { .. }) => {
cc.methods()
}
FunctionKind::Method(
MethodKind::Destructor |
MethodKind::VirtualDestructor { .. },
) => cc.destructors(),
FunctionKind::Method(
MethodKind::Static |
MethodKind::Normal |
MethodKind::Virtual { .. },
) => cc.methods(),
},
}
}
Expand Down Expand Up @@ -1415,7 +1415,7 @@ impl Item {
CXCursor_UsingDirective |
CXCursor_StaticAssert |
CXCursor_FunctionTemplate => {
debug!("Unhandled cursor kind {:?}: {cursor:?}", cursor.kind(),);
debug!("Unhandled cursor kind {:?}: {cursor:?}", cursor.kind());
Err(ParseError::Continue)
}

Expand Down

0 comments on commit 057c952

Please sign in to comment.