Skip to content

Commit 5069909

Browse files
committed
fixup! Fix clippy warnings about variables in format! string
1 parent 367893a commit 5069909

File tree

23 files changed

+139
-179
lines changed

23 files changed

+139
-179
lines changed

extract-generated-code-doc/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl Sections {
2828
if let Some(prev) = previous {
2929
// If the new entry starts with indentation, it belongs to the previous section
3030
if Some(&b' ') == entry.as_bytes().first() {
31-
previous = Some(format!("{}\n\n{}", prev, entry));
31+
previous = Some(format!("{prev}\n\n{entry}"));
3232
} else {
3333
vec.push(prev);
3434
previous = Some(entry);

generator/src/generator/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@ fn write_code_header(out: &mut Output) {
169169
fn camel_case_to_snake(arg: &str) -> String {
170170
assert!(
171171
arg.bytes().all(|c| c.is_ascii_alphanumeric() || c == b'_'),
172-
"{:?}",
173-
arg
172+
"{arg:?}"
174173
);
175174

176175
// Matches "[A-Z][a-z0-9]+|[A-Z]+(?![a-z0-9])|[a-z0-9]+"

generator/src/generator/namespace/async_switch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ impl ImplMode {
3131
),
3232
};
3333

34-
format!("{}{}{}", begin, inner, end)
34+
format!("{begin}{inner}{end}")
3535
}
3636
}

generator/src/generator/namespace/expr_to_str.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ fn expr_to_str_impl(
135135
true,
136136
);
137137
if needs_parens {
138-
format!("({} & {})", lhs_str, rhs_str)
138+
format!("({lhs_str} & {rhs_str})")
139139
} else {
140-
format!("{} & {}", lhs_str, rhs_str)
140+
format!("{lhs_str} & {rhs_str}")
141141
}
142142
}
143143
xcbdefs::BinaryOperator::Or => {
@@ -158,9 +158,9 @@ fn expr_to_str_impl(
158158
true,
159159
);
160160
if needs_parens {
161-
format!("({} | {})", lhs_str, rhs_str)
161+
format!("({lhs_str} | {rhs_str})")
162162
} else {
163-
format!("{} | {}", lhs_str, rhs_str)
163+
format!("{lhs_str} | {rhs_str}")
164164
}
165165
}
166166
// I'm not sure know how to handle overflow here,
@@ -179,9 +179,9 @@ fn expr_to_str_impl(
179179
true,
180180
);
181181
if needs_parens {
182-
format!("(!{})", rhs_str)
182+
format!("(!{rhs_str})")
183183
} else {
184-
format!("!{}", rhs_str)
184+
format!("!{rhs_str}")
185185
}
186186
}
187187
},
@@ -195,15 +195,15 @@ fn expr_to_str_impl(
195195
}
196196
};
197197
if let Some(t) = cast_to_type {
198-
format!("{}::from({})", t, value)
198+
format!("{t}::from({value})")
199199
} else {
200200
value
201201
}
202202
}
203203
xcbdefs::Expression::ParamRef(param_ref_expr) => {
204204
let rust_field_name = to_rust_variable_name(&param_ref_expr.field_name);
205205
if let Some(t) = cast_to_type {
206-
format!("{}::from({})", t, rust_field_name)
206+
format!("{t}::from({rust_field_name})")
207207
} else {
208208
rust_field_name
209209
}
@@ -227,7 +227,7 @@ fn expr_to_str_impl(
227227
Some("u32"),
228228
true,
229229
);
230-
format!("{}.count_ones()", arg)
230+
format!("{arg}.count_ones()")
231231
}
232232
xcbdefs::Expression::SumOf(sum_of_expr) => {
233233
// nested sum-of not supported
@@ -272,7 +272,7 @@ fn expr_to_str_impl(
272272
}
273273
xcbdefs::Expression::ListElementRef => {
274274
if let Some(t) = cast_to_type {
275-
format!("{}::from(*x)", t)
275+
format!("{t}::from(*x)")
276276
} else if needs_parens {
277277
"(*x)".into()
278278
} else {
@@ -281,11 +281,11 @@ fn expr_to_str_impl(
281281
}
282282
xcbdefs::Expression::Value(value) => {
283283
let value_str = format_literal_integer(*value);
284-
format!("{}u32", value_str)
284+
format!("{value_str}u32")
285285
}
286286
xcbdefs::Expression::Bit(bit) => {
287287
let value_str = format_literal_integer(1u32 << *bit);
288-
format!("{}u32", value_str)
288+
format!("{value_str}u32")
289289
}
290290
}
291291
}

generator/src/generator/namespace/helpers.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ pub(super) fn to_rust_variable_name(name: &str) -> String {
576576
///
577577
/// If name ends with an underscore, it will be trimmed.
578578
pub(super) fn prefix_var_name(name: &str, prefix: &str) -> String {
579-
let mut prefixed = format!("{}_{}", prefix, name);
579+
let mut prefixed = format!("{prefix}_{name}");
580580
if prefixed.ends_with('_') {
581581
prefixed.truncate(prefixed.len() - 1);
582582
}
@@ -589,9 +589,9 @@ pub(super) fn prefix_var_name(name: &str, prefix: &str) -> String {
589589
/// extra one.
590590
pub(super) fn postfix_var_name(name: &str, postfix: &str) -> String {
591591
if name.ends_with('_') {
592-
format!("{}{}", name, postfix)
592+
format!("{name}{postfix}")
593593
} else {
594-
format!("{}_{}", name, postfix)
594+
format!("{name}_{postfix}")
595595
}
596596
}
597597

generator/src/generator/namespace/mod.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl<'ns, 'c> NamespaceGenerator<'ns, 'c> {
237237
};
238238
self.emit_event_opcode(name, number, event_full_def, out);
239239

240-
let full_name = format!("{}Event", name);
240+
let full_name = format!("{name}Event");
241241

242242
let fields = event_full_def.fields.borrow();
243243
let mut derives = Derives::all();
@@ -346,7 +346,7 @@ impl<'ns, 'c> NamespaceGenerator<'ns, 'c> {
346346
|field_name| {
347347
let rust_field_name = to_rust_variable_name(field_name);
348348
if !deducible_fields.contains_key(field_name) {
349-
format!("input.{}", rust_field_name)
349+
format!("input.{rust_field_name}")
350350
} else {
351351
rust_field_name
352352
}
@@ -536,7 +536,7 @@ impl<'ns, 'c> NamespaceGenerator<'ns, 'c> {
536536
)
537537
};
538538
if let Some(list_length) = list_field.length() {
539-
format!("[{}; {}]", element_type, list_length)
539+
format!("[{element_type}; {list_length}]")
540540
} else {
541541
unreachable!();
542542
}
@@ -956,16 +956,15 @@ impl<'ns, 'c> NamespaceGenerator<'ns, 'c> {
956956
if let xcbdefs::FieldDef::Normal(normal_field) = field {
957957
let rust_type = self.field_value_type_to_rust_type(&normal_field.type_);
958958
let rust_list_field_name = to_rust_variable_name(list_field_name);
959-
let msg = format!("`{}` has too many elements", rust_list_field_name);
959+
let msg = format!("`{rust_list_field_name}` has too many elements");
960960
let list_len = format!("{}.len()", wrap_field_ref(&rust_list_field_name));
961961
let value = match op {
962962
DeducibleLengthFieldOp::None => {
963-
format!("{}::try_from({}).expect(\"{}\")", rust_type, list_len, msg)
963+
format!("{rust_type}::try_from({list_len}).expect(\"{msg}\")")
964964
}
965965
DeducibleLengthFieldOp::Mul(n) => format!(
966-
"{}::try_from({}).ok().and_then(|len| \
967-
len.checked_mul({})).expect(\"{}\")",
968-
rust_type, list_len, n, msg,
966+
"{rust_type}::try_from({list_len}).ok().and_then(|len| \
967+
len.checked_mul({n})).expect(\"{msg}\")"
969968
),
970969
DeducibleLengthFieldOp::Div(n) => {
971970
outln!(
@@ -977,10 +976,7 @@ impl<'ns, 'c> NamespaceGenerator<'ns, 'c> {
977976
rust_list_field_name,
978977
n,
979978
);
980-
format!(
981-
"{}::try_from({} / {}).expect(\"{}\")",
982-
rust_type, list_len, n, msg,
983-
)
979+
format!("{rust_type}::try_from({list_len} / {n}).expect(\"{msg}\")")
984980
}
985981
};
986982
outln!(out, "let {} = {};", dst_var_name, value);
@@ -1123,7 +1119,7 @@ impl<'ns, 'c> NamespaceGenerator<'ns, 'c> {
11231119
// Prevent rustdoc interpreting many leading spaces as code examples (?)
11241120
for line in text.trim().split('\n') {
11251121
let line = line.trim();
1126-
let line = format!("{} {}", prefix_char, line);
1122+
let line = format!("{prefix_char} {line}");
11271123
prefix_char = ' ';
11281124
if line.trim().is_empty() {
11291125
outln!(out, "///");
@@ -1305,7 +1301,7 @@ impl<'ns, 'c> NamespaceGenerator<'ns, 'c> {
13051301
_ => None,
13061302
};
13071303
if let Some(ref type_) = wire_type {
1308-
write!(s, "{}::from(", type_).unwrap();
1304+
write!(s, "{type_}::from(").unwrap();
13091305
}
13101306
s.push_str(&wrap_name(&ext_param.name));
13111307
if wire_type.is_some() {
@@ -1325,9 +1321,9 @@ impl<'ns, 'c> NamespaceGenerator<'ns, 'c> {
13251321
xcbdefs::FieldDef::List(list_field) => {
13261322
let element_type = self.field_value_type_to_rust_type(&list_field.element_type);
13271323
if let Some(list_len) = list_field.length() {
1328-
format!("[{}; {}]", element_type, list_len)
1324+
format!("[{element_type}; {list_len}]")
13291325
} else {
1330-
format!("Vec<{}>", element_type)
1326+
format!("Vec<{element_type}>")
13311327
}
13321328
}
13331329
xcbdefs::FieldDef::Switch(switch_field) => {

generator/src/generator/namespace/parse.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ pub(super) fn emit_field_parse(
129129
);
130130
} else if let Some(list_len) = list_field.length() {
131131
for i in 0..list_len {
132-
let tmp_name = format!("{}_{}", rust_field_name, i);
132+
let tmp_name = format!("{rust_field_name}_{i}");
133133
outln!(
134134
out,
135135
"let ({}_{}, remaining) = {};",
@@ -186,7 +186,7 @@ pub(super) fn emit_field_parse(
186186
xcbdefs::FieldDef::Switch(switch_field) => {
187187
let rust_field_name = to_rust_variable_name(&switch_field.name);
188188
let switch_struct_name = if let FieldContainer::Request(request_name) = container {
189-
format!("{}Aux", request_name)
189+
format!("{request_name}Aux")
190190
} else {
191191
format!("{}{}", switch_prefix, to_rust_type_name(&switch_field.name))
192192
};

0 commit comments

Comments
 (0)