mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +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
|
@ -88,7 +88,7 @@ impl FromStr for AssistKind {
|
|||
"RefactorExtract" => Ok(AssistKind::RefactorExtract),
|
||||
"RefactorInline" => Ok(AssistKind::RefactorInline),
|
||||
"RefactorRewrite" => Ok(AssistKind::RefactorRewrite),
|
||||
unknown => Err(format!("Unknown AssistKind: '{}'", unknown)),
|
||||
unknown => Err(format!("Unknown AssistKind: '{unknown}'")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -367,7 +367,7 @@ fn import_for_item(
|
|||
let expected_import_end = if item_as_assoc(db, original_item).is_some() {
|
||||
unresolved_qualifier.to_string()
|
||||
} else {
|
||||
format!("{}::{}", unresolved_qualifier, item_name(db, original_item)?)
|
||||
format!("{unresolved_qualifier}::{}", item_name(db, original_item)?)
|
||||
};
|
||||
if !import_path_string.contains(unresolved_first_segment)
|
||||
|| !import_path_string.ends_with(&expected_import_end)
|
||||
|
|
|
@ -1014,7 +1014,7 @@ fn check_with_config(
|
|||
.and_then(|it| ImportScope::find_insert_use_container(&it, sema))
|
||||
.or_else(|| ImportScope::from(syntax))
|
||||
.unwrap();
|
||||
let path = ast::SourceFile::parse(&format!("use {};", path))
|
||||
let path = ast::SourceFile::parse(&format!("use {path};"))
|
||||
.tree()
|
||||
.syntax()
|
||||
.descendants()
|
||||
|
|
|
@ -197,7 +197,7 @@ fn rename_mod(
|
|||
|
||||
// Module exists in a named file
|
||||
if !is_mod_rs {
|
||||
let path = format!("{}.rs", new_name);
|
||||
let path = format!("{new_name}.rs");
|
||||
let dst = AnchoredPathBuf { anchor, path };
|
||||
source_change.push_file_system_edit(FileSystemEdit::MoveFile { src: anchor, dst })
|
||||
}
|
||||
|
@ -207,9 +207,7 @@ fn rename_mod(
|
|||
// - Module has submodules defined in separate files
|
||||
let dir_paths = match (is_mod_rs, has_detached_child, module.name(sema.db)) {
|
||||
// Go up one level since the anchor is inside the dir we're trying to rename
|
||||
(true, _, Some(mod_name)) => {
|
||||
Some((format!("../{}", mod_name), format!("../{}", new_name)))
|
||||
}
|
||||
(true, _, Some(mod_name)) => Some((format!("../{mod_name}"), format!("../{new_name}"))),
|
||||
// The anchor is on the same level as target dir
|
||||
(false, true, Some(mod_name)) => Some((mod_name.to_string(), new_name.to_string())),
|
||||
_ => None,
|
||||
|
@ -356,7 +354,7 @@ fn source_edit_from_name(edit: &mut TextEditBuilder, name: &ast::Name, new_name:
|
|||
|
||||
// FIXME: instead of splitting the shorthand, recursively trigger a rename of the
|
||||
// other name https://github.com/rust-lang/rust-analyzer/issues/6547
|
||||
edit.insert(ident_pat.syntax().text_range().start(), format!("{}: ", new_name));
|
||||
edit.insert(ident_pat.syntax().text_range().start(), format!("{new_name}: "));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -414,7 +412,7 @@ fn source_edit_from_name_ref(
|
|||
// Foo { field } -> Foo { new_name: field }
|
||||
// ^ insert `new_name: `
|
||||
let offset = name_ref.syntax().text_range().start();
|
||||
edit.insert(offset, format!("{}: ", new_name));
|
||||
edit.insert(offset, format!("{new_name}: "));
|
||||
return true;
|
||||
}
|
||||
(None, Some(_)) if matches!(def, Definition::Local(_)) => {
|
||||
|
@ -422,7 +420,7 @@ fn source_edit_from_name_ref(
|
|||
// Foo { field } -> Foo { field: new_name }
|
||||
// ^ insert `: new_name`
|
||||
let offset = name_ref.syntax().text_range().end();
|
||||
edit.insert(offset, format!(": {}", new_name));
|
||||
edit.insert(offset, format!(": {new_name}"));
|
||||
return true;
|
||||
}
|
||||
_ => (),
|
||||
|
|
|
@ -206,7 +206,7 @@ pub fn world_symbols(db: &RootDatabase, query: Query) -> Vec<FileSymbol> {
|
|||
}
|
||||
|
||||
pub fn crate_symbols(db: &RootDatabase, krate: Crate, query: Query) -> Vec<FileSymbol> {
|
||||
let _p = profile::span("crate_symbols").detail(|| format!("{:?}", query));
|
||||
let _p = profile::span("crate_symbols").detail(|| format!("{query:?}"));
|
||||
|
||||
let modules = krate.modules(db);
|
||||
let indices: Vec<_> = modules
|
||||
|
|
|
@ -205,7 +205,7 @@ mod tests {
|
|||
fn check(input: &str, expect: &Expect) {
|
||||
let (output, exprs) = parse_format_exprs(input).unwrap_or(("-".to_string(), vec![]));
|
||||
let outcome_repr = if !exprs.is_empty() {
|
||||
format!("{}; {}", output, with_placeholders(exprs).join(", "))
|
||||
format!("{output}; {}", with_placeholders(exprs).join(", "))
|
||||
} else {
|
||||
output
|
||||
};
|
||||
|
|
|
@ -241,9 +241,9 @@ fn generate_descriptor_clippy(buf: &mut String, path: &Path) {
|
|||
|
||||
buf.push_str(r#"pub const CLIPPY_LINT_GROUPS: &[LintGroup] = &["#);
|
||||
for (id, children) in clippy_groups {
|
||||
let children = children.iter().map(|id| format!("clippy::{}", id)).collect::<Vec<_>>();
|
||||
let children = children.iter().map(|id| format!("clippy::{id}")).collect::<Vec<_>>();
|
||||
if !children.is_empty() {
|
||||
let lint_ident = format!("clippy::{}", id);
|
||||
let lint_ident = format!("clippy::{id}");
|
||||
let description = format!("lint group for: {}", children.iter().join(", "));
|
||||
push_lint_group(buf, &lint_ident, &description, &children);
|
||||
}
|
||||
|
@ -273,7 +273,7 @@ fn push_lint_group(buf: &mut String, label: &str, description: &str, children: &
|
|||
|
||||
push_lint_completion(buf, label, description);
|
||||
|
||||
let children = format!("&[{}]", children.iter().map(|it| format!("\"{}\"", it)).join(", "));
|
||||
let children = format!("&[{}]", children.iter().map(|it| format!("\"{it}\"")).join(", "));
|
||||
format_to!(
|
||||
buf,
|
||||
r###"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue