Skip to content

Commit

Permalink
Inline format args
Browse files Browse the repository at this point in the history
Ran this to auto-inline all format args:

```
cargo clippy --workspace --fix --all-targets -- -A clippy::all -W clippy::uninlined_format_args
```
  • Loading branch information
nyurik authored and emilio committed Nov 30, 2024
1 parent 72e85ef commit dc696e1
Show file tree
Hide file tree
Showing 34 changed files with 162 additions and 201 deletions.
4 changes: 2 additions & 2 deletions bindgen-cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn main() {
if verbose {
print_verbose_err()
}
eprintln!("{}", info);
eprintln!("{info}");
}));

let bindings =
Expand All @@ -48,7 +48,7 @@ pub fn main() {
bindings.write(output).expect("Unable to write output");
}
Err(error) => {
eprintln!("{}", error);
eprintln!("{error}");
std::process::exit(1);
}
};
Expand Down
4 changes: 2 additions & 2 deletions bindgen-integration/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl ParseCallbacks for MacroCallback {
_ => {
// The system might provide lots of functional macros.
// Ensure we did not miss handling one that we meant to handle.
assert!(!name.starts_with("TESTMACRO_"), "name = {}", name);
assert!(!name.starts_with("TESTMACRO_"), "name = {name}");
}
}
}
Expand Down Expand Up @@ -258,7 +258,7 @@ fn setup_wrap_static_fns_test() {
.expect("Unable to generate bindings");

println!("cargo:rustc-link-lib=static=wrap_static_fns"); // tell cargo to link libextern
println!("bindings generated: {}", bindings);
println!("bindings generated: {bindings}");

let obj_path = out_path.join("wrap_static_fns.o");
let lib_path = out_path.join("libwrap_static_fns.a");
Expand Down
4 changes: 2 additions & 2 deletions bindgen-tests/tests/parse_callbacks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl ParseCallbacks for EnumVariantRename {
original_variant_name: &str,
_variant_value: EnumVariantValue,
) -> Option<String> {
Some(format!("RENAMED_{}", original_variant_name))
Some(format!("RENAMED_{original_variant_name}"))
}
}

Expand Down Expand Up @@ -172,7 +172,7 @@ pub fn lookup(cb: &str) -> Box<dyn ParseCallbacks> {
),
})
} else {
panic!("Couldn't find name ParseCallbacks: {}", cb)
panic!("Couldn't find name ParseCallbacks: {cb}")
}
}
}
Expand Down
36 changes: 18 additions & 18 deletions bindgen-tests/tests/quickchecking/src/fuzzers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,11 @@ impl Arbitrary for DeclarationC {
impl fmt::Display for DeclarationC {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
DeclarationC::FunctionPtrDecl(ref d) => write!(f, "{}", d),
DeclarationC::StructDecl(ref d) => write!(f, "{}", d),
DeclarationC::UnionDecl(ref d) => write!(f, "{}", d),
DeclarationC::VariableDecl(ref d) => write!(f, "{}", d),
DeclarationC::FunctionDecl(ref d) => write!(f, "{}", d),
DeclarationC::FunctionPtrDecl(ref d) => write!(f, "{d}"),
DeclarationC::StructDecl(ref d) => write!(f, "{d}"),
DeclarationC::UnionDecl(ref d) => write!(f, "{d}"),
DeclarationC::VariableDecl(ref d) => write!(f, "{d}"),
DeclarationC::FunctionDecl(ref d) => write!(f, "{d}"),
}
}
}
Expand All @@ -225,9 +225,9 @@ impl fmt::Display for DeclarationListC {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut display = String::new();
for decl in &self.decls {
display += &format!("{}", decl);
display += &format!("{decl}");
}
write!(f, "{}", display)
write!(f, "{display}")
}
}

Expand Down Expand Up @@ -347,7 +347,7 @@ impl fmt::Display for ArrayDimensionC {
/// identifiers unique.
impl MakeUnique for BasicTypeDeclarationC {
fn make_unique(&mut self, stamp: usize) {
self.ident_id += &format!("_{}", stamp);
self.ident_id += &format!("_{stamp}");
}
}

Expand Down Expand Up @@ -384,7 +384,7 @@ impl fmt::Display for BasicTypeDeclarationC {
/// identifiers unique.
impl MakeUnique for StructDeclarationC {
fn make_unique(&mut self, stamp: usize) {
self.ident_id += &format!("_{}", stamp);
self.ident_id += &format!("_{stamp}");
}
}

Expand Down Expand Up @@ -432,7 +432,7 @@ impl fmt::Display for StructDeclarationC {
/// identifiers unique.
impl MakeUnique for UnionDeclarationC {
fn make_unique(&mut self, stamp: usize) {
self.ident_id += &format!("_{}", stamp);
self.ident_id += &format!("_{stamp}");
}
}

Expand Down Expand Up @@ -480,7 +480,7 @@ impl fmt::Display for UnionDeclarationC {
/// FunctionPointerDeclarationC identifiers unique.
impl MakeUnique for FunctionPointerDeclarationC {
fn make_unique(&mut self, stamp: usize) {
self.ident_id += &format!("_{}", stamp);
self.ident_id += &format!("_{stamp}");
}
}

Expand Down Expand Up @@ -517,7 +517,7 @@ impl fmt::Display for FunctionPointerDeclarationC {
/// identifiers unique.
impl MakeUnique for FunctionPrototypeC {
fn make_unique(&mut self, stamp: usize) {
self.ident_id += &format!("_{}", stamp);
self.ident_id += &format!("_{stamp}");
}
}

Expand Down Expand Up @@ -589,11 +589,11 @@ impl fmt::Display for ParameterListC {
let mut display = String::new();
for (i, p) in self.params.iter().enumerate() {
match i {
0 => display += &format!("{}", p),
_ => display += &format!(",{}", p),
0 => display += &format!("{p}"),
_ => display += &format!(",{p}"),
}
}
write!(f, "{}", display)
write!(f, "{display}")
}
}

Expand All @@ -614,17 +614,17 @@ impl fmt::Display for HeaderC {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut display = String::new();
for decl in &self.def.decls {
display += &format!("{}", decl);
display += &format!("{decl}");
}
write!(f, "{}", display)
write!(f, "{display}")
}
}

/// Use Display trait for Debug so that any failing property tests report
/// generated C code rather than the data structures that contain it.
impl fmt::Debug for HeaderC {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self)
write!(f, "{self}")
}
}

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 @@ -81,7 +81,7 @@ fn bindgen_prop(header: fuzzers::HeaderC) -> TestResult {
match run_predicate_script(header) {
Ok(o) => TestResult::from_bool(o.status.success()),
Err(e) => {
println!("{:?}", e);
println!("{e:?}");
TestResult::from_bool(false)
}
}
Expand Down
14 changes: 7 additions & 7 deletions bindgen-tests/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ fn error_diff_mismatch(
filename: &Path,
) -> Result<(), Error> {
println!("diff expected generated");
println!("--- expected: {:?}", filename);
println!("--- expected: {filename:?}");
if let Some(header) = header {
println!("+++ generated from: {:?}", header);
println!("+++ generated from: {header:?}");
}

show_diff(expected, actual);
Expand Down Expand Up @@ -153,9 +153,9 @@ fn compare_generated_header(
} else if maj >= 9 {
"9".to_owned()
} else {
format!("{}.{}", maj, min)
format!("{maj}.{min}")
};
expectation.push(format!("libclang-{}", version_str));
expectation.push(format!("libclang-{version_str}"));
}
}
}
Expand Down Expand Up @@ -194,7 +194,7 @@ fn compare_generated_header(
Ok(bindings) => format_code(bindings.to_string()).map_err(|err| {
Error::new(
ErrorKind::Other,
format!("Cannot parse the generated bindings: {}", err),
format!("Cannot parse the generated bindings: {err}"),
)
})?,
Err(_) => "/* error generating bindings */\n".into(),
Expand All @@ -219,7 +219,7 @@ fn compare_generated_header(
if let Err(e) =
compare_generated_header(header, roundtrip_builder, false)
{
return Err(Error::new(ErrorKind::Other, format!("Checking CLI flags roundtrip errored! You probably need to fix Builder::command_line_flags. {}", e)));
return Err(Error::new(ErrorKind::Other, format!("Checking CLI flags roundtrip errored! You probably need to fix Builder::command_line_flags. {e}")));
}
}

Expand Down Expand Up @@ -703,7 +703,7 @@ fn build_flags_output_helper(builder: &bindgen::Builder) {
.map(|x| format!("{}", shlex::try_quote(x).unwrap()))
.collect();
let flags_str = flags_quoted.join(" ");
println!("{}", flags_str);
println!("{flags_str}");

let (builder, _output, _verbose) =
builder_from_flags(command_line_flags.into_iter()).unwrap();
Expand Down
22 changes: 9 additions & 13 deletions bindgen/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,7 @@ impl fmt::Display for SourceLocation {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let (file, line, col, _) = self.location();
if let Some(name) = file.name() {
write!(f, "{}:{}:{}", name, line, col)
write!(f, "{name}:{line}:{col}")
} else {
"builtin definitions".fmt(f)
}
Expand All @@ -1645,7 +1645,7 @@ impl fmt::Display for SourceLocation {

impl fmt::Debug for SourceLocation {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self)
write!(f, "{self}")
}
}

Expand Down Expand Up @@ -2126,15 +2126,15 @@ pub(crate) fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult {
);
}
if let Some(usr) = c.usr() {
print_indent(depth, format!(" {}usr = \"{}\"", prefix, usr));
print_indent(depth, format!(" {prefix}usr = \"{usr}\""));
}
if let Ok(num) = c.num_args() {
print_indent(depth, format!(" {}number-of-args = {}", prefix, num));
print_indent(depth, format!(" {prefix}number-of-args = {num}"));
}
if let Some(num) = c.num_template_args() {
print_indent(
depth,
format!(" {}number-of-template-args = {}", prefix, num),
format!(" {prefix}number-of-template-args = {num}"),
);
}

Expand All @@ -2143,7 +2143,7 @@ pub(crate) fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult {
Some(w) => w.to_string(),
None => "<unevaluable>".to_string(),
};
print_indent(depth, format!(" {}bit-width = {}", prefix, width));
print_indent(depth, format!(" {prefix}bit-width = {width}"));
}

if let Some(ty) = c.enum_type() {
Expand All @@ -2153,7 +2153,7 @@ pub(crate) fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult {
);
}
if let Some(val) = c.enum_val_signed() {
print_indent(depth, format!(" {}enum-val = {}", prefix, val));
print_indent(depth, format!(" {prefix}enum-val = {val}"));
}
if let Some(ty) = c.typedef_type() {
print_indent(
Expand Down Expand Up @@ -2231,16 +2231,12 @@ pub(crate) fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult {
print_indent(
depth,
format!(
" {}number-of-template-args = {}",
prefix, num_template_args
" {prefix}number-of-template-args = {num_template_args}"
),
);
}
if let Some(num) = ty.num_elements() {
print_indent(
depth,
format!(" {}number-of-elements = {}", prefix, num),
);
print_indent(depth, format!(" {prefix}number-of-elements = {num}"));
}
print_indent(
depth,
Expand Down
2 changes: 1 addition & 1 deletion bindgen/codegen/bitfield_unit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn bitfield_unit_get_bit() {
}

println!();
println!("bits = {:?}", bits);
println!("bits = {bits:?}");
assert_eq!(
bits,
&[
Expand Down
5 changes: 2 additions & 3 deletions bindgen/codegen/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ impl fmt::Display for Error {
Error::UnsupportedAbi(abi) => {
write!(
f,
"{} ABI is not supported by the configured Rust target.",
abi
"{abi} ABI is not supported by the configured Rust target."
)
}
Error::InvalidPointerSize { ty_name, ty_size, ptr_size } => {
write!(f, "The {} pointer type has size {} but the current target's pointer size is {}.", ty_name, ty_size, ptr_size)
write!(f, "The {ty_name} pointer type has size {ty_size} but the current target's pointer size is {ptr_size}.")
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions bindgen/codegen/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub(crate) mod attributes {
let name: Cow<'_, str> = if MANGLE {
name.into()
} else {
format!("\u{1}{}", name).into()
format!("\u{1}{name}").into()
};

quote! {
Expand Down Expand Up @@ -375,7 +375,7 @@ pub(crate) mod ast_ty {
None => {
unnamed_arguments += 1;
let name =
ctx.rust_ident(format!("arg{}", unnamed_arguments));
ctx.rust_ident(format!("arg{unnamed_arguments}"));
quote! { #name }
}
})
Expand Down
Loading

0 comments on commit dc696e1

Please sign in to comment.