Skip to content

Commit fab3026

Browse files
nyurikpvdrz
authored andcommitted
Inline more format args, spelink
* fixed `insantiation` -> `instantiation` in some logging * inlined a lot of format arg to make them a bit more readable
1 parent 74b2770 commit fab3026

33 files changed

+160
-256
lines changed

bindgen-tests/build.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ pub fn main() {
3535
.to_lowercase();
3636
writeln!(
3737
dst,
38-
"test_header!(header_{}, {:?});",
39-
func,
38+
"test_header!(header_{func}, {:?});",
4039
entry.path(),
4140
)
4241
.unwrap();

bindgen-tests/tests/parse_callbacks/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl ParseCallbacks for PrefixLinkNameParseCallback {
5252
) -> Option<String> {
5353
self.prefix
5454
.as_deref()
55-
.map(|prefix| format!("{}{}", prefix, item_info.name))
55+
.map(|prefix| format!("{prefix}{}", item_info.name))
5656
}
5757
}
5858

bindgen-tests/tests/quickchecking/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//! let generate_range: usize = 10; // Determines things like the length of
1010
//! // arbitrary vectors generated.
1111
//! let header = fuzzers::HeaderC::arbitrary(&mut Gen::new(generate_range));
12-
//! println!("{}", header);
12+
//! println!("{header}");
1313
//! ```
1414
#![deny(missing_docs)]
1515

bindgen-tests/tests/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ macro_rules! test_header {
359359
});
360360

361361
if let Err(err) = result {
362-
panic!("{}", err);
362+
panic!("{err}");
363363
}
364364
}
365365
};

bindgen/clang.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ impl ClangToken {
10661066
// expressions, so we strip them down here.
10671067
CXToken_Comment => return None,
10681068
_ => {
1069-
warn!("Found unexpected token kind: {:?}", self);
1069+
warn!("Found unexpected token kind: {self:?}");
10701070
return None;
10711071
}
10721072
};
@@ -2090,26 +2090,25 @@ pub(crate) fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult {
20902090
let prefix = prefix.as_ref();
20912091
print_indent(
20922092
depth,
2093-
format!(" {}kind = {}", prefix, kind_to_str(c.kind())),
2093+
format!(" {prefix}kind = {}", kind_to_str(c.kind())),
20942094
);
20952095
print_indent(
20962096
depth,
2097-
format!(" {}spelling = \"{}\"", prefix, c.spelling()),
2097+
format!(" {prefix}spelling = \"{}\"", c.spelling()),
20982098
);
2099-
print_indent(depth, format!(" {}location = {}", prefix, c.location()));
2099+
print_indent(depth, format!(" {prefix}location = {}", c.location()));
21002100
print_indent(
21012101
depth,
2102-
format!(" {}is-definition? {}", prefix, c.is_definition()),
2102+
format!(" {prefix}is-definition? {}", c.is_definition()),
21032103
);
21042104
print_indent(
21052105
depth,
2106-
format!(" {}is-declaration? {}", prefix, c.is_declaration()),
2106+
format!(" {prefix}is-declaration? {}", c.is_declaration()),
21072107
);
21082108
print_indent(
21092109
depth,
21102110
format!(
2111-
" {}is-inlined-function? {}",
2112-
prefix,
2111+
" {prefix}is-inlined-function? {}",
21132112
c.is_inlined_function()
21142113
),
21152114
);
@@ -2118,11 +2117,7 @@ pub(crate) fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult {
21182117
if templ_kind != CXCursor_NoDeclFound {
21192118
print_indent(
21202119
depth,
2121-
format!(
2122-
" {}template-kind = {}",
2123-
prefix,
2124-
kind_to_str(templ_kind)
2125-
),
2120+
format!(" {prefix}template-kind = {}", kind_to_str(templ_kind)),
21262121
);
21272122
}
21282123
if let Some(usr) = c.usr() {
@@ -2149,7 +2144,7 @@ pub(crate) fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult {
21492144
if let Some(ty) = c.enum_type() {
21502145
print_indent(
21512146
depth,
2152-
format!(" {}enum-type = {}", prefix, type_to_str(ty.kind())),
2147+
format!(" {prefix}enum-type = {}", type_to_str(ty.kind())),
21532148
);
21542149
}
21552150
if let Some(val) = c.enum_val_signed() {
@@ -2158,13 +2153,13 @@ pub(crate) fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult {
21582153
if let Some(ty) = c.typedef_type() {
21592154
print_indent(
21602155
depth,
2161-
format!(" {}typedef-type = {}", prefix, type_to_str(ty.kind())),
2156+
format!(" {prefix}typedef-type = {}", type_to_str(ty.kind())),
21622157
);
21632158
}
21642159
if let Some(ty) = c.ret_type() {
21652160
print_indent(
21662161
depth,
2167-
format!(" {}ret-type = {}", prefix, type_to_str(ty.kind())),
2162+
format!(" {prefix}ret-type = {}", type_to_str(ty.kind())),
21682163
);
21692164
}
21702165

@@ -2214,16 +2209,16 @@ pub(crate) fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult {
22142209
let prefix = prefix.as_ref();
22152210

22162211
let kind = ty.kind();
2217-
print_indent(depth, format!(" {}kind = {}", prefix, type_to_str(kind)));
2212+
print_indent(depth, format!(" {prefix}kind = {}", type_to_str(kind)));
22182213
if kind == CXType_Invalid {
22192214
return;
22202215
}
22212216

2222-
print_indent(depth, format!(" {}cconv = {}", prefix, ty.call_conv()));
2217+
print_indent(depth, format!(" {prefix}cconv = {}", ty.call_conv()));
22232218

22242219
print_indent(
22252220
depth,
2226-
format!(" {}spelling = \"{}\"", prefix, ty.spelling()),
2221+
format!(" {prefix}spelling = \"{}\"", ty.spelling()),
22272222
);
22282223
let num_template_args =
22292224
unsafe { clang_Type_getNumTemplateArguments(ty.x) };
@@ -2240,7 +2235,7 @@ pub(crate) fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult {
22402235
}
22412236
print_indent(
22422237
depth,
2243-
format!(" {}is-variadic? {}", prefix, ty.is_variadic()),
2238+
format!(" {prefix}is-variadic? {}", ty.is_variadic()),
22442239
);
22452240

22462241
let canonical = ty.canonical_type();

bindgen/codegen/bitfield_unit_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ macro_rules! bitfield_unit_get {
8888
let actual = unit.get($start, $len);
8989

9090
println!();
91-
println!("expected = {:064b}", expected);
92-
println!("actual = {:064b}", actual);
91+
println!("expected = {expected:064b}");
92+
println!("actual = {actual:064b}");
9393

9494
assert_eq!(expected, actual);
9595
})*
@@ -191,7 +191,7 @@ macro_rules! bitfield_unit_set {
191191
println!();
192192
println!("set({}, {}, {:032b}", $start, $len, $val);
193193
println!("expected = {:064b}", $expected);
194-
println!("actual = {:064b}", actual);
194+
println!("actual = {actual:064b}");
195195

196196
assert_eq!($expected, actual);
197197
)*

bindgen/codegen/helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ pub(crate) mod ast_ty {
353353
return Ok(tokens);
354354
}
355355

356-
warn!("Unknown non-finite float number: {:?}", f);
356+
warn!("Unknown non-finite float number: {f:?}");
357357
Err(())
358358
}
359359

bindgen/codegen/impl_debug.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::ir::comp::{BitfieldUnit, CompKind, Field, FieldData, FieldMethods};
22
use crate::ir::context::BindgenContext;
33
use crate::ir::item::{HasTypeParamInArray, IsOpaque, Item, ItemCanonicalName};
44
use crate::ir::ty::{TypeKind, RUST_DERIVE_IN_ARRAY_LIMIT};
5+
use std::fmt::Write as _;
56

67
pub(crate) fn gen_debug_impl(
78
ctx: &BindgenContext,
@@ -96,7 +97,7 @@ impl ImplDebug<'_> for BitfieldUnit {
9697
}
9798

9899
if let Some(bitfield_name) = bitfield.name() {
99-
format_string.push_str(&format!("{bitfield_name} : {{:?}}"));
100+
let _ = write!(format_string, "{bitfield_name} : {{:?}}");
100101
let getter_name = bitfield.getter_name();
101102
let name_ident = ctx.rust_ident_raw(getter_name);
102103
tokens.push(quote! {

bindgen/codegen/mod.rs

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ impl Item {
503503
// TODO(emilio, #453): Figure out what to do when this happens
504504
// legitimately, we could track the opaque stuff and disable the
505505
// assertion there I guess.
506-
warn!("Found non-allowlisted item in code generation: {:?}", self);
506+
warn!("Found non-allowlisted item in code generation: {self:?}");
507507
}
508508

509509
result.set_seen(self.id());
@@ -521,7 +521,7 @@ impl CodeGenerator for Item {
521521
result: &mut CodegenResult<'_>,
522522
_extra: &(),
523523
) {
524-
debug!("<Item as CodeGenerator>::codegen: self = {:?}", self);
524+
debug!("<Item as CodeGenerator>::codegen: self = {self:?}");
525525
if !self.process_before_codegen(ctx, result) {
526526
return;
527527
}
@@ -553,7 +553,7 @@ impl CodeGenerator for Module {
553553
result: &mut CodegenResult<'_>,
554554
item: &Item,
555555
) {
556-
debug!("<Module as CodeGenerator>::codegen: item = {:?}", item);
556+
debug!("<Module as CodeGenerator>::codegen: item = {item:?}");
557557

558558
let codegen_self = |result: &mut CodegenResult,
559559
found_any: &mut bool| {
@@ -652,7 +652,7 @@ impl CodeGenerator for Var {
652652
item: &Item,
653653
) {
654654
use crate::ir::var::VarType;
655-
debug!("<Var as CodeGenerator>::codegen: item = {:?}", item);
655+
debug!("<Var as CodeGenerator>::codegen: item = {item:?}");
656656
debug_assert!(item.is_enabled_for_codegen(ctx));
657657

658658
let canonical_name = item.canonical_name(ctx);
@@ -829,7 +829,7 @@ impl CodeGenerator for Type {
829829
result: &mut CodegenResult<'_>,
830830
item: &Item,
831831
) {
832-
debug!("<Type as CodeGenerator>::codegen: item = {:?}", item);
832+
debug!("<Type as CodeGenerator>::codegen: item = {item:?}");
833833
debug_assert!(item.is_enabled_for_codegen(ctx));
834834

835835
match *self.kind() {
@@ -927,16 +927,14 @@ impl CodeGenerator for Type {
927927
assert_eq!(
928928
layout.size,
929929
ctx.target_pointer_size(),
930-
"Target platform requires `--no-size_t-is-usize`. The size of `{}` ({}) does not match the target pointer size ({})",
931-
spelling,
930+
"Target platform requires `--no-size_t-is-usize`. The size of `{spelling}` ({}) does not match the target pointer size ({})",
932931
layout.size,
933932
ctx.target_pointer_size(),
934933
);
935934
assert_eq!(
936935
layout.align,
937936
ctx.target_pointer_size(),
938-
"Target platform requires `--no-size_t-is-usize`. The alignment of `{}` ({}) does not match the target pointer size ({})",
939-
spelling,
937+
"Target platform requires `--no-size_t-is-usize`. The alignment of `{spelling}` ({}) does not match the target pointer size ({})",
940938
layout.align,
941939
ctx.target_pointer_size(),
942940
);
@@ -1146,7 +1144,7 @@ impl CodeGenerator for Type {
11461144
interface.codegen(ctx, result, item)
11471145
}
11481146
ref u @ TypeKind::UnresolvedTypeRef(..) => {
1149-
unreachable!("Should have been resolved after parsing {:?}!", u)
1147+
unreachable!("Should have been resolved after parsing {u:?}!")
11501148
}
11511149
}
11521150
}
@@ -2097,7 +2095,7 @@ impl CodeGenerator for CompInfo {
20972095
result: &mut CodegenResult<'_>,
20982096
item: &Item,
20992097
) {
2100-
debug!("<CompInfo as CodeGenerator>::codegen: item = {:?}", item);
2098+
debug!("<CompInfo as CodeGenerator>::codegen: item = {item:?}");
21012099
debug_assert!(item.is_enabled_for_codegen(ctx));
21022100

21032101
// Don't output classes with template parameters that aren't types, and
@@ -2531,10 +2529,7 @@ impl CodeGenerator for CompInfo {
25312529
// affect layout, so we're bad and pray to the gods for avoid sending
25322530
// all the tests to shit when parsing things like max_align_t.
25332531
if self.found_unknown_attr() {
2534-
warn!(
2535-
"Type {} has an unknown attribute that may affect layout",
2536-
canonical_ident
2537-
);
2532+
warn!("Type {canonical_ident} has an unknown attribute that may affect layout");
25382533
}
25392534

25402535
if all_template_params.is_empty() {
@@ -3544,7 +3539,7 @@ impl CodeGenerator for Enum {
35443539
result: &mut CodegenResult<'_>,
35453540
item: &Item,
35463541
) {
3547-
debug!("<Enum as CodeGenerator>::codegen: item = {:?}", item);
3542+
debug!("<Enum as CodeGenerator>::codegen: item = {item:?}");
35483543
debug_assert!(item.is_enabled_for_codegen(ctx));
35493544

35503545
let name = item.canonical_name(ctx);
@@ -3600,8 +3595,7 @@ impl CodeGenerator for Enum {
36003595
(false, 8) => IntKind::U64,
36013596
_ => {
36023597
warn!(
3603-
"invalid enum decl: signed: {}, size: {}",
3604-
signed, size
3598+
"invalid enum decl: signed: {signed}, size: {size}"
36053599
);
36063600
IntKind::I32
36073601
}
@@ -4355,7 +4349,7 @@ impl TryToRustTy for Type {
43554349
Ok(syn::parse_quote! { #name })
43564350
}
43574351
ref u @ TypeKind::UnresolvedTypeRef(..) => {
4358-
unreachable!("Should have been resolved after parsing {:?}!", u)
4352+
unreachable!("Should have been resolved after parsing {u:?}!")
43594353
}
43604354
}
43614355
}
@@ -4487,7 +4481,7 @@ impl CodeGenerator for Function {
44874481
result: &mut CodegenResult<'_>,
44884482
item: &Item,
44894483
) -> Self::Return {
4490-
debug!("<Function as CodeGenerator>::codegen: item = {:?}", item);
4484+
debug!("<Function as CodeGenerator>::codegen: item = {item:?}");
44914485
debug_assert!(item.is_enabled_for_codegen(ctx));
44924486

44934487
let is_internal = matches!(self.linkage(), Linkage::Internal);
@@ -4718,10 +4712,8 @@ fn unsupported_abi_diagnostic(
47184712
error: &error::Error,
47194713
) {
47204714
warn!(
4721-
"Skipping {}function `{}` because the {}",
4715+
"Skipping {}function `{fn_name}` because the {error}",
47224716
if variadic { "variadic " } else { "" },
4723-
fn_name,
4724-
error
47254717
);
47264718

47274719
#[cfg(feature = "experimental")]
@@ -4731,10 +4723,8 @@ fn unsupported_abi_diagnostic(
47314723
let mut diag = Diagnostic::default();
47324724
diag.with_title(
47334725
format!(
4734-
"Skipping {}function `{}` because the {}",
4726+
"Skipping {}function `{fn_name}` because the {error}",
47354727
if variadic { "variadic " } else { "" },
4736-
fn_name,
4737-
error
47384728
),
47394729
Level::Warning,
47404730
)
@@ -4774,8 +4764,7 @@ fn variadic_fn_diagnostic(
47744764
_ctx: &BindgenContext,
47754765
) {
47764766
warn!(
4777-
"Cannot generate wrapper for the static variadic function `{}`.",
4778-
fn_name,
4767+
"Cannot generate wrapper for the static variadic function `{fn_name}`."
47794768
);
47804769

47814770
#[cfg(feature = "experimental")]
@@ -4817,7 +4806,7 @@ fn objc_method_codegen(
48174806
// This would ideally resolve the method into an Item, and use
48184807
// Item::process_before_codegen; however, ObjC methods are not currently
48194808
// made into function items.
4820-
let name = format!("{}::{}{}", rust_class_name, prefix, method.rust_name());
4809+
let name = format!("{rust_class_name}::{prefix}{}", method.rust_name());
48214810
if ctx.options().blocklisted_items.matches(name) {
48224811
return;
48234812
}
@@ -4854,8 +4843,7 @@ fn objc_method_codegen(
48544843
ctx.wrap_unsafe_ops(body)
48554844
};
48564845

4857-
let method_name =
4858-
ctx.rust_ident(format!("{}{}", prefix, method.rust_name()));
4846+
let method_name = ctx.rust_ident(format!("{prefix}{}", method.rust_name()));
48594847

48604848
methods.push(quote! {
48614849
unsafe fn #method_name #sig where <Self as std::ops::Deref>::Target: objc::Message + Sized {
@@ -5095,10 +5083,9 @@ pub(crate) fn codegen(
50955083
if let Some(path) = context.options().emit_ir_graphviz.as_ref() {
50965084
match dot::write_dot_file(context, path) {
50975085
Ok(()) => info!(
5098-
"Your dot file was generated successfully into: {}",
5099-
path
5086+
"Your dot file was generated successfully into: {path}"
51005087
),
5101-
Err(e) => warn!("{}", e),
5088+
Err(e) => warn!("{e}"),
51025089
}
51035090
}
51045091

@@ -5108,7 +5095,7 @@ pub(crate) fn codegen(
51085095
"Your depfile was generated successfully into: {}",
51095096
spec.depfile_path.display()
51105097
),
5111-
Err(e) => warn!("{}", e),
5098+
Err(e) => warn!("{e}"),
51125099
}
51135100
}
51145101

0 commit comments

Comments
 (0)