From dc696e16239d09cfd783f71f032c3d737eaa361b Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Fri, 29 Nov 2024 18:06:00 -0500 Subject: [PATCH] Inline format args Ran this to auto-inline all format args: ``` cargo clippy --workspace --fix --all-targets -- -A clippy::all -W clippy::uninlined_format_args ``` --- bindgen-cli/main.rs | 4 +- bindgen-integration/build.rs | 4 +- bindgen-tests/tests/parse_callbacks/mod.rs | 4 +- .../tests/quickchecking/src/fuzzers.rs | 36 +++++----- bindgen-tests/tests/quickchecking/src/lib.rs | 2 +- bindgen-tests/tests/tests.rs | 14 ++-- bindgen/clang.rs | 22 +++--- bindgen/codegen/bitfield_unit_tests.rs | 2 +- bindgen/codegen/error.rs | 5 +- bindgen/codegen/helpers.rs | 4 +- bindgen/codegen/impl_debug.rs | 25 +++---- bindgen/codegen/mod.rs | 70 +++++++++---------- bindgen/codegen/serialize.rs | 35 +++++----- bindgen/codegen/struct_layout.rs | 2 +- bindgen/diagnostics.rs | 7 +- bindgen/features.rs | 3 +- bindgen/ir/analysis/has_destructor.rs | 5 +- bindgen/ir/analysis/has_float.rs | 5 +- .../ir/analysis/has_type_param_in_array.rs | 5 +- bindgen/ir/analysis/mod.rs | 4 +- bindgen/ir/annotations.rs | 2 +- bindgen/ir/comp.rs | 4 +- bindgen/ir/context.rs | 12 ++-- bindgen/ir/enum_ty.rs | 2 +- bindgen/ir/function.rs | 11 +-- bindgen/ir/item.rs | 6 +- bindgen/ir/objc.rs | 13 ++-- bindgen/ir/traversal.rs | 3 +- bindgen/ir/ty.rs | 4 +- bindgen/ir/var.rs | 9 +-- bindgen/lib.rs | 27 ++++--- bindgen/options/cli.rs | 6 +- bindgen/options/mod.rs | 2 +- bindgen/regex_set.rs | 4 +- 34 files changed, 162 insertions(+), 201 deletions(-) diff --git a/bindgen-cli/main.rs b/bindgen-cli/main.rs index c15aa00f91..0edf3a84d5 100644 --- a/bindgen-cli/main.rs +++ b/bindgen-cli/main.rs @@ -37,7 +37,7 @@ pub fn main() { if verbose { print_verbose_err() } - eprintln!("{}", info); + eprintln!("{info}"); })); let bindings = @@ -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); } }; diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index 88ba945366..c712569816 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -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}"); } } } @@ -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"); diff --git a/bindgen-tests/tests/parse_callbacks/mod.rs b/bindgen-tests/tests/parse_callbacks/mod.rs index 9f4b04a202..c372ce1057 100644 --- a/bindgen-tests/tests/parse_callbacks/mod.rs +++ b/bindgen-tests/tests/parse_callbacks/mod.rs @@ -66,7 +66,7 @@ impl ParseCallbacks for EnumVariantRename { original_variant_name: &str, _variant_value: EnumVariantValue, ) -> Option { - Some(format!("RENAMED_{}", original_variant_name)) + Some(format!("RENAMED_{original_variant_name}")) } } @@ -172,7 +172,7 @@ pub fn lookup(cb: &str) -> Box { ), }) } else { - panic!("Couldn't find name ParseCallbacks: {}", cb) + panic!("Couldn't find name ParseCallbacks: {cb}") } } } diff --git a/bindgen-tests/tests/quickchecking/src/fuzzers.rs b/bindgen-tests/tests/quickchecking/src/fuzzers.rs index 569ed6e09b..fffe78f8c7 100644 --- a/bindgen-tests/tests/quickchecking/src/fuzzers.rs +++ b/bindgen-tests/tests/quickchecking/src/fuzzers.rs @@ -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}"), } } } @@ -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}") } } @@ -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}"); } } @@ -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}"); } } @@ -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}"); } } @@ -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}"); } } @@ -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}"); } } @@ -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}") } } @@ -614,9 +614,9 @@ 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}") } } @@ -624,7 +624,7 @@ impl fmt::Display for HeaderC { /// 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}") } } diff --git a/bindgen-tests/tests/quickchecking/src/lib.rs b/bindgen-tests/tests/quickchecking/src/lib.rs index c631742ec8..2c33858af2 100644 --- a/bindgen-tests/tests/quickchecking/src/lib.rs +++ b/bindgen-tests/tests/quickchecking/src/lib.rs @@ -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) } } diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs index c008766d72..18262851cd 100644 --- a/bindgen-tests/tests/tests.rs +++ b/bindgen-tests/tests/tests.rs @@ -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); @@ -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}")); } } } @@ -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(), @@ -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}"))); } } @@ -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(); diff --git a/bindgen/clang.rs b/bindgen/clang.rs index d8dc27a562..03af94c8af 100644 --- a/bindgen/clang.rs +++ b/bindgen/clang.rs @@ -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) } @@ -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}") } } @@ -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}"), ); } @@ -2143,7 +2143,7 @@ pub(crate) fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult { Some(w) => w.to_string(), None => "".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() { @@ -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( @@ -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, diff --git a/bindgen/codegen/bitfield_unit_tests.rs b/bindgen/codegen/bitfield_unit_tests.rs index e143e4ea78..12b7204871 100644 --- a/bindgen/codegen/bitfield_unit_tests.rs +++ b/bindgen/codegen/bitfield_unit_tests.rs @@ -33,7 +33,7 @@ fn bitfield_unit_get_bit() { } println!(); - println!("bits = {:?}", bits); + println!("bits = {bits:?}"); assert_eq!( bits, &[ diff --git a/bindgen/codegen/error.rs b/bindgen/codegen/error.rs index 82e921d771..b82ba2aef1 100644 --- a/bindgen/codegen/error.rs +++ b/bindgen/codegen/error.rs @@ -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}.") } } } diff --git a/bindgen/codegen/helpers.rs b/bindgen/codegen/helpers.rs index 4bd08011f9..89665380e7 100644 --- a/bindgen/codegen/helpers.rs +++ b/bindgen/codegen/helpers.rs @@ -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! { @@ -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 } } }) diff --git a/bindgen/codegen/impl_debug.rs b/bindgen/codegen/impl_debug.rs index 87d5d14964..fd4422547e 100644 --- a/bindgen/codegen/impl_debug.rs +++ b/bindgen/codegen/impl_debug.rs @@ -10,7 +10,7 @@ pub(crate) fn gen_debug_impl( kind: CompKind, ) -> proc_macro2::TokenStream { let struct_name = item.canonical_name(ctx); - let mut format_string = format!("{} {{{{ ", struct_name); + let mut format_string = format!("{struct_name} {{{{ "); let mut tokens = vec![]; if item.is_opaque(ctx, &()) { @@ -96,7 +96,7 @@ impl ImplDebug<'_> for BitfieldUnit { } if let Some(bitfield_name) = bitfield.name() { - format_string.push_str(&format!("{} : {{:?}}", bitfield_name)); + format_string.push_str(&format!("{bitfield_name} : {{:?}}")); let getter_name = bitfield.getter_name(); let name_ident = ctx.rust_ident_raw(getter_name); tokens.push(quote! { @@ -137,7 +137,7 @@ impl<'a> ImplDebug<'a> for Item { name_ident: proc_macro2::TokenStream, ) -> Option<(String, Vec)> { Some(( - format!("{}: {{:?}}", name), + format!("{name}: {{:?}}"), vec![quote! { self.#name_ident }], @@ -162,7 +162,7 @@ impl<'a> ImplDebug<'a> for Item { TypeKind::TemplateInstantiation(ref inst) => { if inst.is_opaque(ctx, self) { - Some((format!("{}: opaque", name), vec![])) + Some((format!("{name}: opaque"), vec![])) } else { debug_print(name, quote! { #name_ident }) } @@ -170,16 +170,13 @@ impl<'a> ImplDebug<'a> for Item { // The generic is not required to implement Debug, so we can not debug print that type TypeKind::TypeParam => { - Some((format!("{}: Non-debuggable generic", name), vec![])) + Some((format!("{name}: Non-debuggable generic"), vec![])) } TypeKind::Array(_, len) => { // Generics are not required to implement Debug if self.has_type_param_in_array(ctx) { - Some(( - format!("{}: Array with length {}", name, len), - vec![], - )) + Some((format!("{name}: Array with length {len}"), vec![])) } else if len < RUST_DERIVE_IN_ARRAY_LIMIT || ctx.options().rust_features().larger_arrays { @@ -188,11 +185,11 @@ impl<'a> ImplDebug<'a> for Item { } else if ctx.options().use_core { // There is no String in core; reducing field visibility to avoid breaking // no_std setups. - Some((format!("{}: [...]", name), vec![])) + Some((format!("{name}: [...]"), vec![])) } else { // Let's implement our own print function Some(( - format!("{}: [{{}}]", name), + format!("{name}: [{{}}]"), vec![quote! { self.#name_ident .iter() @@ -207,11 +204,11 @@ impl<'a> ImplDebug<'a> for Item { if ctx.options().use_core { // There is no format! in core; reducing field visibility to avoid breaking // no_std setups. - Some((format!("{}(...)", name), vec![])) + Some((format!("{name}(...)"), vec![])) } else { let self_ids = 0..len; Some(( - format!("{}({{}})", name), + format!("{name}({{}})"), vec![quote! { #(format!("{:?}", self.#self_ids)),* }], @@ -233,7 +230,7 @@ impl<'a> ImplDebug<'a> for Item { TypeKind::Function(ref sig) if !sig.function_pointers_can_derive() => { - Some((format!("{}: FunctionPointer", name), vec![])) + Some((format!("{name}: FunctionPointer"), vec![])) } _ => debug_print(name, quote! { #name_ident }), } diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index b5ec56273e..88809e2fbd 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -82,7 +82,7 @@ impl fmt::Display for CodegenError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::Serialize { msg, loc } => { - write!(f, "serialization error at {}: {}", loc, msg) + write!(f, "serialization error at {loc}: {msg}") } Self::Io(err) => err.fmt(f), } @@ -869,7 +869,7 @@ impl CodeGenerator for Type { { utils::fnsig_block(ctx, fnsig) } else { - panic!("invalid block typedef: {:?}", inner_item) + panic!("invalid block typedef: {inner_item:?}") } }; @@ -1569,9 +1569,9 @@ impl FieldCodegen<'_> for FieldData { return; } - let getter_name = ctx.rust_ident_raw(format!("get_{}", field_name)); + let getter_name = ctx.rust_ident_raw(format!("get_{field_name}")); let mutable_getter_name = - ctx.rust_ident_raw(format!("get_{}_mut", field_name)); + ctx.rust_ident_raw(format!("get_{field_name}_mut")); methods.extend(Some(match accessor_kind { FieldAccessorKind::None => unreachable!(), @@ -2149,7 +2149,7 @@ impl CodeGenerator for CompInfo { generic_param_names.push(ident.clone()); let prefix = ctx.trait_prefix(); - let field_name = ctx.rust_ident(format!("_phantom_{}", idx)); + let field_name = ctx.rust_ident(format!("_phantom_{idx}")); fields.push(quote! { pub #field_name : ::#prefix::marker::PhantomData< ::#prefix::cell::UnsafeCell<#ident> @@ -2403,7 +2403,7 @@ impl CodeGenerator for CompInfo { let packed_repr = if n == 1 { "packed".to_string() } else { - format!("packed({})", n) + format!("packed({n})") }; attributes.push(attributes::repr_list(&["C", &packed_repr])); } else { @@ -3011,7 +3011,7 @@ impl Method { let mut new_name; while { - new_name = format!("{}{}", name, count); + new_name = format!("{name}{count}"); method_names.contains(&new_name) } { count += 1; @@ -3024,7 +3024,7 @@ impl Method { let mut function_name = function_item.canonical_name(ctx); if times_seen > 0 { - write!(&mut function_name, "{}", times_seen).unwrap(); + write!(&mut function_name, "{times_seen}").unwrap(); } let function_name = ctx.rust_ident(function_name); let mut args = utils::fnsig_arguments(ctx, signature); @@ -3387,7 +3387,7 @@ impl<'a> EnumBuilder<'a> { } else { let ident = ctx.rust_ident(match mangling_prefix { Some(prefix) => { - Cow::Owned(format!("{}_{}", prefix, variant_name)) + Cow::Owned(format!("{prefix}_{variant_name}")) } None => variant_name, }); @@ -3403,7 +3403,7 @@ impl<'a> EnumBuilder<'a> { EnumBuilder::Consts { .. } => { let constant_name = match mangling_prefix { Some(prefix) => { - Cow::Owned(format!("{}_{}", prefix, variant_name)) + Cow::Owned(format!("{prefix}_{variant_name}")) } None => variant_name, }; @@ -3711,12 +3711,12 @@ impl CodeGenerator for Enum { ) { let constant_name = if enum_.name().is_some() { if ctx.options().prepend_enum_name { - format!("{}_{}", enum_canonical_name, variant_name) + format!("{enum_canonical_name}_{variant_name}") } else { - format!("{}", variant_name) + format!("{variant_name}") } } else { - format!("{}", variant_name) + format!("{variant_name}") }; let constant_name = ctx.rust_ident(constant_name); @@ -3776,18 +3776,16 @@ impl CodeGenerator for Enum { Entry::Occupied(ref entry) => { if variation.is_rust() { let variant_name = ctx.rust_mangle(variant.name()); - let mangled_name = - if is_toplevel || enum_ty.name().is_some() { - variant_name - } else { - let parent_name = - parent_canonical_name.as_ref().unwrap(); + let mangled_name = if is_toplevel || + enum_ty.name().is_some() + { + variant_name + } else { + let parent_name = + parent_canonical_name.as_ref().unwrap(); - Cow::Owned(format!( - "{}_{}", - parent_name, variant_name - )) - }; + Cow::Owned(format!("{parent_name}_{variant_name}")) + }; let existing_variant_name = entry.get(); // Use associated constants for named enums. @@ -3848,7 +3846,7 @@ impl CodeGenerator for Enum { parent_canonical_name.as_ref().unwrap(); Ident::new( - &format!("{}_{}", parent_name, variant_name), + &format!("{parent_name}_{variant_name}"), Span::call_site(), ) }; @@ -4498,7 +4496,7 @@ impl CodeGenerator for Function { let signature = signature_item.kind().expect_type().canonical_type(ctx); let signature = match *signature.kind() { TypeKind::Function(ref sig) => sig, - _ => panic!("Signature kind is not a Function: {:?}", signature), + _ => panic!("Signature kind is not a Function: {signature:?}"), }; if is_internal { @@ -4590,8 +4588,7 @@ impl CodeGenerator for Function { } Ok(ClangAbi::Unknown(unknown_abi)) => { panic!( - "Invalid or unknown abi {:?} for function {:?} ({:?})", - unknown_abi, canonical_name, self + "Invalid or unknown abi {unknown_abi:?} for function {canonical_name:?} ({self:?})" ); } Ok(abi) => abi, @@ -4601,7 +4598,7 @@ impl CodeGenerator for Function { // suffix. let times_seen = result.overload_number(&canonical_name); if times_seen > 0 { - write!(&mut canonical_name, "{}", times_seen).unwrap(); + write!(&mut canonical_name, "{times_seen}").unwrap(); } let mut has_link_name_attr = false; @@ -4787,7 +4784,7 @@ fn variadic_fn_diagnostic( let mut diag = Diagnostic::default(); - diag.with_title(format!("Cannot generate wrapper for the static function `{}`.", fn_name), Level::Warning) + diag.with_title(format!("Cannot generate wrapper for the static function `{fn_name}`."), Level::Warning) .add_annotation("The `--wrap-static-fns` feature does not support variadic functions.", Level::Note) .add_annotation("No code will be generated for this function.", Level::Note); @@ -5031,8 +5028,7 @@ impl CodeGenerator for ObjCInterface { result.push(from_block); let error_msg = format!( - "This {} cannot be downcasted to {}", - parent_struct_name, child_struct_name + "This {parent_struct_name} cannot be downcasted to {child_struct_name}" ); let try_into_block = quote! { impl std::convert::TryFrom<#parent_struct> for #class_name { @@ -5091,7 +5087,7 @@ pub(crate) fn codegen( let codegen_items = context.codegen_items(); for (id, item) in context.items() { if codegen_items.contains(&id) { - println!("ir: {:?} = {:#?}", id, item); + println!("ir: {id:?} = {item:#?}"); } } } @@ -5190,7 +5186,7 @@ pub(crate) mod utils { if !context.options().input_headers.is_empty() { for header in &context.options().input_headers { - writeln!(code, "#include \"{}\"", header)?; + writeln!(code, "#include \"{header}\"")?; } writeln!(code)?; @@ -5198,7 +5194,7 @@ pub(crate) mod utils { if !context.options().input_header_contents.is_empty() { for (name, contents) in &context.options().input_header_contents { - writeln!(code, "// {}\n{}", name, contents)?; + writeln!(code, "// {name}\n{contents}")?; } writeln!(code)?; @@ -5708,7 +5704,7 @@ pub(crate) mod utils { Some(ref name) => ctx.rust_mangle(name).into_owned(), None => { unnamed_arguments += 1; - format!("arg{}", unnamed_arguments) + format!("arg{unnamed_arguments}") } }; @@ -5752,7 +5748,7 @@ pub(crate) mod utils { Some(ref name) => ctx.rust_mangle(name).into_owned(), None => { unnamed_arguments += 1; - format!("arg{}", unnamed_arguments) + format!("arg{unnamed_arguments}") } }; diff --git a/bindgen/codegen/serialize.rs b/bindgen/codegen/serialize.rs index 19df21e3d5..7f25c28dda 100644 --- a/bindgen/codegen/serialize.rs +++ b/bindgen/codegen/serialize.rs @@ -45,7 +45,7 @@ impl<'a> CSerialize<'a> for Item { func.serialize(ctx, (self, extra), stack, writer) } kind => Err(CodegenError::Serialize { - msg: format!("Cannot serialize item kind {:?}", kind), + msg: format!("Cannot serialize item kind {kind:?}"), loc: get_loc(self), }), } @@ -102,7 +102,7 @@ impl<'a> CSerialize<'a> for Function { } else { Some(( opt_name.unwrap_or_else(|| { - let name = format!("arg_{}", count); + let name = format!("arg_{count}"); count += 1; name }), @@ -131,15 +131,15 @@ impl<'a> CSerialize<'a> for Function { const INDENT: &str = " "; // Write `wrap_name(args`. - write!(writer, " {}(", wrap_name)?; + write!(writer, " {wrap_name}(")?; serialize_args(&args, ctx, writer)?; if wrap_as_variadic.is_none() { // Write `) { name(` if the function returns void and `) { return name(` if it does not. if ret_ty.is_void() { - write!(writer, ") {{ {}(", name)?; + write!(writer, ") {{ {name}(")?; } else { - write!(writer, ") {{ return {}(", name)?; + write!(writer, ") {{ return {name}(")?; } } else { // Write `, ...) {` @@ -165,7 +165,7 @@ impl<'a> CSerialize<'a> for Function { if !ret_ty.is_void() { write!(writer, "ret = ")?; } - write!(writer, "{}(", name)?; + write!(writer, "{name}(")?; } // Get the arguments names and insert at the right place if necessary `ap` @@ -179,7 +179,7 @@ impl<'a> CSerialize<'a> for Function { // Write `arg_names);`. serialize_sep(", ", args.iter(), ctx, writer, |name, _, buf| { - write!(buf, "{}", name).map_err(From::from) + write!(buf, "{name}").map_err(From::from) })?; #[rustfmt::skip] write!(writer, ");{}", if wrap_as_variadic.is_none() { " " } else { "\n" })?; @@ -257,8 +257,7 @@ impl<'a> CSerialize<'a> for Type { int_kind => { return Err(CodegenError::Serialize { msg: format!( - "Cannot serialize integer kind {:?}", - int_kind + "Cannot serialize integer kind {int_kind:?}" ), loc: get_loc(item), }) @@ -294,9 +293,9 @@ impl<'a> CSerialize<'a> for Type { TypeKind::Alias(type_id) => { if let Some(name) = self.name() { if self.is_const() { - write!(writer, "const {}", name)?; + write!(writer, "const {name}")?; } else { - write!(writer, "{}", name)?; + write!(writer, "{name}")?; } } else { type_id.serialize(ctx, (), stack, writer)?; @@ -304,7 +303,7 @@ impl<'a> CSerialize<'a> for Type { } TypeKind::Array(type_id, length) => { type_id.serialize(ctx, (), stack, writer)?; - write!(writer, " [{}]", length)? + write!(writer, " [{length}]")? } TypeKind::Function(signature) => { if self.is_const() { @@ -320,7 +319,7 @@ impl<'a> CSerialize<'a> for Type { write!(writer, " (")?; while let Some(item) = stack.pop() { - write!(writer, "{}", item)?; + write!(writer, "{item}")?; } write!(writer, ")")?; @@ -367,8 +366,8 @@ impl<'a> CSerialize<'a> for Type { let name = item.canonical_name(ctx); match comp_info.kind() { - CompKind::Struct => write!(writer, "struct {}", name)?, - CompKind::Union => write!(writer, "union {}", name)?, + CompKind::Struct => write!(writer, "struct {name}")?, + CompKind::Union => write!(writer, "union {name}")?, }; } TypeKind::Enum(_enum_ty) => { @@ -377,11 +376,11 @@ impl<'a> CSerialize<'a> for Type { } let name = item.canonical_name(ctx); - write!(writer, "enum {}", name)?; + write!(writer, "enum {name}")?; } ty => { return Err(CodegenError::Serialize { - msg: format!("Cannot serialize type kind {:?}", ty), + msg: format!("Cannot serialize type kind {ty:?}"), loc: get_loc(item), }) } @@ -390,7 +389,7 @@ impl<'a> CSerialize<'a> for Type { if !stack.is_empty() { write!(writer, " ")?; while let Some(item) = stack.pop() { - write!(writer, "{}", item)?; + write!(writer, "{item}")?; } } diff --git a/bindgen/codegen/struct_layout.rs b/bindgen/codegen/struct_layout.rs index b78c65e55b..e3235dd84c 100644 --- a/bindgen/codegen/struct_layout.rs +++ b/bindgen/codegen/struct_layout.rs @@ -407,7 +407,7 @@ impl<'a> StructLayoutTracker<'a> { self.padding_count += 1; let padding_field_name = Ident::new( - &format!("__bindgen_padding_{}", padding_count), + &format!("__bindgen_padding_{padding_count}"), Span::call_site(), ); diff --git a/bindgen/diagnostics.rs b/bindgen/diagnostics.rs index e6f169e260..f22402ac0e 100644 --- a/bindgen/diagnostics.rs +++ b/bindgen/diagnostics.rs @@ -93,10 +93,10 @@ impl<'a> Diagnostic<'a> { let hide_warning = "\r \r"; let string = dl.to_string(); for line in string.lines() { - println!("cargo:warning={}{}", hide_warning, line); + println!("cargo:warning={hide_warning}{line}"); } } else { - eprintln!("{}\n", dl); + eprintln!("{dl}\n"); } } } @@ -126,8 +126,7 @@ impl<'a> Slice<'a> { line: usize, col: usize, ) -> &mut Self { - write!(name, ":{}:{}", line, col) - .expect("Writing to a string cannot fail"); + write!(name, ":{line}:{col}").expect("Writing to a string cannot fail"); self.filename = Some(name); self.line = Some(line); self diff --git a/bindgen/features.rs b/bindgen/features.rs index 174491fae0..650c810b0e 100644 --- a/bindgen/features.rs +++ b/bindgen/features.rs @@ -334,8 +334,7 @@ mod test { fn test_invalid_target(input: &str) { assert!( input.parse::().is_err(), - "{} should be an invalid target", - input + "{input} should be an invalid target" ); } diff --git a/bindgen/ir/analysis/has_destructor.rs b/bindgen/ir/analysis/has_destructor.rs index f7b52b4a03..2f5cf1127d 100644 --- a/bindgen/ir/analysis/has_destructor.rs +++ b/bindgen/ir/analysis/has_destructor.rs @@ -58,9 +58,8 @@ impl HasDestructorAnalysis<'_> { let was_not_already_in_set = self.have_destructor.insert(id); assert!( was_not_already_in_set, - "We shouldn't try and insert {:?} twice because if it was \ - already in the set, `constrain` should have exited early.", - id + "We shouldn't try and insert {id:?} twice because if it was \ + already in the set, `constrain` should have exited early." ); ConstrainResult::Changed } diff --git a/bindgen/ir/analysis/has_float.rs b/bindgen/ir/analysis/has_float.rs index f27b4dc5dc..75778ba7f4 100644 --- a/bindgen/ir/analysis/has_float.rs +++ b/bindgen/ir/analysis/has_float.rs @@ -68,9 +68,8 @@ impl HasFloat<'_> { let was_not_already_in_set = self.has_float.insert(id); assert!( was_not_already_in_set, - "We shouldn't try and insert {:?} twice because if it was \ - already in the set, `constrain` should have exited early.", - id + "We shouldn't try and insert {id:?} twice because if it was \ + already in the set, `constrain` should have exited early." ); ConstrainResult::Changed diff --git a/bindgen/ir/analysis/has_type_param_in_array.rs b/bindgen/ir/analysis/has_type_param_in_array.rs index c11f9df82e..2ac378bf75 100644 --- a/bindgen/ir/analysis/has_type_param_in_array.rs +++ b/bindgen/ir/analysis/has_type_param_in_array.rs @@ -74,9 +74,8 @@ impl HasTypeParameterInArray<'_> { self.has_type_parameter_in_array.insert(id); assert!( was_not_already_in_set, - "We shouldn't try and insert {:?} twice because if it was \ - already in the set, `constrain` should have exited early.", - id + "We shouldn't try and insert {id:?} twice because if it was \ + already in the set, `constrain` should have exited early." ); ConstrainResult::Changed diff --git a/bindgen/ir/analysis/mod.rs b/bindgen/ir/analysis/mod.rs index 3dd0780c0e..b40a66ccb9 100644 --- a/bindgen/ir/analysis/mod.rs +++ b/bindgen/ir/analysis/mod.rs @@ -370,7 +370,7 @@ mod tests { fn monotone() { let g = Graph::make_test_graph(); let reachable = analyze::(&g); - println!("reachable = {:#?}", reachable); + println!("reachable = {reachable:#?}"); fn nodes(nodes: A) -> HashSet where @@ -388,7 +388,7 @@ mod tests { expected.insert(Node(6), nodes([8])); expected.insert(Node(7), nodes([3, 4, 5, 6, 7, 8])); expected.insert(Node(8), nodes([])); - println!("expected = {:#?}", expected); + println!("expected = {expected:#?}"); assert_eq!(reachable, expected); } diff --git a/bindgen/ir/annotations.rs b/bindgen/ir/annotations.rs index 12295288c1..70d392f110 100644 --- a/bindgen/ir/annotations.rs +++ b/bindgen/ir/annotations.rs @@ -28,7 +28,7 @@ impl FromStr for FieldVisibilityKind { "private" => Ok(Self::Private), "crate" => Ok(Self::PublicCrate), "public" => Ok(Self::Public), - _ => Err(format!("Invalid visibility kind: `{}`", s)), + _ => Err(format!("Invalid visibility kind: `{s}`")), } } } diff --git a/bindgen/ir/comp.rs b/bindgen/ir/comp.rs index 036e7e5c8f..422f553b64 100644 --- a/bindgen/ir/comp.rs +++ b/bindgen/ir/comp.rs @@ -782,7 +782,7 @@ impl CompFields { getter }; let setter = { - let setter = format!("set_{}", bitfield_name); + let setter = format!("set_{bitfield_name}"); let mut setter = ctx.rust_mangle(&setter).to_string(); if has_method(methods, ctx, &setter) { setter.push_str("_bindgen_bitfield"); @@ -1466,7 +1466,7 @@ impl CompInfo { let field_name = match ci.base_members.len() { 0 => "_base".into(), - n => format!("_base_{}", n), + n => format!("_base_{n}"), }; let type_id = Item::from_ty_or_ref(cur.cur_type(), cur, None, ctx); diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index ccd559e58f..9cdb26c0c8 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -1294,8 +1294,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" }) }) }, - "{:?} should be in some ancestor module's children set", - id + "{id:?} should be in some ancestor module's children set" ); } } @@ -1515,7 +1514,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" let item_id = item_id.into(); match self.resolve_item_fallible(item_id) { Some(item) => item, - None => panic!("Not an item: {:?}", item_id), + None => panic!("Not an item: {item_id:?}"), } } @@ -2035,8 +2034,7 @@ If you encounter an error missing from this list, please file an issue or a PR!" CXType_LongDouble => FloatKind::LongDouble, CXType_Float128 => FloatKind::Float128, _ => panic!( - "Non floating-type complex? {:?}, {:?}", - ty, float_type, + "Non floating-type complex? {ty:?}, {float_type:?}", ), }; TypeKind::Complex(float_kind) @@ -3147,11 +3145,11 @@ fn unused_regex_diagnostic(item: &str, name: &str, _ctx: &BindgenContext) { Diagnostic::default() .with_title( - format!("Unused regular expression: `{}`.", item), + format!("Unused regular expression: `{item}`."), Level::Warning, ) .add_annotation( - format!("This regular expression was passed to `{}`.", name), + format!("This regular expression was passed to `{name}`."), Level::Note, ) .display(); diff --git a/bindgen/ir/enum_ty.rs b/bindgen/ir/enum_ty.rs index 70cf0eae88..8a90cf99a4 100644 --- a/bindgen/ir/enum_ty.rs +++ b/bindgen/ir/enum_ty.rs @@ -79,7 +79,7 @@ impl Enum { let is_signed = variant_ty.map_or(true, |ty| match *ty.kind() { TypeKind::Int(ref int_kind) => int_kind.is_signed(), ref other => { - panic!("Since when enums can be non-integers? {:?}", other) + panic!("Since when enums can be non-integers? {other:?}") } }); diff --git a/bindgen/ir/function.rs b/bindgen/ir/function.rs index 1557843d03..5b6f8196e6 100644 --- a/bindgen/ir/function.rs +++ b/bindgen/ir/function.rs @@ -158,11 +158,7 @@ impl DotAttributes for Function { if let Some(ref mangled) = self.mangled_name { let mangled: String = mangled.chars().flat_map(|c| c.escape_default()).collect(); - writeln!( - out, - "mangled name{}", - mangled - )?; + writeln!(out, "mangled name{mangled}")?; } Ok(()) @@ -209,7 +205,7 @@ impl FromStr for Abi { "win64" => Ok(Self::Win64), "C-unwind" => Ok(Self::CUnwind), "system" => Ok(Self::System), - _ => Err(format!("Invalid or unknown ABI {:?}", s)), + _ => Err(format!("Invalid or unknown ABI {s:?}")), } } } @@ -261,8 +257,7 @@ impl quote::ToTokens for ClangAbi { match *self { Self::Known(abi) => abi.to_tokens(tokens), Self::Unknown(cc) => panic!( - "Cannot turn unknown calling convention to tokens: {:?}", - cc + "Cannot turn unknown calling convention to tokens: {cc:?}" ), } } diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs index 67976c9805..ea82ec5f75 100644 --- a/bindgen/ir/item.rs +++ b/bindgen/ir/item.rs @@ -727,7 +727,7 @@ impl Item { to.push_str(&self.canonical_name(ctx)); if let ItemKind::Type(ref ty) = *self.kind() { if let TypeKind::TemplateInstantiation(ref inst) = *ty.kind() { - to.push_str(&format!("_open{}_", level)); + to.push_str(&format!("_open{level}_")); for arg in inst.template_arguments() { arg.into_resolver() .through_type_refs() @@ -735,7 +735,7 @@ impl Item { .push_disambiguated_name(ctx, to, level + 1); to.push('_'); } - to.push_str(&format!("close{}", level)); + to.push_str(&format!("close{level}")); } } } @@ -801,7 +801,7 @@ impl Item { if let Some(idx) = self.overload_index(ctx) { if idx > 0 { - write!(&mut name, "{}", idx).unwrap(); + write!(&mut name, "{idx}").unwrap(); } } diff --git a/bindgen/ir/objc.rs b/bindgen/ir/objc.rs index d7f7cc65a6..a748d9a171 100644 --- a/bindgen/ir/objc.rs +++ b/bindgen/ir/objc.rs @@ -262,10 +262,7 @@ impl ObjCMethod { // unless it is `crate`, `self`, `super` or `Self`, so we try to add the `_` // suffix to it and parse it. if ["crate", "self", "super", "Self"].contains(&name) { - Some(Ident::new( - &format!("{}_", name), - Span::call_site(), - )) + Some(Ident::new(&format!("{name}_"), Span::call_site())) } else { Some(Ident::new(name, Span::call_site())) } @@ -278,11 +275,11 @@ impl ObjCMethod { Some( syn::parse_str::(name) .or_else(|err| { - syn::parse_str::(&format!("r#{}", name)) + syn::parse_str::(&format!("r#{name}")) .map_err(|_| err) }) .or_else(|err| { - syn::parse_str::(&format!("{}_", name)) + syn::parse_str::(&format!("{name}_")) .map_err(|_| err) }) .expect("Invalid identifier"), @@ -302,9 +299,7 @@ impl ObjCMethod { // Check right amount of arguments assert!( args.len() == split_name.len() - 1, - "Incorrect method name or arguments for objc method, {:?} vs {:?}", - args, - split_name + "Incorrect method name or arguments for objc method, {args:?} vs {split_name:?}" ); // Get arguments without type signatures to pass to `msg_send!` diff --git a/bindgen/ir/traversal.rs b/bindgen/ir/traversal.rs index 17e24f701e..9a0a02b8c4 100644 --- a/bindgen/ir/traversal.rs +++ b/bindgen/ir/traversal.rs @@ -287,8 +287,7 @@ impl<'ctx> TraversalStorage<'ctx> for Paths<'ctx> { } path.reverse(); panic!( - "Found reference to dangling id = {:?}\nvia path = {:?}", - item, path + "Found reference to dangling id = {item:?}\nvia path = {path:?}" ); } diff --git a/bindgen/ir/ty.rs b/bindgen/ir/ty.rs index d527b1c778..8f39a2c388 100644 --- a/bindgen/ir/ty.rs +++ b/bindgen/ir/ty.rs @@ -261,7 +261,7 @@ impl Type { TypeKind::Pointer(inner) => Some((inner, Cow::Borrowed("ptr"))), TypeKind::Reference(inner) => Some((inner, Cow::Borrowed("ref"))), TypeKind::Array(inner, length) => { - Some((inner, format!("array{}", length).into())) + Some((inner, format!("array{length}").into())) } _ => None, }; @@ -269,7 +269,7 @@ impl Type { ctx.resolve_item(inner) .expect_type() .sanitized_name(ctx) - .map(|name| format!("{}_{}", prefix, name).into()) + .map(|name| format!("{prefix}_{name}").into()) } else { self.name().map(Self::sanitize_name) } diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index 01c57704d3..707d14f470 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -113,11 +113,7 @@ impl DotAttributes for Var { } if let Some(ref mangled) = self.mangled_name { - writeln!( - out, - "mangled name{}", - mangled - )?; + writeln!(out, "mangled name{mangled}")?; } Ok(()) @@ -320,8 +316,7 @@ impl ClangSubItemParser for Var { matches!(ty.kind(), CXType_Auto | CXType_Unexposed), "Couldn't resolve constant type, and it \ wasn't an nondeductible auto type or unexposed \ - type: {:?}", - ty + type: {ty:?}" ); return Err(e); } diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 18b5023b1f..2230926293 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -191,7 +191,7 @@ impl FromStr for Formatter { "rustfmt" => Ok(Self::Rustfmt), #[cfg(feature = "prettyplease")] "prettyplease" => Ok(Self::Prettyplease), - _ => Err(format!("`{}` is not a valid formatter", s)), + _ => Err(format!("`{s}` is not a valid formatter")), } } } @@ -627,10 +627,10 @@ impl std::fmt::Display for BindgenError { write!(f, "header '{}' does not exist.", h.display()) } BindgenError::ClangDiagnostic(message) => { - write!(f, "clang diagnosed error: {}", message) + write!(f, "clang diagnosed error: {message}") } BindgenError::Codegen(err) => { - write!(f, "codegen error: {}", err) + write!(f, "codegen error: {err}") } } } @@ -748,7 +748,7 @@ impl Bindings { if !explicit_target && !is_host_build { options.clang_args.insert( 0, - format!("--target={}", effective_target).into_boxed_str(), + format!("--target={effective_target}").into_boxed_str(), ); }; @@ -872,9 +872,7 @@ impl Bindings { debug_assert_eq!( context.target_pointer_size(), std::mem::size_of::<*mut ()>(), - "{:?} {:?}", - effective_target, - HOST_TARGET + "{effective_target:?} {HOST_TARGET:?}" ); } @@ -928,8 +926,7 @@ impl Bindings { } Err(err) => { eprintln!( - "Failed to run rustfmt: {} (non-fatal, continuing)", - err + "Failed to run rustfmt: {err} (non-fatal, continuing)" ); writer.write_all(self.module.to_string().as_bytes())?; } @@ -1097,7 +1094,7 @@ fn parse(context: &mut BindgenContext) -> Result<(), BindgenError> { error.push_str(&msg); error.push('\n'); } else { - eprintln!("clang diag: {}", msg); + eprintln!("clang diag: {msg}"); } } @@ -1183,7 +1180,7 @@ fn get_target_dependent_env_var( var: &str, ) -> Option { if let Ok(target) = env_var(parse_callbacks, "TARGET") { - if let Ok(v) = env_var(parse_callbacks, format!("{}_{}", var, target)) { + if let Ok(v) = env_var(parse_callbacks, format!("{var}_{target}")) { return Some(v); } if let Ok(v) = env_var( @@ -1250,16 +1247,16 @@ impl Default for CargoCallbacks { impl callbacks::ParseCallbacks for CargoCallbacks { fn header_file(&self, filename: &str) { if self.rerun_on_header_files { - println!("cargo:rerun-if-changed={}", filename); + println!("cargo:rerun-if-changed={filename}"); } } fn include_file(&self, filename: &str) { - println!("cargo:rerun-if-changed={}", filename); + println!("cargo:rerun-if-changed={filename}"); } fn read_env_var(&self, key: &str) { - println!("cargo:rerun-if-env-changed={}", key); + println!("cargo:rerun-if-env-changed={key}"); } } @@ -1303,7 +1300,7 @@ fn commandline_flag_unit_test_function() { .iter() .map(|&x| x.into()) .collect::>(); - println!("{:?}", command_line_flags); + println!("{command_line_flags:?}"); assert!(test_cases.iter().all(|x| command_line_flags.contains(x))); } diff --git a/bindgen/options/cli.rs b/bindgen/options/cli.rs index a20ebb1020..c683de178e 100644 --- a/bindgen/options/cli.rs +++ b/bindgen/options/cli.rs @@ -41,7 +41,7 @@ fn parse_codegen_config( otherwise => { return Err(Error::raw( ErrorKind::InvalidValue, - format!("Unknown codegen item kind: {}", otherwise), + format!("Unknown codegen item kind: {otherwise}"), )); } } @@ -688,7 +688,7 @@ where for item in self.regex_set.get_items() { args.extend_from_slice(&[ flag.to_owned(), - format!("{}={}", item, derives), + format!("{item}={derives}"), ]); } @@ -728,7 +728,7 @@ where for item in self.regex_set.get_items() { args.extend_from_slice(&[ flag.to_owned(), - format!("{}={}", item, attributes), + format!("{item}={attributes}"), ]); } diff --git a/bindgen/options/mod.rs b/bindgen/options/mod.rs index 57988e79e6..baac4bcee1 100644 --- a/bindgen/options/mod.rs +++ b/bindgen/options/mod.rs @@ -2013,7 +2013,7 @@ options! { for (abi, set) in overrides { for item in set.get_items() { args.push("--override-abi".to_owned()); - args.push(format!("{}={}", item, abi)); + args.push(format!("{item}={abi}")); } } }, diff --git a/bindgen/regex_set.rs b/bindgen/regex_set.rs index 3375632761..d842af4835 100644 --- a/bindgen/regex_set.rs +++ b/bindgen/regex_set.rs @@ -94,7 +94,7 @@ impl RegexSet { record_matches: bool, _name: Option<&'static str>, ) { - let items = self.items.iter().map(|item| format!("^({})$", item)); + let items = self.items.iter().map(|item| format!("^({item})$")); self.record_matches = record_matches; self.set = match RxSet::new(items) { Ok(x) => Some(x), @@ -189,7 +189,7 @@ fn invalid_regex_warning( } diagnostic.add_annotation( - format!("This regular expression was passed via `{}`.", name), + format!("This regular expression was passed via `{name}`."), Level::Note, );