Skip to content

Commit

Permalink
Inline more format args, spelink
Browse files Browse the repository at this point in the history
* fixed `insantiation` -> `instantiation` in some logging
* inlined a lot of format arg to make them a bit more readable
  • Loading branch information
nyurik authored and pvdrz committed Dec 1, 2024
1 parent 74b2770 commit fab3026
Show file tree
Hide file tree
Showing 33 changed files with 160 additions and 256 deletions.
3 changes: 1 addition & 2 deletions bindgen-tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ pub fn main() {
.to_lowercase();
writeln!(
dst,
"test_header!(header_{}, {:?});",
func,
"test_header!(header_{func}, {:?});",
entry.path(),
)
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion bindgen-tests/tests/parse_callbacks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl ParseCallbacks for PrefixLinkNameParseCallback {
) -> Option<String> {
self.prefix
.as_deref()
.map(|prefix| format!("{}{}", prefix, item_info.name))
.map(|prefix| format!("{prefix}{}", item_info.name))
}
}

Expand Down
2 changes: 1 addition & 1 deletion bindgen-tests/tests/quickchecking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//! let generate_range: usize = 10; // Determines things like the length of
//! // arbitrary vectors generated.
//! let header = fuzzers::HeaderC::arbitrary(&mut Gen::new(generate_range));
//! println!("{}", header);
//! println!("{header}");
//! ```
#![deny(missing_docs)]

Expand Down
2 changes: 1 addition & 1 deletion bindgen-tests/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ macro_rules! test_header {
});

if let Err(err) = result {
panic!("{}", err);
panic!("{err}");
}
}
};
Expand Down
35 changes: 15 additions & 20 deletions bindgen/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ impl ClangToken {
// expressions, so we strip them down here.
CXToken_Comment => return None,
_ => {
warn!("Found unexpected token kind: {:?}", self);
warn!("Found unexpected token kind: {self:?}");
return None;
}
};
Expand Down Expand Up @@ -2090,26 +2090,25 @@ pub(crate) fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult {
let prefix = prefix.as_ref();
print_indent(
depth,
format!(" {}kind = {}", prefix, kind_to_str(c.kind())),
format!(" {prefix}kind = {}", kind_to_str(c.kind())),
);
print_indent(
depth,
format!(" {}spelling = \"{}\"", prefix, c.spelling()),
format!(" {prefix}spelling = \"{}\"", c.spelling()),
);
print_indent(depth, format!(" {}location = {}", prefix, c.location()));
print_indent(depth, format!(" {prefix}location = {}", c.location()));
print_indent(
depth,
format!(" {}is-definition? {}", prefix, c.is_definition()),
format!(" {prefix}is-definition? {}", c.is_definition()),
);
print_indent(
depth,
format!(" {}is-declaration? {}", prefix, c.is_declaration()),
format!(" {prefix}is-declaration? {}", c.is_declaration()),
);
print_indent(
depth,
format!(
" {}is-inlined-function? {}",
prefix,
" {prefix}is-inlined-function? {}",
c.is_inlined_function()
),
);
Expand All @@ -2118,11 +2117,7 @@ pub(crate) fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult {
if templ_kind != CXCursor_NoDeclFound {
print_indent(
depth,
format!(
" {}template-kind = {}",
prefix,
kind_to_str(templ_kind)
),
format!(" {prefix}template-kind = {}", kind_to_str(templ_kind)),
);
}
if let Some(usr) = c.usr() {
Expand All @@ -2149,7 +2144,7 @@ pub(crate) fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult {
if let Some(ty) = c.enum_type() {
print_indent(
depth,
format!(" {}enum-type = {}", prefix, type_to_str(ty.kind())),
format!(" {prefix}enum-type = {}", type_to_str(ty.kind())),
);
}
if let Some(val) = c.enum_val_signed() {
Expand All @@ -2158,13 +2153,13 @@ pub(crate) fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult {
if let Some(ty) = c.typedef_type() {
print_indent(
depth,
format!(" {}typedef-type = {}", prefix, type_to_str(ty.kind())),
format!(" {prefix}typedef-type = {}", type_to_str(ty.kind())),
);
}
if let Some(ty) = c.ret_type() {
print_indent(
depth,
format!(" {}ret-type = {}", prefix, type_to_str(ty.kind())),
format!(" {prefix}ret-type = {}", type_to_str(ty.kind())),
);
}

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

let kind = ty.kind();
print_indent(depth, format!(" {}kind = {}", prefix, type_to_str(kind)));
print_indent(depth, format!(" {prefix}kind = {}", type_to_str(kind)));
if kind == CXType_Invalid {
return;
}

print_indent(depth, format!(" {}cconv = {}", prefix, ty.call_conv()));
print_indent(depth, format!(" {prefix}cconv = {}", ty.call_conv()));

print_indent(
depth,
format!(" {}spelling = \"{}\"", prefix, ty.spelling()),
format!(" {prefix}spelling = \"{}\"", ty.spelling()),
);
let num_template_args =
unsafe { clang_Type_getNumTemplateArguments(ty.x) };
Expand All @@ -2240,7 +2235,7 @@ pub(crate) fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult {
}
print_indent(
depth,
format!(" {}is-variadic? {}", prefix, ty.is_variadic()),
format!(" {prefix}is-variadic? {}", ty.is_variadic()),
);

let canonical = ty.canonical_type();
Expand Down
6 changes: 3 additions & 3 deletions bindgen/codegen/bitfield_unit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ macro_rules! bitfield_unit_get {
let actual = unit.get($start, $len);

println!();
println!("expected = {:064b}", expected);
println!("actual = {:064b}", actual);
println!("expected = {expected:064b}");
println!("actual = {actual:064b}");

assert_eq!(expected, actual);
})*
Expand Down Expand Up @@ -191,7 +191,7 @@ macro_rules! bitfield_unit_set {
println!();
println!("set({}, {}, {:032b}", $start, $len, $val);
println!("expected = {:064b}", $expected);
println!("actual = {:064b}", actual);
println!("actual = {actual:064b}");

assert_eq!($expected, actual);
)*
Expand Down
2 changes: 1 addition & 1 deletion bindgen/codegen/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ pub(crate) mod ast_ty {
return Ok(tokens);
}

warn!("Unknown non-finite float number: {:?}", f);
warn!("Unknown non-finite float number: {f:?}");
Err(())
}

Expand Down
3 changes: 2 additions & 1 deletion bindgen/codegen/impl_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::ir::comp::{BitfieldUnit, CompKind, Field, FieldData, FieldMethods};
use crate::ir::context::BindgenContext;
use crate::ir::item::{HasTypeParamInArray, IsOpaque, Item, ItemCanonicalName};
use crate::ir::ty::{TypeKind, RUST_DERIVE_IN_ARRAY_LIMIT};
use std::fmt::Write as _;

pub(crate) fn gen_debug_impl(
ctx: &BindgenContext,
Expand Down Expand Up @@ -96,7 +97,7 @@ impl ImplDebug<'_> for BitfieldUnit {
}

if let Some(bitfield_name) = bitfield.name() {
format_string.push_str(&format!("{bitfield_name} : {{:?}}"));
let _ = write!(format_string, "{bitfield_name} : {{:?}}");
let getter_name = bitfield.getter_name();
let name_ident = ctx.rust_ident_raw(getter_name);
tokens.push(quote! {
Expand Down
57 changes: 22 additions & 35 deletions bindgen/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ impl Item {
// TODO(emilio, #453): Figure out what to do when this happens
// legitimately, we could track the opaque stuff and disable the
// assertion there I guess.
warn!("Found non-allowlisted item in code generation: {:?}", self);
warn!("Found non-allowlisted item in code generation: {self:?}");
}

result.set_seen(self.id());
Expand All @@ -521,7 +521,7 @@ impl CodeGenerator for Item {
result: &mut CodegenResult<'_>,
_extra: &(),
) {
debug!("<Item as CodeGenerator>::codegen: self = {:?}", self);
debug!("<Item as CodeGenerator>::codegen: self = {self:?}");
if !self.process_before_codegen(ctx, result) {
return;
}
Expand Down Expand Up @@ -553,7 +553,7 @@ impl CodeGenerator for Module {
result: &mut CodegenResult<'_>,
item: &Item,
) {
debug!("<Module as CodeGenerator>::codegen: item = {:?}", item);
debug!("<Module as CodeGenerator>::codegen: item = {item:?}");

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

let canonical_name = item.canonical_name(ctx);
Expand Down Expand Up @@ -829,7 +829,7 @@ impl CodeGenerator for Type {
result: &mut CodegenResult<'_>,
item: &Item,
) {
debug!("<Type as CodeGenerator>::codegen: item = {:?}", item);
debug!("<Type as CodeGenerator>::codegen: item = {item:?}");
debug_assert!(item.is_enabled_for_codegen(ctx));

match *self.kind() {
Expand Down Expand Up @@ -927,16 +927,14 @@ impl CodeGenerator for Type {
assert_eq!(
layout.size,
ctx.target_pointer_size(),
"Target platform requires `--no-size_t-is-usize`. The size of `{}` ({}) does not match the target pointer size ({})",
spelling,
"Target platform requires `--no-size_t-is-usize`. The size of `{spelling}` ({}) does not match the target pointer size ({})",
layout.size,
ctx.target_pointer_size(),
);
assert_eq!(
layout.align,
ctx.target_pointer_size(),
"Target platform requires `--no-size_t-is-usize`. The alignment of `{}` ({}) does not match the target pointer size ({})",
spelling,
"Target platform requires `--no-size_t-is-usize`. The alignment of `{spelling}` ({}) does not match the target pointer size ({})",
layout.align,
ctx.target_pointer_size(),
);
Expand Down Expand Up @@ -1146,7 +1144,7 @@ impl CodeGenerator for Type {
interface.codegen(ctx, result, item)
}
ref u @ TypeKind::UnresolvedTypeRef(..) => {
unreachable!("Should have been resolved after parsing {:?}!", u)
unreachable!("Should have been resolved after parsing {u:?}!")
}
}
}
Expand Down Expand Up @@ -2097,7 +2095,7 @@ impl CodeGenerator for CompInfo {
result: &mut CodegenResult<'_>,
item: &Item,
) {
debug!("<CompInfo as CodeGenerator>::codegen: item = {:?}", item);
debug!("<CompInfo as CodeGenerator>::codegen: item = {item:?}");
debug_assert!(item.is_enabled_for_codegen(ctx));

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

if all_template_params.is_empty() {
Expand Down Expand Up @@ -3544,7 +3539,7 @@ impl CodeGenerator for Enum {
result: &mut CodegenResult<'_>,
item: &Item,
) {
debug!("<Enum as CodeGenerator>::codegen: item = {:?}", item);
debug!("<Enum as CodeGenerator>::codegen: item = {item:?}");
debug_assert!(item.is_enabled_for_codegen(ctx));

let name = item.canonical_name(ctx);
Expand Down Expand Up @@ -3600,8 +3595,7 @@ impl CodeGenerator for Enum {
(false, 8) => IntKind::U64,
_ => {
warn!(
"invalid enum decl: signed: {}, size: {}",
signed, size
"invalid enum decl: signed: {signed}, size: {size}"
);
IntKind::I32
}
Expand Down Expand Up @@ -4355,7 +4349,7 @@ impl TryToRustTy for Type {
Ok(syn::parse_quote! { #name })
}
ref u @ TypeKind::UnresolvedTypeRef(..) => {
unreachable!("Should have been resolved after parsing {:?}!", u)
unreachable!("Should have been resolved after parsing {u:?}!")
}
}
}
Expand Down Expand Up @@ -4487,7 +4481,7 @@ impl CodeGenerator for Function {
result: &mut CodegenResult<'_>,
item: &Item,
) -> Self::Return {
debug!("<Function as CodeGenerator>::codegen: item = {:?}", item);
debug!("<Function as CodeGenerator>::codegen: item = {item:?}");
debug_assert!(item.is_enabled_for_codegen(ctx));

let is_internal = matches!(self.linkage(), Linkage::Internal);
Expand Down Expand Up @@ -4718,10 +4712,8 @@ fn unsupported_abi_diagnostic(
error: &error::Error,
) {
warn!(
"Skipping {}function `{}` because the {}",
"Skipping {}function `{fn_name}` because the {error}",
if variadic { "variadic " } else { "" },
fn_name,
error
);

#[cfg(feature = "experimental")]
Expand All @@ -4731,10 +4723,8 @@ fn unsupported_abi_diagnostic(
let mut diag = Diagnostic::default();
diag.with_title(
format!(
"Skipping {}function `{}` because the {}",
"Skipping {}function `{fn_name}` because the {error}",
if variadic { "variadic " } else { "" },
fn_name,
error
),
Level::Warning,
)
Expand Down Expand Up @@ -4774,8 +4764,7 @@ fn variadic_fn_diagnostic(
_ctx: &BindgenContext,
) {
warn!(
"Cannot generate wrapper for the static variadic function `{}`.",
fn_name,
"Cannot generate wrapper for the static variadic function `{fn_name}`."
);

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

let method_name =
ctx.rust_ident(format!("{}{}", prefix, method.rust_name()));
let method_name = ctx.rust_ident(format!("{prefix}{}", method.rust_name()));

methods.push(quote! {
unsafe fn #method_name #sig where <Self as std::ops::Deref>::Target: objc::Message + Sized {
Expand Down Expand Up @@ -5095,10 +5083,9 @@ pub(crate) fn codegen(
if let Some(path) = context.options().emit_ir_graphviz.as_ref() {
match dot::write_dot_file(context, path) {
Ok(()) => info!(
"Your dot file was generated successfully into: {}",
path
"Your dot file was generated successfully into: {path}"
),
Err(e) => warn!("{}", e),
Err(e) => warn!("{e}"),
}
}

Expand All @@ -5108,7 +5095,7 @@ pub(crate) fn codegen(
"Your depfile was generated successfully into: {}",
spec.depfile_path.display()
),
Err(e) => warn!("{}", e),
Err(e) => warn!("{e}"),
}
}

Expand Down
Loading

0 comments on commit fab3026

Please sign in to comment.