mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42: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
|
@ -13,7 +13,7 @@ pub(crate) fn mismatched_arg_count(
|
|||
d: &hir::MismatchedArgCount,
|
||||
) -> Diagnostic {
|
||||
let s = if d.expected == 1 { "" } else { "s" };
|
||||
let message = format!("expected {} argument{}, found {}", d.expected, s, d.found);
|
||||
let message = format!("expected {} argument{s}, found {}", d.expected, d.found);
|
||||
Diagnostic::new("mismatched-arg-count", message, invalid_args_range(ctx, d))
|
||||
}
|
||||
|
||||
|
|
|
@ -78,13 +78,13 @@ fn missing_record_expr_field_fixes(
|
|||
|
||||
let mut new_field = new_field.to_string();
|
||||
if usage_file_id != def_file_id {
|
||||
new_field = format!("pub(crate) {}", new_field);
|
||||
new_field = format!("pub(crate) {new_field}");
|
||||
}
|
||||
new_field = format!("\n{}{}", indent, new_field);
|
||||
new_field = format!("\n{indent}{new_field}");
|
||||
|
||||
let needs_comma = !last_field_syntax.to_string().ends_with(',');
|
||||
if needs_comma {
|
||||
new_field = format!(",{}", new_field);
|
||||
new_field = format!(",{new_field}");
|
||||
}
|
||||
|
||||
let source_change = SourceChange::from_text_edit(
|
||||
|
|
|
@ -106,11 +106,11 @@ fn add_missing_ok_or_some(
|
|||
}
|
||||
|
||||
let mut builder = TextEdit::builder();
|
||||
builder.insert(expr.syntax().text_range().start(), format!("{}(", variant_name));
|
||||
builder.insert(expr.syntax().text_range().start(), format!("{variant_name}("));
|
||||
builder.insert(expr.syntax().text_range().end(), ")".to_string());
|
||||
let source_change =
|
||||
SourceChange::from_text_edit(d.expr.file_id.original_file(ctx.sema.db), builder.finish());
|
||||
let name = format!("Wrap in {}", variant_name);
|
||||
let name = format!("Wrap in {variant_name}");
|
||||
acc.push(fix("wrap_in_constructor", &name, source_change, expr_range));
|
||||
Some(())
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, file_id: FileId) -> Option<Vec<Assist>> {
|
|||
// `submod/bla.rs` -> `submod.rs`
|
||||
let parent_mod = (|| {
|
||||
let (name, _) = parent.name_and_extension()?;
|
||||
parent.parent()?.join(&format!("{}.rs", name))
|
||||
parent.parent()?.join(&format!("{name}.rs"))
|
||||
})();
|
||||
paths.extend(parent_mod);
|
||||
paths
|
||||
|
@ -99,8 +99,8 @@ fn make_fixes(
|
|||
matches!(item, ast::Item::Module(m) if m.item_list().is_none())
|
||||
}
|
||||
|
||||
let mod_decl = format!("mod {};", new_mod_name);
|
||||
let pub_mod_decl = format!("pub mod {};", new_mod_name);
|
||||
let mod_decl = format!("mod {new_mod_name};");
|
||||
let pub_mod_decl = format!("pub mod {new_mod_name};");
|
||||
|
||||
let ast: ast::SourceFile = db.parse(parent_file_id).tree();
|
||||
|
||||
|
@ -125,8 +125,8 @@ fn make_fixes(
|
|||
Some(last) => {
|
||||
cov_mark::hit!(unlinked_file_append_to_existing_mods);
|
||||
let offset = last.syntax().text_range().end();
|
||||
mod_decl_builder.insert(offset, format!("\n{}", mod_decl));
|
||||
pub_mod_decl_builder.insert(offset, format!("\n{}", pub_mod_decl));
|
||||
mod_decl_builder.insert(offset, format!("\n{mod_decl}"));
|
||||
pub_mod_decl_builder.insert(offset, format!("\n{pub_mod_decl}"));
|
||||
}
|
||||
None => {
|
||||
// Prepend before the first item in the file.
|
||||
|
@ -134,15 +134,15 @@ fn make_fixes(
|
|||
Some(item) => {
|
||||
cov_mark::hit!(unlinked_file_prepend_before_first_item);
|
||||
let offset = item.syntax().text_range().start();
|
||||
mod_decl_builder.insert(offset, format!("{}\n\n", mod_decl));
|
||||
pub_mod_decl_builder.insert(offset, format!("{}\n\n", pub_mod_decl));
|
||||
mod_decl_builder.insert(offset, format!("{mod_decl}\n\n"));
|
||||
pub_mod_decl_builder.insert(offset, format!("{pub_mod_decl}\n\n"));
|
||||
}
|
||||
None => {
|
||||
// No items in the file, so just append at the end.
|
||||
cov_mark::hit!(unlinked_file_empty_file);
|
||||
let offset = ast.syntax().text_range().end();
|
||||
mod_decl_builder.insert(offset, format!("{}\n", mod_decl));
|
||||
pub_mod_decl_builder.insert(offset, format!("{}\n", pub_mod_decl));
|
||||
mod_decl_builder.insert(offset, format!("{mod_decl}\n"));
|
||||
pub_mod_decl_builder.insert(offset, format!("{pub_mod_decl}\n"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -152,13 +152,13 @@ fn make_fixes(
|
|||
Some(vec![
|
||||
fix(
|
||||
"add_mod_declaration",
|
||||
&format!("Insert `{}`", mod_decl),
|
||||
&format!("Insert `{mod_decl}`"),
|
||||
SourceChange::from_text_edit(parent_file_id, mod_decl_builder.finish()),
|
||||
trigger_range,
|
||||
),
|
||||
fix(
|
||||
"add_pub_mod_declaration",
|
||||
&format!("Insert `{}`", pub_mod_decl),
|
||||
&format!("Insert `{pub_mod_decl}`"),
|
||||
SourceChange::from_text_edit(parent_file_id, pub_mod_decl_builder.finish()),
|
||||
trigger_range,
|
||||
),
|
||||
|
|
|
@ -13,7 +13,7 @@ pub(crate) fn unresolved_macro_call(
|
|||
let bang = if d.is_bang { "!" } else { "" };
|
||||
Diagnostic::new(
|
||||
"unresolved-macro-call",
|
||||
format!("unresolved macro `{}{}`", d.path, bang),
|
||||
format!("unresolved macro `{}{bang}`", d.path),
|
||||
display_range,
|
||||
)
|
||||
.experimental()
|
||||
|
|
|
@ -16,7 +16,7 @@ pub(crate) fn unresolved_module(
|
|||
"unresolved-module",
|
||||
match &*d.candidates {
|
||||
[] => "unresolved module".to_string(),
|
||||
[candidate] => format!("unresolved module, can't find module file: {}", candidate),
|
||||
[candidate] => format!("unresolved module, can't find module file: {candidate}"),
|
||||
[candidates @ .., last] => {
|
||||
format!(
|
||||
"unresolved module, can't find module file: {}, or {}",
|
||||
|
|
|
@ -26,7 +26,7 @@ pub(crate) fn unresolved_proc_macro(
|
|||
};
|
||||
|
||||
let message = match &d.macro_name {
|
||||
Some(name) => format!("proc macro `{}` not expanded", name),
|
||||
Some(name) => format!("proc macro `{name}` not expanded"),
|
||||
None => "proc macro not expanded".to_string(),
|
||||
};
|
||||
let severity = if config_enabled { Severity::Error } else { Severity::WeakWarning };
|
||||
|
|
|
@ -218,7 +218,7 @@ pub fn diagnostics(
|
|||
// [#34344] Only take first 128 errors to prevent slowing down editor/ide, the number 128 is chosen arbitrarily.
|
||||
res.extend(
|
||||
parse.errors().iter().take(128).map(|err| {
|
||||
Diagnostic::new("syntax-error", format!("Syntax Error: {}", err), err.range())
|
||||
Diagnostic::new("syntax-error", format!("Syntax Error: {err}"), err.range())
|
||||
}),
|
||||
);
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ pub(crate) fn check_no_fix(ra_fixture: &str) {
|
|||
)
|
||||
.pop()
|
||||
.unwrap();
|
||||
assert!(diagnostic.fixes.is_none(), "got a fix when none was expected: {:?}", diagnostic);
|
||||
assert!(diagnostic.fixes.is_none(), "got a fix when none was expected: {diagnostic:?}");
|
||||
}
|
||||
|
||||
pub(crate) fn check_expect(ra_fixture: &str, expect: Expect) {
|
||||
|
|
|
@ -39,7 +39,7 @@ impl Diagnostic {
|
|||
for block in comment_blocks {
|
||||
let id = block.id;
|
||||
if let Err(msg) = is_valid_diagnostic_name(&id) {
|
||||
panic!("invalid diagnostic name: {:?}:\n {}", id, msg)
|
||||
panic!("invalid diagnostic name: {id:?}:\n {msg}")
|
||||
}
|
||||
let doc = block.contents.join("\n");
|
||||
let location = sourcegen::Location { file: path.clone(), line: block.line };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue