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
}

0 commit comments

Comments
 (0)