From 057c9523ada21bd0e8e2aad25860af453ca299ae Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Wed, 8 Jan 2025 22:47:06 -0500 Subject: [PATCH] A few minor clippy lints * Fix `unnested_or_patterns` * Do a few `match_same_arms`, but keep the lint disabled --- Cargo.toml | 4 +-- bindgen-tests/build.rs | 29 ++++++++----------- bindgen/codegen/mod.rs | 2 +- bindgen/ir/analysis/derive.rs | 27 ++++++++++------- bindgen/ir/analysis/has_float.rs | 2 +- .../ir/analysis/has_type_param_in_array.rs | 2 +- bindgen/ir/function.rs | 8 ++--- bindgen/ir/int.rs | 4 +-- bindgen/ir/item.rs | 20 ++++++------- 9 files changed, 47 insertions(+), 51 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 248c041378..269f35a9e4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" @@ -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" diff --git a/bindgen-tests/build.rs b/bindgen-tests/build.rs index d98e823919..b261ed0a35 100644 --- a/bindgen-tests/build.rs +++ b/bindgen-tests/build.rs @@ -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}; @@ -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(); - } - _ => {} } } diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index cf819950db..248c618174 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -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 | diff --git a/bindgen/ir/analysis/derive.rs b/bindgen/ir/analysis/derive.rs index 1643a91461..bd4e40494e 100644 --- a/bindgen/ir/analysis/derive.rs +++ b/bindgen/ir/analysis/derive.rs @@ -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 } @@ -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 } @@ -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 } diff --git a/bindgen/ir/analysis/has_float.rs b/bindgen/ir/analysis/has_float.rs index da4b413372..e2463ccb96 100644 --- a/bindgen/ir/analysis/has_float.rs +++ b/bindgen/ir/analysis/has_float.rs @@ -56,7 +56,7 @@ impl HasFloat<'_> { EdgeKind::FunctionParameter | EdgeKind::InnerType | EdgeKind::InnerVar | - EdgeKind::Method => false, + EdgeKind::Method | EdgeKind::Generic => false, } } diff --git a/bindgen/ir/analysis/has_type_param_in_array.rs b/bindgen/ir/analysis/has_type_param_in_array.rs index 466ccb2ae8..687f81560c 100644 --- a/bindgen/ir/analysis/has_type_param_in_array.rs +++ b/bindgen/ir/analysis/has_type_param_in_array.rs @@ -58,7 +58,7 @@ impl HasTypeParameterInArray<'_> { EdgeKind::FunctionParameter | EdgeKind::InnerType | EdgeKind::InnerVar | - EdgeKind::Method => false, + EdgeKind::Method | EdgeKind::Generic => false, } } diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index 2474ea839a..0a6ccb1e04 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -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), } } diff --git a/bindgen/ir/int.rs b/bindgen/ir/int.rs index 4251b3753a..4b49931ed8 100644 --- a/bindgen/ir/int.rs +++ b/bindgen/ir/int.rs @@ -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, } } diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index b131455849..9a90b27eda 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -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(), }, } } @@ -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) }