Skip to content

Commit 97ab915

Browse files
nyurikemilio
authored andcommitted
fix all clippy lints
1 parent 8777ea8 commit 97ab915

File tree

11 files changed

+42
-44
lines changed

11 files changed

+42
-44
lines changed

Diff for: bindgen-tests/tests/parse_callbacks/item_discovery_callback/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl ParseCallbacks for ItemDiscovery {
2020

2121
fn test_item_discovery_callback(
2222
header: &str,
23-
expected: HashMap<DiscoveredItemId, DiscoveredItem>,
23+
expected: &HashMap<DiscoveredItemId, DiscoveredItem>,
2424
) {
2525
let discovery = ItemDiscovery::default();
2626
let info = Rc::clone(&discovery.0);
@@ -34,7 +34,7 @@ fn test_item_discovery_callback(
3434
.generate()
3535
.expect("TODO: panic message");
3636

37-
compare_item_caches(&info.borrow(), &expected);
37+
compare_item_caches(&info.borrow(), expected);
3838
}
3939

4040
#[test]
@@ -103,7 +103,7 @@ fn test_item_discovery_callback_c() {
103103
),
104104
]);
105105
test_item_discovery_callback(
106-
"/tests/parse_callbacks/item_discovery_callback/header_item_discovery.h", expected);
106+
"/tests/parse_callbacks/item_discovery_callback/header_item_discovery.h", &expected);
107107
}
108108

109109
#[test]
@@ -125,7 +125,7 @@ fn test_item_discovery_callback_cpp() {
125125
),
126126
]);
127127
test_item_discovery_callback(
128-
"/tests/parse_callbacks/item_discovery_callback/header_item_discovery.hpp", expected);
128+
"/tests/parse_callbacks/item_discovery_callback/header_item_discovery.hpp", &expected);
129129
}
130130

131131
pub fn compare_item_caches(generated: &ItemCache, expected: &ItemCache) {

Diff for: bindgen-tests/tests/quickchecking/src/fuzzers.rs

+14-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use quickcheck::{Arbitrary, Gen};
22
use std::fmt;
3+
use std::fmt::Write as _;
34

45
/// `BaseTypeC` is used in generation of C headers to represent the C language's
56
/// primitive types as well as `void*`.
@@ -223,11 +224,10 @@ impl Arbitrary for DeclarationListC {
223224
/// Enables to string and format for `DeclarationListC` types.
224225
impl fmt::Display for DeclarationListC {
225226
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
226-
let mut display = String::new();
227227
for decl in &self.decls {
228-
display += &format!("{decl}");
228+
write!(f, "{decl}")?;
229229
}
230-
write!(f, "{display}")
230+
Ok(())
231231
}
232232
}
233233

@@ -330,7 +330,7 @@ impl Arbitrary for ArrayDimensionC {
330330

331331
for _ in 1..dimensions {
332332
// 16 is an arbitrary "not too big" number for capping array size.
333-
def += &format!("[{}]", gen_range(g, lower_bound, 16));
333+
let _ = write!(def, "[{}]", gen_range(g, lower_bound, 16));
334334
}
335335
ArrayDimensionC { def }
336336
}
@@ -347,7 +347,7 @@ impl fmt::Display for ArrayDimensionC {
347347
/// identifiers unique.
348348
impl MakeUnique for BasicTypeDeclarationC {
349349
fn make_unique(&mut self, stamp: usize) {
350-
self.ident_id += &format!("_{stamp}");
350+
let _ = write!(self.ident_id, "_{stamp}");
351351
}
352352
}
353353

@@ -384,7 +384,7 @@ impl fmt::Display for BasicTypeDeclarationC {
384384
/// identifiers unique.
385385
impl MakeUnique for StructDeclarationC {
386386
fn make_unique(&mut self, stamp: usize) {
387-
self.ident_id += &format!("_{stamp}");
387+
let _ = write!(self.ident_id, "_{stamp}");
388388
}
389389
}
390390

@@ -432,7 +432,7 @@ impl fmt::Display for StructDeclarationC {
432432
/// identifiers unique.
433433
impl MakeUnique for UnionDeclarationC {
434434
fn make_unique(&mut self, stamp: usize) {
435-
self.ident_id += &format!("_{stamp}");
435+
let _ = write!(self.ident_id, "_{stamp}");
436436
}
437437
}
438438

@@ -480,7 +480,7 @@ impl fmt::Display for UnionDeclarationC {
480480
/// `FunctionPointerDeclarationC` identifiers unique.
481481
impl MakeUnique for FunctionPointerDeclarationC {
482482
fn make_unique(&mut self, stamp: usize) {
483-
self.ident_id += &format!("_{stamp}");
483+
let _ = write!(self.ident_id, "_{stamp}");
484484
}
485485
}
486486

@@ -517,7 +517,7 @@ impl fmt::Display for FunctionPointerDeclarationC {
517517
/// identifiers unique.
518518
impl MakeUnique for FunctionPrototypeC {
519519
fn make_unique(&mut self, stamp: usize) {
520-
self.ident_id += &format!("_{stamp}");
520+
let _ = write!(self.ident_id, "_{stamp}");
521521
}
522522
}
523523

@@ -586,14 +586,13 @@ impl Arbitrary for ParameterListC {
586586
/// Enables to string and format for `ParameterListC` types.
587587
impl fmt::Display for ParameterListC {
588588
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
589-
let mut display = String::new();
590589
for (i, p) in self.params.iter().enumerate() {
591590
match i {
592-
0 => display += &format!("{p}"),
593-
_ => display += &format!(",{p}"),
591+
0 => write!(f, "{p}")?,
592+
_ => write!(f, ",{p}")?,
594593
}
595594
}
596-
write!(f, "{display}")
595+
Ok(())
597596
}
598597
}
599598

@@ -612,11 +611,10 @@ impl Arbitrary for HeaderC {
612611
/// Enables to string and format for `HeaderC` types.
613612
impl fmt::Display for HeaderC {
614613
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
615-
let mut display = String::new();
616614
for decl in &self.def.decls {
617-
display += &format!("{decl}");
615+
write!(f, "{decl}")?;
618616
}
619-
write!(f, "{display}")
617+
Ok(())
620618
}
621619
}
622620

Diff for: bindgen-tests/tests/tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn should_overwrite_expected() -> bool {
2727
return true;
2828
}
2929
assert!(
30-
var == "0" || var == "",
30+
var == "0" || var.is_empty(),
3131
"Invalid value of BINDGEN_OVERWRITE_EXPECTED"
3232
);
3333
}
@@ -57,7 +57,7 @@ fn error_diff_mismatch(
5757
if let Some(var) = env::var_os("BINDGEN_TESTS_DIFFTOOL") {
5858
//usecase: var = "meld" -> You can hand check differences
5959
let Some(std::path::Component::Normal(name)) =
60-
filename.components().last()
60+
filename.components().next_back()
6161
else {
6262
panic!("Why is the header variable so weird?")
6363
};
@@ -187,7 +187,7 @@ fn compare_generated_header(
187187
header.display(),
188188
looked_at,
189189
),
190-
};
190+
}
191191

192192
let (builder, roundtrip_builder) = builder.into_builder(check_roundtrip)?;
193193

Diff for: bindgen/codegen/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -3075,7 +3075,7 @@ impl Method {
30753075
parent: parent_id,
30763076
final_name: name.clone(),
30773077
},
3078-
)
3078+
);
30793079
});
30803080

30813081
let mut function_name = function_item.canonical_name(ctx);
@@ -3138,7 +3138,7 @@ impl Method {
31383138
exprs[0] = quote! {
31393139
self
31403140
};
3141-
};
3141+
}
31423142

31433143
let call = quote! {
31443144
#function_name (#( #exprs ),* )
@@ -3282,7 +3282,7 @@ impl FromStr for EnumVariation {
32823282
struct EnumBuilder {
32833283
/// Type identifier of the enum.
32843284
///
3285-
/// This is the base name, i.e. for ModuleConst enums, this does not include the module name.
3285+
/// This is the base name, i.e. for `ModuleConst` enums, this does not include the module name.
32863286
enum_type: Ident,
32873287
/// Attributes applying to the enum type
32883288
attrs: Vec<proc_macro2::TokenStream>,
@@ -3453,7 +3453,7 @@ impl EnumBuilder {
34533453
}
34543454

34553455
fn newtype_bitfield_impl(
3456-
prefix: Ident,
3456+
prefix: &Ident,
34573457
rust_ty: &syn::Type,
34583458
) -> proc_macro2::TokenStream {
34593459
let rust_ty_name = &rust_ty;
@@ -3593,7 +3593,7 @@ impl EnumBuilder {
35933593

35943594
let prefix = ctx.trait_prefix();
35953595
let bitfield_impl_opt = is_bitfield
3596-
.then(|| Self::newtype_bitfield_impl(prefix, rust_ty));
3596+
.then(|| Self::newtype_bitfield_impl(&prefix, rust_ty));
35973597

35983598
quote! {
35993599
// Previously variant impls where before the enum definition.
@@ -4625,7 +4625,7 @@ impl CodeGenerator for Function {
46254625
FunctionKind::Method(ref method_kind) => {
46264626
method_kind.is_pure_virtual()
46274627
}
4628-
_ => false,
4628+
FunctionKind::Function => false,
46294629
};
46304630
if is_pure_virtual && !ctx.options().generate_pure_virtual_functions {
46314631
// Pure virtual methods have no actual symbol, so we can't generate

Diff for: bindgen/codegen/serialize.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ impl<'a> CSerialize<'a> for Type {
368368
match comp_info.kind() {
369369
CompKind::Struct => write!(writer, "struct {name}")?,
370370
CompKind::Union => write!(writer, "union {name}")?,
371-
};
371+
}
372372
}
373373
TypeKind::Enum(_enum_ty) => {
374374
if self.is_const() {
@@ -384,7 +384,7 @@ impl<'a> CSerialize<'a> for Type {
384384
loc: get_loc(item),
385385
})
386386
}
387-
};
387+
}
388388

389389
if !stack.is_empty() {
390390
write!(writer, " ")?;

Diff for: bindgen/codegen/struct_layout.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,11 @@ impl<'a> StructLayoutTracker<'a> {
266266
}
267267
};
268268

269-
if !is_union {
270-
self.latest_offset += field_layout.size;
271-
} else {
269+
if is_union {
272270
self.latest_offset =
273271
cmp::max(self.latest_offset, field_layout.size);
272+
} else {
273+
self.latest_offset += field_layout.size;
274274
}
275275
self.latest_field_layout = Some(field_layout);
276276
self.max_field_align =

Diff for: bindgen/ir/analysis/derive.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl CannotDerive<'_> {
197197
self.derive_trait
198198
);
199199
}
200-
};
200+
}
201201
return layout_can_derive;
202202
}
203203

@@ -355,7 +355,7 @@ impl CannotDerive<'_> {
355355
self.derive_trait
356356
);
357357
}
358-
};
358+
}
359359
return layout_can_derive;
360360
}
361361
}

Diff for: bindgen/ir/comp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1855,7 +1855,7 @@ impl IsOpaque for CompInfo {
18551855
// See https://github.com/rust-lang/rust-bindgen/issues/537 and
18561856
// https://github.com/rust-lang/rust/issues/33158
18571857
if self.is_packed(ctx, layout.as_ref()) &&
1858-
layout.map_or(false, |l| l.align > 1)
1858+
layout.is_some_and(|l| l.align > 1)
18591859
{
18601860
warn!("Found a type that is both packed and aligned to greater than \
18611861
1; Rust before version 1.33 doesn't have `#[repr(packed(N))]`, so we \

Diff for: bindgen/ir/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
931931
*ty.kind()
932932
{
933933
typerefs.push((id, *ty, loc, parent_id));
934-
};
934+
}
935935
}
936936
typerefs
937937
}
@@ -3076,7 +3076,7 @@ impl TemplateParameters for PartialType {
30763076
num_params += 1;
30773077
}
30783078
_ => {}
3079-
};
3079+
}
30803080
clang_sys::CXChildVisit_Continue
30813081
});
30823082
num_params

Diff for: bindgen/ir/item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -727,15 +727,15 @@ impl Item {
727727
to.push_str(&self.canonical_name(ctx));
728728
if let ItemKind::Type(ref ty) = *self.kind() {
729729
if let TypeKind::TemplateInstantiation(ref inst) = *ty.kind() {
730-
to.push_str(&format!("_open{level}_"));
730+
let _ = write!(to, "_open{level}_");
731731
for arg in inst.template_arguments() {
732732
arg.into_resolver()
733733
.through_type_refs()
734734
.resolve(ctx)
735735
.push_disambiguated_name(ctx, to, level + 1);
736736
to.push('_');
737737
}
738-
to.push_str(&format!("close{level}"));
738+
let _ = write!(to, "close{level}");
739739
}
740740
}
741741
}

Diff for: bindgen/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ impl BindgenOptions {
575575
self.parse_callbacks
576576
.iter()
577577
.filter_map(|cb| f(cb.as_ref()))
578-
.last()
578+
.next_back()
579579
}
580580

581581
fn all_callbacks<T>(
@@ -796,7 +796,7 @@ impl Bindings {
796796
0,
797797
format!("--target={effective_target}").into_boxed_str(),
798798
);
799-
};
799+
}
800800

801801
fn detect_include_paths(options: &mut BindgenOptions) {
802802
if !options.detect_include_paths {
@@ -1209,7 +1209,7 @@ pub fn clang_version() -> ClangVersion {
12091209
};
12101210
}
12111211
}
1212-
};
1212+
}
12131213
ClangVersion {
12141214
parsed: None,
12151215
full: raw_v.clone(),

0 commit comments

Comments
 (0)