Skip to content

Clippify, and hide some lints in test output #3003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions bindgen-tests/tests/expectations/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,23 @@ publish = false
block = "0.1"
libloading = "0.7"
objc = "0.2"

[lints.rust]
### FIXME: these might need to be fixed,
### esp the calling convention, because it is a hard error now
# deprecated = "allow"
# invalid-value = "allow"
# unsupported_calling_conventions = "allow"
non-snake-case = "allow"
unexpected-cfgs = "allow"

[lints.clippy]
disallowed-names = "allow"
manual-c-str-literals = "allow"
missing-safety-doc = "allow"
op-ref = "allow"
ptr-offset-with-cast = "allow"
too-many-arguments = "allow"
transmute-int-to-bool = "allow"
unnecessary-cast = "allow"
useless-transmute = "allow"
4 changes: 2 additions & 2 deletions bindgen/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ impl Cursor {
let found_attr = &mut found_attrs[idx];
if !*found_attr {
// `attr.name` and` attr.token_kind` are checked against unexposed attributes only.
if attr.kind.map_or(false, |k| k == kind) ||
if attr.kind == Some(kind) ||
(kind == CXCursor_UnexposedAttr &&
cur.tokens().iter().any(|t| {
t.kind == attr.token_kind &&
Expand Down Expand Up @@ -1522,7 +1522,7 @@ impl Type {
// Yep, the spelling of this containing type-parameter is extremely
// nasty... But can happen in <type_traits>. Unfortunately I couldn't
// reduce it enough :(
self.template_args().map_or(false, |args| args.len() > 0) &&
self.template_args().is_some_and(|args| args.len() > 0) &&
!matches!(
self.declaration().kind(),
CXCursor_ClassTemplatePartialSpecialization |
Expand Down
2 changes: 1 addition & 1 deletion bindgen/ir/analysis/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ impl<'ctx> MonotoneFramework for CannotDerive<'ctx> {
let is_reached_limit =
|l: Layout| l.align > RUST_DERIVE_IN_ARRAY_LIMIT;
if !self.derive_trait.can_derive_large_array(self.ctx) &&
ty.layout(self.ctx).map_or(false, is_reached_limit)
ty.layout(self.ctx).is_some_and(is_reached_limit)
{
// We have to be conservative: the struct *could* have enough
// padding that we emit an array that is longer than
Expand Down
2 changes: 1 addition & 1 deletion bindgen/ir/annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl Annotations {
comment
.get_tag_attrs()
.next()
.map_or(false, |attr| attr.name == "rustbindgen")
.is_some_and(|attr| attr.name == "rustbindgen")
{
*matched = true;
for attr in comment.get_tag_attrs() {
Expand Down
2 changes: 1 addition & 1 deletion bindgen/ir/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn preprocess_multi_line(comment: &str) -> String {
.collect();

// Remove the trailing line corresponding to the `*/`.
if lines.last().map_or(false, |l| l.trim().is_empty()) {
if lines.last().is_some_and(|l| l.trim().is_empty()) {
lines.pop();
}

Expand Down
2 changes: 1 addition & 1 deletion bindgen/ir/comp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,7 @@ impl CompInfo {
return (false, false);
}

if layout.map_or(false, |l| l.size == 0) {
if layout.is_some_and(|l| l.size == 0) {
return (false, false);
}

Expand Down
11 changes: 4 additions & 7 deletions bindgen/ir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
.chain(Some(immut_self.root_module.into()))
.find(|id| {
let item = immut_self.resolve_item(*id);
item.as_module().map_or(false, |m| {
item.as_module().is_some_and(|m| {
m.children().contains(&replacement_id.into())
})
})
Expand Down Expand Up @@ -1289,9 +1289,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
);
self.resolve_item(ancestor)
.as_module()
.map_or(false, |m| {
m.children().contains(&id)
})
.is_some_and(|m| m.children().contains(&id))
})
},
"{:?} should be in some ancestor module's children set",
Expand Down Expand Up @@ -1424,8 +1422,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
self.used_template_parameters
.as_ref()
.expect("should have found template parameter usage if we're in codegen")
.get(&item)
.map_or(false, |items_used_params| items_used_params.contains(&template_param))
.get(&item).is_some_and(|items_used_params| items_used_params.contains(&template_param))
}

/// Return `true` if `item` uses any unbound, generic template parameters,
Expand All @@ -1444,7 +1441,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
"should have template parameter usage info in codegen phase",
)
.get(&item)
.map_or(false, |used| !used.is_empty())
.is_some_and(|used| !used.is_empty())
}

// This deserves a comment. Builtin types don't get a valid declaration, so
Expand Down
8 changes: 3 additions & 5 deletions bindgen/ir/enum_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Enum {

let variant_ty =
repr.and_then(|r| ctx.resolve_type(r).safe_canonical_type(ctx));
let is_bool = variant_ty.map_or(false, Type::is_bool);
let is_bool = variant_ty.is_some_and(Type::is_bool);

// Assume signedness since the default type by the C standard is an int.
let is_signed = variant_ty.map_or(true, |ty| match *ty.kind() {
Expand Down Expand Up @@ -310,14 +310,12 @@ impl EnumVariant {
/// Returns whether this variant should be enforced to be a constant by code
/// generation.
pub(crate) fn force_constification(&self) -> bool {
self.custom_behavior
.map_or(false, |b| b == EnumVariantCustomBehavior::Constify)
self.custom_behavior == Some(EnumVariantCustomBehavior::Constify)
}

/// Returns whether the current variant should be hidden completely from the
/// resulting rust enum.
pub(crate) fn hidden(&self) -> bool {
self.custom_behavior
.map_or(false, |b| b == EnumVariantCustomBehavior::Hide)
self.custom_behavior == Some(EnumVariantCustomBehavior::Hide)
}
}
4 changes: 1 addition & 3 deletions bindgen/ir/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,9 +749,7 @@ impl ClangSubItemParser for Function {
};

if cursor.is_inlined_function() ||
cursor
.definition()
.map_or(false, |x| x.is_inlined_function())
cursor.definition().is_some_and(|x| x.is_inlined_function())
{
if !context.options().generate_inline_functions &&
!context.options().wrap_static_fns
Expand Down
10 changes: 5 additions & 5 deletions bindgen/ir/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ impl Item {

self.ancestors(ctx)
.filter(|id| {
ctx.resolve_item(*id).as_module().map_or(false, |module| {
ctx.resolve_item(*id).as_module().is_some_and(|module| {
!module.is_inline() ||
ctx.options().conservative_inline_namespaces
})
Expand Down Expand Up @@ -1058,7 +1058,7 @@ impl Item {
.map(|id| ctx.resolve_item(id))
.filter(|item| {
item.id() == target.id() ||
item.as_module().map_or(false, |module| {
item.as_module().is_some_and(|module| {
!module.is_inline() ||
ctx.options().conservative_inline_namespaces
})
Expand Down Expand Up @@ -1122,7 +1122,7 @@ impl IsOpaque for Item {
"You're not supposed to call this yet"
);
self.annotations.opaque() ||
self.as_type().map_or(false, |ty| ty.is_opaque(ctx, self)) ||
self.as_type().is_some_and(|ty| ty.is_opaque(ctx, self)) ||
ctx.opaque_by_name(self.path_for_allowlisting(ctx))
}
}
Expand All @@ -1133,14 +1133,14 @@ where
{
fn has_vtable(&self, ctx: &BindgenContext) -> bool {
let id: ItemId = (*self).into();
id.as_type_id(ctx).map_or(false, |id| {
id.as_type_id(ctx).is_some_and(|id| {
!matches!(ctx.lookup_has_vtable(id), HasVtableResult::No)
})
}

fn has_vtable_ptr(&self, ctx: &BindgenContext) -> bool {
let id: ItemId = (*self).into();
id.as_type_id(ctx).map_or(false, |id| {
id.as_type_id(ctx).is_some_and(|id| {
matches!(ctx.lookup_has_vtable(id), HasVtableResult::SelfHasVtable)
})
}
Expand Down
2 changes: 1 addition & 1 deletion bindgen/ir/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl Opaque {
pub(crate) fn array_size_within_derive_limit(&self) -> CanDerive {
if self
.array_size()
.map_or(false, |size| size <= RUST_DERIVE_IN_ARRAY_LIMIT)
.is_some_and(|size| size <= RUST_DERIVE_IN_ARRAY_LIMIT)
{
CanDerive::Yes
} else {
Expand Down
8 changes: 2 additions & 6 deletions bindgen/ir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1217,8 +1217,7 @@ impl Type {

let is_const = ty.is_const() ||
(ty.kind() == CXType_ConstantArray &&
ty.elem_type()
.map_or(false, |element| element.is_const()));
ty.elem_type().is_some_and(|element| element.is_const()));

let ty = Type::new(name, layout, kind, is_const);
// TODO: maybe declaration.canonical()?
Expand All @@ -1233,10 +1232,7 @@ impl Trace for Type {
where
T: Tracer,
{
if self
.name()
.map_or(false, |name| context.is_stdint_type(name))
{
if self.name().is_some_and(|name| context.is_stdint_type(name)) {
// These types are special-cased in codegen and don't need to be traversed.
return;
}
Expand Down
6 changes: 3 additions & 3 deletions bindgen/ir/var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ impl ClangSubItemParser for Var {
([CXType_ConstantArray, CXType_IncompleteArray]
.contains(&ty.kind()) &&
ty.elem_type()
.map_or(false, |element| element.is_const()));
.is_some_and(|element| element.is_const()));

let ty = match Item::from_ty(&ty, cursor, None, ctx) {
Ok(ty) => ty,
Expand All @@ -335,8 +335,8 @@ impl ClangSubItemParser for Var {
.safe_resolve_type(ty)
.and_then(|t| t.safe_canonical_type(ctx));

let is_integer = canonical_ty.map_or(false, |t| t.is_integer());
let is_float = canonical_ty.map_or(false, |t| t.is_float());
let is_integer = canonical_ty.is_some_and(|t| t.is_integer());
let is_float = canonical_ty.is_some_and(|t| t.is_float());

// TODO: We could handle `char` more gracefully.
// TODO: Strings, though the lookup is a bit more hard (we need
Expand Down
2 changes: 1 addition & 1 deletion bindgen/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ pub fn clang_version() -> ClangVersion {
let raw_v: String = clang::extract_clang_version();
let split_v: Option<Vec<&str>> = raw_v
.split_whitespace()
.find(|t| t.chars().next().map_or(false, |v| v.is_ascii_digit()))
.find(|t| t.chars().next().is_some_and(|v| v.is_ascii_digit()))
.map(|v| v.split('.').collect());
if let Some(v) = split_v {
if v.len() >= 2 {
Expand Down
Loading