mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
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:
parent
1927c2e1d8
commit
e16c76e3c3
180 changed files with 487 additions and 501 deletions
|
@ -53,7 +53,7 @@ fn render(
|
|||
let (call, escaped_call) = match &func_kind {
|
||||
FuncKind::Method(_, Some(receiver)) => (
|
||||
format!("{}.{}", receiver.unescaped(), name.unescaped()).into(),
|
||||
format!("{}.{}", receiver, name).into(),
|
||||
format!("{receiver}.{name}").into(),
|
||||
),
|
||||
_ => (name.unescaped().to_smol_str(), name.to_smol_str()),
|
||||
};
|
||||
|
@ -162,7 +162,7 @@ pub(super) fn add_call_parens<'b>(
|
|||
cov_mark::hit!(inserts_parens_for_function_calls);
|
||||
|
||||
let (snippet, label_suffix) = if self_param.is_none() && params.is_empty() {
|
||||
(format!("{}()$0", escaped_name), "()")
|
||||
(format!("{escaped_name}()$0"), "()")
|
||||
} else {
|
||||
builder.trigger_call_info();
|
||||
let snippet = if let Some(CallableSnippets::FillArguments) = ctx.config.callable {
|
||||
|
@ -174,7 +174,7 @@ pub(super) fn add_call_parens<'b>(
|
|||
let smol_str = n.to_smol_str();
|
||||
let text = smol_str.as_str().trim_start_matches('_');
|
||||
let ref_ = ref_of_param(ctx, text, param.ty());
|
||||
f(&format_args!("${{{}:{}{}}}", index + offset, ref_, text))
|
||||
f(&format_args!("${{{}:{ref_}{text}}}", index + offset))
|
||||
}
|
||||
None => {
|
||||
let name = match param.ty().as_adt() {
|
||||
|
@ -185,7 +185,7 @@ pub(super) fn add_call_parens<'b>(
|
|||
.map(|s| to_lower_snake_case(s.as_str()))
|
||||
.unwrap_or_else(|| "_".to_string()),
|
||||
};
|
||||
f(&format_args!("${{{}:{}}}", index + offset, name))
|
||||
f(&format_args!("${{{}:{name}}}", index + offset))
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -200,12 +200,12 @@ pub(super) fn add_call_parens<'b>(
|
|||
)
|
||||
}
|
||||
None => {
|
||||
format!("{}({})$0", escaped_name, function_params_snippet)
|
||||
format!("{escaped_name}({function_params_snippet})$0")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cov_mark::hit!(suppress_arg_snippets);
|
||||
format!("{}($0)", escaped_name)
|
||||
format!("{escaped_name}($0)")
|
||||
};
|
||||
|
||||
(snippet, "(…)")
|
||||
|
|
|
@ -66,7 +66,7 @@ fn render(
|
|||
|
||||
match ctx.snippet_cap() {
|
||||
Some(cap) if needs_bang && !has_call_parens => {
|
||||
let snippet = format!("{}!{}$0{}", escaped_name, bra, ket);
|
||||
let snippet = format!("{escaped_name}!{bra}$0{ket}");
|
||||
let lookup = banged_name(&name);
|
||||
item.insert_snippet(cap, snippet).lookup_by(lookup);
|
||||
}
|
||||
|
|
|
@ -35,8 +35,8 @@ pub(crate) fn render_record_lit(
|
|||
});
|
||||
|
||||
RenderedLiteral {
|
||||
literal: format!("{} {{ {} }}", path, completions),
|
||||
detail: format!("{} {{ {} }}", path, types),
|
||||
literal: format!("{path} {{ {completions} }}"),
|
||||
detail: format!("{path} {{ {types} }}"),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ pub(crate) fn render_tuple_lit(
|
|||
path: &str,
|
||||
) -> RenderedLiteral {
|
||||
if snippet_cap.is_none() {
|
||||
return RenderedLiteral { literal: format!("{}", path), detail: format!("{}", path) };
|
||||
return RenderedLiteral { literal: format!("{path}"), detail: format!("{path}") };
|
||||
}
|
||||
let completions = fields.iter().enumerate().format_with(", ", |(idx, _), f| {
|
||||
if snippet_cap.is_some() {
|
||||
|
@ -62,8 +62,8 @@ pub(crate) fn render_tuple_lit(
|
|||
let types = fields.iter().format_with(", ", |field, f| f(&field.ty(db).display(db)));
|
||||
|
||||
RenderedLiteral {
|
||||
literal: format!("{}({})", path, completions),
|
||||
detail: format!("{}({})", path, types),
|
||||
literal: format!("{path}({completions})"),
|
||||
detail: format!("{path}({types})"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue