Skip to content

Commit e97f4a6

Browse files
nyurikemilio
authored andcommitted
Clippify, and hide some lints in test output
Happy clippy = happy developers The test expectations generate a bunch of lints that are mostly irrelevant, at least at the moment, so might as well record them to avoid `cargo clippy` from reporting them.
1 parent dc696e1 commit e97f4a6

File tree

14 files changed

+46
-37
lines changed

14 files changed

+46
-37
lines changed

bindgen-tests/tests/expectations/Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,23 @@ publish = false
1414
block = "0.1"
1515
libloading = "0.7"
1616
objc = "0.2"
17+
18+
[lints.rust]
19+
### FIXME: these might need to be fixed,
20+
### esp the calling convention, because it is a hard error now
21+
# deprecated = "allow"
22+
# invalid-value = "allow"
23+
# unsupported_calling_conventions = "allow"
24+
non-snake-case = "allow"
25+
unexpected-cfgs = "allow"
26+
27+
[lints.clippy]
28+
disallowed-names = "allow"
29+
manual-c-str-literals = "allow"
30+
missing-safety-doc = "allow"
31+
op-ref = "allow"
32+
ptr-offset-with-cast = "allow"
33+
too-many-arguments = "allow"
34+
transmute-int-to-bool = "allow"
35+
unnecessary-cast = "allow"
36+
useless-transmute = "allow"

bindgen/clang.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ impl Cursor {
788788
let found_attr = &mut found_attrs[idx];
789789
if !*found_attr {
790790
// `attr.name` and` attr.token_kind` are checked against unexposed attributes only.
791-
if attr.kind.map_or(false, |k| k == kind) ||
791+
if attr.kind == Some(kind) ||
792792
(kind == CXCursor_UnexposedAttr &&
793793
cur.tokens().iter().any(|t| {
794794
t.kind == attr.token_kind &&
@@ -1522,7 +1522,7 @@ impl Type {
15221522
// Yep, the spelling of this containing type-parameter is extremely
15231523
// nasty... But can happen in <type_traits>. Unfortunately I couldn't
15241524
// reduce it enough :(
1525-
self.template_args().map_or(false, |args| args.len() > 0) &&
1525+
self.template_args().is_some_and(|args| args.len() > 0) &&
15261526
!matches!(
15271527
self.declaration().kind(),
15281528
CXCursor_ClassTemplatePartialSpecialization |

bindgen/ir/analysis/derive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ impl<'ctx> MonotoneFramework for CannotDerive<'ctx> {
673673
let is_reached_limit =
674674
|l: Layout| l.align > RUST_DERIVE_IN_ARRAY_LIMIT;
675675
if !self.derive_trait.can_derive_large_array(self.ctx) &&
676-
ty.layout(self.ctx).map_or(false, is_reached_limit)
676+
ty.layout(self.ctx).is_some_and(is_reached_limit)
677677
{
678678
// We have to be conservative: the struct *could* have enough
679679
// padding that we emit an array that is longer than

bindgen/ir/annotations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl Annotations {
213213
comment
214214
.get_tag_attrs()
215215
.next()
216-
.map_or(false, |attr| attr.name == "rustbindgen")
216+
.is_some_and(|attr| attr.name == "rustbindgen")
217217
{
218218
*matched = true;
219219
for attr in comment.get_tag_attrs() {

bindgen/ir/comment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn preprocess_multi_line(comment: &str) -> String {
5858
.collect();
5959

6060
// Remove the trailing line corresponding to the `*/`.
61-
if lines.last().map_or(false, |l| l.trim().is_empty()) {
61+
if lines.last().is_some_and(|l| l.trim().is_empty()) {
6262
lines.pop();
6363
}
6464

bindgen/ir/comp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,7 @@ impl CompInfo {
17531753
return (false, false);
17541754
}
17551755

1756-
if layout.map_or(false, |l| l.size == 0) {
1756+
if layout.is_some_and(|l| l.size == 0) {
17571757
return (false, false);
17581758
}
17591759

bindgen/ir/context.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
11481148
.chain(Some(immut_self.root_module.into()))
11491149
.find(|id| {
11501150
let item = immut_self.resolve_item(*id);
1151-
item.as_module().map_or(false, |m| {
1151+
item.as_module().is_some_and(|m| {
11521152
m.children().contains(&replacement_id.into())
11531153
})
11541154
})
@@ -1289,9 +1289,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
12891289
);
12901290
self.resolve_item(ancestor)
12911291
.as_module()
1292-
.map_or(false, |m| {
1293-
m.children().contains(&id)
1294-
})
1292+
.is_some_and(|m| m.children().contains(&id))
12951293
})
12961294
},
12971295
"{id:?} should be in some ancestor module's children set"
@@ -1423,8 +1421,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
14231421
self.used_template_parameters
14241422
.as_ref()
14251423
.expect("should have found template parameter usage if we're in codegen")
1426-
.get(&item)
1427-
.map_or(false, |items_used_params| items_used_params.contains(&template_param))
1424+
.get(&item).is_some_and(|items_used_params| items_used_params.contains(&template_param))
14281425
}
14291426

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

14491446
// This deserves a comment. Builtin types don't get a valid declaration, so

bindgen/ir/enum_ty.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl Enum {
7373

7474
let variant_ty =
7575
repr.and_then(|r| ctx.resolve_type(r).safe_canonical_type(ctx));
76-
let is_bool = variant_ty.map_or(false, Type::is_bool);
76+
let is_bool = variant_ty.is_some_and(Type::is_bool);
7777

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

317316
/// Returns whether the current variant should be hidden completely from the
318317
/// resulting rust enum.
319318
pub(crate) fn hidden(&self) -> bool {
320-
self.custom_behavior
321-
.map_or(false, |b| b == EnumVariantCustomBehavior::Hide)
319+
self.custom_behavior == Some(EnumVariantCustomBehavior::Hide)
322320
}
323321
}

bindgen/ir/function.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -744,9 +744,7 @@ impl ClangSubItemParser for Function {
744744
};
745745

746746
if cursor.is_inlined_function() ||
747-
cursor
748-
.definition()
749-
.map_or(false, |x| x.is_inlined_function())
747+
cursor.definition().is_some_and(|x| x.is_inlined_function())
750748
{
751749
if !context.options().generate_inline_functions &&
752750
!context.options().wrap_static_fns

bindgen/ir/item.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ impl Item {
492492

493493
self.ancestors(ctx)
494494
.filter(|id| {
495-
ctx.resolve_item(*id).as_module().map_or(false, |module| {
495+
ctx.resolve_item(*id).as_module().is_some_and(|module| {
496496
!module.is_inline() ||
497497
ctx.options().conservative_inline_namespaces
498498
})
@@ -1058,7 +1058,7 @@ impl Item {
10581058
.map(|id| ctx.resolve_item(id))
10591059
.filter(|item| {
10601060
item.id() == target.id() ||
1061-
item.as_module().map_or(false, |module| {
1061+
item.as_module().is_some_and(|module| {
10621062
!module.is_inline() ||
10631063
ctx.options().conservative_inline_namespaces
10641064
})
@@ -1122,7 +1122,7 @@ impl IsOpaque for Item {
11221122
"You're not supposed to call this yet"
11231123
);
11241124
self.annotations.opaque() ||
1125-
self.as_type().map_or(false, |ty| ty.is_opaque(ctx, self)) ||
1125+
self.as_type().is_some_and(|ty| ty.is_opaque(ctx, self)) ||
11261126
ctx.opaque_by_name(self.path_for_allowlisting(ctx))
11271127
}
11281128
}
@@ -1133,14 +1133,14 @@ where
11331133
{
11341134
fn has_vtable(&self, ctx: &BindgenContext) -> bool {
11351135
let id: ItemId = (*self).into();
1136-
id.as_type_id(ctx).map_or(false, |id| {
1136+
id.as_type_id(ctx).is_some_and(|id| {
11371137
!matches!(ctx.lookup_has_vtable(id), HasVtableResult::No)
11381138
})
11391139
}
11401140

11411141
fn has_vtable_ptr(&self, ctx: &BindgenContext) -> bool {
11421142
let id: ItemId = (*self).into();
1143-
id.as_type_id(ctx).map_or(false, |id| {
1143+
id.as_type_id(ctx).is_some_and(|id| {
11441144
matches!(ctx.lookup_has_vtable(id), HasVtableResult::SelfHasVtable)
11451145
})
11461146
}

bindgen/ir/layout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl Opaque {
117117
pub(crate) fn array_size_within_derive_limit(&self) -> CanDerive {
118118
if self
119119
.array_size()
120-
.map_or(false, |size| size <= RUST_DERIVE_IN_ARRAY_LIMIT)
120+
.is_some_and(|size| size <= RUST_DERIVE_IN_ARRAY_LIMIT)
121121
{
122122
CanDerive::Yes
123123
} else {

bindgen/ir/ty.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,8 +1217,7 @@ impl Type {
12171217

12181218
let is_const = ty.is_const() ||
12191219
(ty.kind() == CXType_ConstantArray &&
1220-
ty.elem_type()
1221-
.map_or(false, |element| element.is_const()));
1220+
ty.elem_type().is_some_and(|element| element.is_const()));
12221221

12231222
let ty = Type::new(name, layout, kind, is_const);
12241223
// TODO: maybe declaration.canonical()?
@@ -1233,10 +1232,7 @@ impl Trace for Type {
12331232
where
12341233
T: Tracer,
12351234
{
1236-
if self
1237-
.name()
1238-
.map_or(false, |name| context.is_stdint_type(name))
1239-
{
1235+
if self.name().is_some_and(|name| context.is_stdint_type(name)) {
12401236
// These types are special-cased in codegen and don't need to be traversed.
12411237
return;
12421238
}

bindgen/ir/var.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ impl ClangSubItemParser for Var {
307307
([CXType_ConstantArray, CXType_IncompleteArray]
308308
.contains(&ty.kind()) &&
309309
ty.elem_type()
310-
.map_or(false, |element| element.is_const()));
310+
.is_some_and(|element| element.is_const()));
311311

312312
let ty = match Item::from_ty(&ty, cursor, None, ctx) {
313313
Ok(ty) => ty,
@@ -330,8 +330,8 @@ impl ClangSubItemParser for Var {
330330
.safe_resolve_type(ty)
331331
.and_then(|t| t.safe_canonical_type(ctx));
332332

333-
let is_integer = canonical_ty.map_or(false, |t| t.is_integer());
334-
let is_float = canonical_ty.map_or(false, |t| t.is_float());
333+
let is_integer = canonical_ty.is_some_and(|t| t.is_integer());
334+
let is_float = canonical_ty.is_some_and(|t| t.is_float());
335335

336336
// TODO: We could handle `char` more gracefully.
337337
// TODO: Strings, though the lookup is a bit more hard (we need

bindgen/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ pub fn clang_version() -> ClangVersion {
11441144
let raw_v: String = clang::extract_clang_version();
11451145
let split_v: Option<Vec<&str>> = raw_v
11461146
.split_whitespace()
1147-
.find(|t| t.chars().next().map_or(false, |v| v.is_ascii_digit()))
1147+
.find(|t| t.chars().next().is_some_and(|v| v.is_ascii_digit()))
11481148
.map(|v| v.split('.').collect());
11491149
if let Some(v) = split_v {
11501150
if v.len() >= 2 {

0 commit comments

Comments
 (0)