Skip to content

Commit b44f5ac

Browse files
committed
NFC: inline format args in generate code
CLI `generate` code is a particularly heavy user of format-based macros, and so it benefits most from inlining format args where possible. This is done by adding `#![warn(clippy::uninlined_format_args)]` + running `cargo clippy --fix` followed by `cargo fmt`, so shouldn't require manual review. This is a follow-up to #1142 and, like that PR, is mainly done to make generate's code a bit cleaner and diffs simpler.
1 parent 2085691 commit b44f5ac

File tree

6 files changed

+207
-161
lines changed

6 files changed

+207
-161
lines changed

crates/cli/src/subcommands/generate/csharp.rs

Lines changed: 96 additions & 75 deletions
Large diffs are not rendered by default.

crates/cli/src/subcommands/generate/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![warn(clippy::uninlined_format_args)]
2+
13
use std::fs;
24
use std::io::Write;
35
use std::ops::Deref;

crates/cli/src/subcommands/generate/python.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,9 @@ fn autogen_python_product_table_common(
250250
.expect("autogen'd tuples should have field names")
251251
.replace("r#", "")
252252
.to_case(Case::Snake);
253-
format!("\"{}\"", field_name)
253+
format!("\"{field_name}\"")
254254
}) {
255-
writeln!(output, "primary_key = {}", primary_key);
255+
writeln!(output, "primary_key = {primary_key}");
256256
writeln!(output);
257257
}
258258

@@ -380,7 +380,7 @@ fn autogen_python_product_table_common(
380380
let python_field_name = field_name.to_string().replace("r#", "").to_case(Case::Snake);
381381
match &field.algebraic_type {
382382
AlgebraicType::Sum(sum_type) if sum_type.as_option().is_some() => {
383-
reducer_args.push(format!("{{'0': [self.{}]}}", python_field_name))
383+
reducer_args.push(format!("{{'0': [self.{python_field_name}]}}"))
384384
}
385385
AlgebraicType::Sum(_) => unimplemented!(),
386386
AlgebraicType::Product(_) => {
@@ -393,7 +393,7 @@ fn autogen_python_product_table_common(
393393
let ref_type = &ctx.typespace.types[type_ref.idx()];
394394
if let AlgebraicType::Sum(sum_type) = ref_type {
395395
if sum_type.is_simple_enum() {
396-
reducer_args.push(format!("{{str({}.value): []}}", python_field_name))
396+
reducer_args.push(format!("{{str({python_field_name}.value): []}}"))
397397
} else {
398398
unimplemented!()
399399
}
@@ -405,7 +405,7 @@ fn autogen_python_product_table_common(
405405
}
406406
let reducer_args_str = reducer_args.join(", ");
407407

408-
writeln!(output, "return [{}]", reducer_args_str);
408+
writeln!(output, "return [{reducer_args_str}]");
409409
}
410410
writeln!(output);
411411

0 commit comments

Comments
 (0)