Inline all format arguments where possible

This makes code more readale and concise,
moving all format arguments like `format!("{}", foo)`
into the more compact `format!("{foo}")` form.

The change was automatically created with, so there are far less change
of an accidental typo.

```
cargo clippy --fix -- -A clippy::all -W clippy::uninlined_format_args
```
This commit is contained in:
Yuri Astrakhan 2022-12-23 13:42:58 -05:00
parent 1927c2e1d8
commit e16c76e3c3
180 changed files with 487 additions and 501 deletions

View file

@ -87,7 +87,7 @@ impl IndentLevel {
for token in tokens {
if let Some(ws) = ast::Whitespace::cast(token) {
if ws.text().contains('\n') {
let new_ws = make::tokens::whitespace(&format!("{}{}", ws.syntax(), self));
let new_ws = make::tokens::whitespace(&format!("{}{self}", ws.syntax()));
ted::replace(ws.syntax(), &new_ws);
}
}
@ -103,7 +103,7 @@ impl IndentLevel {
if let Some(ws) = ast::Whitespace::cast(token) {
if ws.text().contains('\n') {
let new_ws = make::tokens::whitespace(
&ws.syntax().text().replace(&format!("\n{}", self), "\n"),
&ws.syntax().text().replace(&format!("\n{self}"), "\n"),
);
ted::replace(ws.syntax(), &new_ws);
}

View file

@ -481,7 +481,7 @@ impl ast::AssocItemList {
},
};
let elements: Vec<SyntaxElement<_>> = vec![
make::tokens::whitespace(&format!("{}{}", whitespace, indent)).into(),
make::tokens::whitespace(&format!("{whitespace}{indent}")).into(),
item.syntax().clone().into(),
];
ted::insert_all(position, elements);
@ -537,7 +537,7 @@ impl ast::MatchArmList {
},
};
let indent = IndentLevel::from_node(self.syntax()) + 1;
elements.push(make::tokens::whitespace(&format!("\n{}", indent)).into());
elements.push(make::tokens::whitespace(&format!("\n{indent}")).into());
elements.push(arm.syntax().clone().into());
if needs_comma(&arm) {
ted::append_child(arm.syntax(), make::token(SyntaxKind::COMMA));
@ -555,7 +555,7 @@ impl ast::RecordExprFieldList {
let is_multiline = self.syntax().text().contains_char('\n');
let whitespace = if is_multiline {
let indent = IndentLevel::from_node(self.syntax()) + 1;
make::tokens::whitespace(&format!("\n{}", indent))
make::tokens::whitespace(&format!("\n{indent}"))
} else {
make::tokens::single_space()
};
@ -616,7 +616,7 @@ impl ast::RecordPatFieldList {
let is_multiline = self.syntax().text().contains_char('\n');
let whitespace = if is_multiline {
let indent = IndentLevel::from_node(self.syntax()) + 1;
make::tokens::whitespace(&format!("\n{}", indent))
make::tokens::whitespace(&format!("\n{indent}"))
} else {
make::tokens::single_space()
};
@ -681,7 +681,7 @@ impl ast::VariantList {
},
};
let elements: Vec<SyntaxElement<_>> = vec![
make::tokens::whitespace(&format!("{}{}", "\n", indent)).into(),
make::tokens::whitespace(&format!("{}{indent}", "\n")).into(),
variant.syntax().clone().into(),
ast::make::token(T![,]).into(),
];
@ -704,11 +704,11 @@ fn normalize_ws_between_braces(node: &SyntaxNode) -> Option<()> {
match l.next_sibling_or_token() {
Some(ws) if ws.kind() == SyntaxKind::WHITESPACE => {
if ws.next_sibling_or_token()?.into_token()? == r {
ted::replace(ws, make::tokens::whitespace(&format!("\n{}", indent)));
ted::replace(ws, make::tokens::whitespace(&format!("\n{indent}")));
}
}
Some(ws) if ws.kind() == T!['}'] => {
ted::insert(Position::after(l), make::tokens::whitespace(&format!("\n{}", indent)));
ted::insert(Position::after(l), make::tokens::whitespace(&format!("\n{indent}")));
}
_ => (),
}

View file

@ -436,9 +436,7 @@ mod tests {
fn check_string_value<'a>(lit: &str, expected: impl Into<Option<&'a str>>) {
assert_eq!(
ast::String { syntax: make::tokens::literal(&format!("\"{}\"", lit)) }
.value()
.as_deref(),
ast::String { syntax: make::tokens::literal(&format!("\"{lit}\"")) }.value().as_deref(),
expected.into()
);
}
@ -461,7 +459,7 @@ bcde", "abcde",
expected: impl Into<Option<&'a [u8; N]>>,
) {
assert_eq!(
ast::ByteString { syntax: make::tokens::literal(&format!("b\"{}\"", lit)) }
ast::ByteString { syntax: make::tokens::literal(&format!("b\"{lit}\"")) }
.value()
.as_deref(),
expected.into().map(|value| &value[..])