mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +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
|
@ -453,7 +453,7 @@ fn get_doc_base_url(db: &RootDatabase, def: Definition) -> Option<Url> {
|
|||
})?
|
||||
}
|
||||
};
|
||||
Url::parse(&base).ok()?.join(&format!("{}/", display_name)).ok()
|
||||
Url::parse(&base).ok()?.join(&format!("{display_name}/")).ok()
|
||||
}
|
||||
|
||||
/// Get the filename and extension generated for a symbol by rustdoc.
|
||||
|
@ -488,7 +488,7 @@ fn filename_and_frag_for_def(
|
|||
Some(kw) => {
|
||||
format!("keyword.{}.html", kw.trim_matches('"'))
|
||||
}
|
||||
None => format!("{}/index.html", name),
|
||||
None => format!("{name}/index.html"),
|
||||
},
|
||||
None => String::from("index.html"),
|
||||
},
|
||||
|
|
|
@ -63,8 +63,8 @@ mod tests {
|
|||
|
||||
fn check(link: &str, expected: Expect) {
|
||||
let (l, a) = parse_intra_doc_link(link);
|
||||
let a = a.map_or_else(String::new, |a| format!(" ({:?})", a));
|
||||
expected.assert_eq(&format!("{}{}", l, a));
|
||||
let a = a.map_or_else(String::new, |a| format!(" ({a:?})"));
|
||||
expected.assert_eq(&format!("{l}{a}"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -40,7 +40,7 @@ fn check_doc_links(ra_fixture: &str) {
|
|||
.into_iter()
|
||||
.map(|(_, link, ns)| {
|
||||
let def = resolve_doc_path_for_def(sema.db, cursor_def, &link, ns)
|
||||
.unwrap_or_else(|| panic!("Failed to resolve {}", link));
|
||||
.unwrap_or_else(|| panic!("Failed to resolve {link}"));
|
||||
let nav_target = def.try_to_nav(sema.db).unwrap();
|
||||
let range =
|
||||
FileRange { file_id: nav_target.file_id, range: nav_target.focus_or_full_range() };
|
||||
|
|
|
@ -187,7 +187,7 @@ mod tests {
|
|||
let (analysis, position) = fixture::position(ra_fixture);
|
||||
let navs = analysis.goto_definition(position).unwrap().expect("no definition found").info;
|
||||
|
||||
assert!(navs.is_empty(), "didn't expect this to resolve anywhere: {:?}", navs)
|
||||
assert!(navs.is_empty(), "didn't expect this to resolve anywhere: {navs:?}")
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -163,7 +163,7 @@ pub(crate) fn hover(
|
|||
.filter_map(|(def, node)| hover_for_definition(sema, file_id, def, &node, config))
|
||||
.reduce(|mut acc: HoverResult, HoverResult { markup, actions }| {
|
||||
acc.actions.extend(actions);
|
||||
acc.markup = Markup::from(format!("{}\n---\n{}", acc.markup, markup));
|
||||
acc.markup = Markup::from(format!("{}\n---\n{markup}", acc.markup));
|
||||
acc
|
||||
})
|
||||
})
|
||||
|
|
|
@ -417,8 +417,8 @@ pub(super) fn definition(
|
|||
Definition::Variant(it) => label_value_and_docs(db, it, |&it| {
|
||||
if !it.parent_enum(db).is_data_carrying(db) {
|
||||
match it.eval(db) {
|
||||
Ok(x) => Some(format!("{}", x)),
|
||||
Err(_) => it.value(db).map(|x| format!("{:?}", x)),
|
||||
Ok(x) => Some(format!("{x}")),
|
||||
Err(_) => it.value(db).map(|x| format!("{x:?}")),
|
||||
}
|
||||
} else {
|
||||
None
|
||||
|
@ -427,7 +427,7 @@ pub(super) fn definition(
|
|||
Definition::Const(it) => label_value_and_docs(db, it, |it| {
|
||||
let body = it.eval(db);
|
||||
match body {
|
||||
Ok(x) => Some(format!("{}", x)),
|
||||
Ok(x) => Some(format!("{x}")),
|
||||
Err(_) => {
|
||||
let source = it.source(db)?;
|
||||
let mut body = source.value.body()?.syntax().clone();
|
||||
|
@ -483,7 +483,7 @@ pub(super) fn definition(
|
|||
|
||||
fn render_builtin_attr(db: &RootDatabase, attr: hir::BuiltinAttr) -> Option<Markup> {
|
||||
let name = attr.name(db);
|
||||
let desc = format!("#[{}]", name);
|
||||
let desc = format!("#[{name}]");
|
||||
|
||||
let AttributeTemplate { word, list, name_value_str } = match attr.template(db) {
|
||||
Some(template) => template,
|
||||
|
@ -522,7 +522,7 @@ where
|
|||
V: Display,
|
||||
{
|
||||
let label = if let Some(value) = value_extractor(&def) {
|
||||
format!("{} // {}", def.display(db), value)
|
||||
format!("{} // {value}", def.display(db))
|
||||
} else {
|
||||
def.display(db).to_string()
|
||||
};
|
||||
|
@ -541,7 +541,7 @@ where
|
|||
V: Display,
|
||||
{
|
||||
let label = if let Some(value) = value_extractor(&def) {
|
||||
format!("{} = {}", def.display(db), value)
|
||||
format!("{} = {value}", def.display(db))
|
||||
} else {
|
||||
def.display(db).to_string()
|
||||
};
|
||||
|
@ -605,9 +605,9 @@ fn local(db: &RootDatabase, it: hir::Local) -> Option<Markup> {
|
|||
} else {
|
||||
""
|
||||
};
|
||||
format!("{}{}{}: {}", let_kw, is_mut, name, ty)
|
||||
format!("{let_kw}{is_mut}{name}: {ty}")
|
||||
}
|
||||
Either::Right(_) => format!("{}self: {}", is_mut, ty),
|
||||
Either::Right(_) => format!("{is_mut}self: {ty}"),
|
||||
};
|
||||
markup(None, desc, None)
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ fn check(ra_fixture: &str, expect: Expect) {
|
|||
let content = analysis.db.file_text(position.file_id);
|
||||
let hovered_element = &content[hover.range];
|
||||
|
||||
let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
|
||||
let actual = format!("*{hovered_element}*\n{}\n", hover.info.markup);
|
||||
expect.assert_eq(&actual)
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ fn check_hover_no_links(ra_fixture: &str, expect: Expect) {
|
|||
let content = analysis.db.file_text(position.file_id);
|
||||
let hovered_element = &content[hover.range];
|
||||
|
||||
let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
|
||||
let actual = format!("*{hovered_element}*\n{}\n", hover.info.markup);
|
||||
expect.assert_eq(&actual)
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) {
|
|||
let content = analysis.db.file_text(position.file_id);
|
||||
let hovered_element = &content[hover.range];
|
||||
|
||||
let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
|
||||
let actual = format!("*{hovered_element}*\n{}\n", hover.info.markup);
|
||||
expect.assert_eq(&actual)
|
||||
}
|
||||
|
||||
|
|
|
@ -468,7 +468,7 @@ mod tests {
|
|||
.collect::<Vec<_>>();
|
||||
expected.sort_by_key(|(range, _)| range.start());
|
||||
|
||||
assert_eq!(expected, actual, "\nExpected:\n{:#?}\n\nActual:\n{:#?}", expected, actual);
|
||||
assert_eq!(expected, actual, "\nExpected:\n{expected:#?}\n\nActual:\n{actual:#?}");
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
|
|
|
@ -160,7 +160,7 @@ fn is_named_constructor(
|
|||
let ctor_name = match qual_seg.kind()? {
|
||||
ast::PathSegmentKind::Name(name_ref) => {
|
||||
match qual_seg.generic_arg_list().map(|it| it.generic_args()) {
|
||||
Some(generics) => format!("{}<{}>", name_ref, generics.format(", ")),
|
||||
Some(generics) => format!("{name_ref}<{}>", generics.format(", ")),
|
||||
None => name_ref.to_string(),
|
||||
}
|
||||
}
|
||||
|
@ -473,7 +473,7 @@ fn main() {
|
|||
.unwrap();
|
||||
let actual =
|
||||
inlay_hints.into_iter().map(|it| (it.range, it.label.to_string())).collect::<Vec<_>>();
|
||||
assert_eq!(expected, actual, "\nExpected:\n{:#?}\n\nActual:\n{:#?}", expected, actual);
|
||||
assert_eq!(expected, actual, "\nExpected:\n{expected:#?}\n\nActual:\n{actual:#?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -33,6 +33,6 @@ impl Markup {
|
|||
self.text.as_str()
|
||||
}
|
||||
pub fn fenced_block(contents: &impl fmt::Display) -> Markup {
|
||||
format!("```rust\n{}\n```", contents).into()
|
||||
format!("```rust\n{contents}\n```").into()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -273,7 +273,7 @@ mod tests {
|
|||
fn no_moniker(ra_fixture: &str) {
|
||||
let (analysis, position) = fixture::position(ra_fixture);
|
||||
if let Some(x) = analysis.moniker(position).unwrap() {
|
||||
assert_eq!(x.info.len(), 0, "Moniker founded but no moniker expected: {:?}", x);
|
||||
assert_eq!(x.info.len(), 0, "Moniker founded but no moniker expected: {x:?}");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -117,10 +117,10 @@ impl NavigationTarget {
|
|||
self.full_range
|
||||
);
|
||||
if let Some(focus_range) = self.focus_range {
|
||||
buf.push_str(&format!(" {:?}", focus_range))
|
||||
buf.push_str(&format!(" {focus_range:?}"))
|
||||
}
|
||||
if let Some(container_name) = &self.container_name {
|
||||
buf.push_str(&format!(" {}", container_name))
|
||||
buf.push_str(&format!(" {container_name}"))
|
||||
}
|
||||
buf
|
||||
}
|
||||
|
|
|
@ -345,7 +345,7 @@ mod tests {
|
|||
let (analysis, position) = fixture::position(ra_fixture_before);
|
||||
let rename_result = analysis
|
||||
.rename(position, new_name)
|
||||
.unwrap_or_else(|err| panic!("Rename to '{}' was cancelled: {}", new_name, err));
|
||||
.unwrap_or_else(|err| panic!("Rename to '{new_name}' was cancelled: {err}"));
|
||||
match rename_result {
|
||||
Ok(source_change) => {
|
||||
let mut text_edit_builder = TextEdit::builder();
|
||||
|
@ -371,7 +371,7 @@ mod tests {
|
|||
.collect::<String>();
|
||||
assert_eq!(error_message.trim(), err.to_string());
|
||||
} else {
|
||||
panic!("Rename to '{}' failed unexpectedly: {}", new_name, err)
|
||||
panic!("Rename to '{new_name}' failed unexpectedly: {err}")
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -397,11 +397,11 @@ mod tests {
|
|||
let (analysis, position) = fixture::position(ra_fixture);
|
||||
let result = analysis
|
||||
.prepare_rename(position)
|
||||
.unwrap_or_else(|err| panic!("PrepareRename was cancelled: {}", err));
|
||||
.unwrap_or_else(|err| panic!("PrepareRename was cancelled: {err}"));
|
||||
match result {
|
||||
Ok(RangeInfo { range, info: () }) => {
|
||||
let source = analysis.file_text(position.file_id).unwrap();
|
||||
expect.assert_eq(&format!("{:?}: {}", range, &source[range]))
|
||||
expect.assert_eq(&format!("{range:?}: {}", &source[range]))
|
||||
}
|
||||
Err(RenameError(err)) => expect.assert_eq(&err),
|
||||
};
|
||||
|
|
|
@ -66,12 +66,12 @@ impl Runnable {
|
|||
// test package::module::testname
|
||||
pub fn label(&self, target: Option<String>) -> String {
|
||||
match &self.kind {
|
||||
RunnableKind::Test { test_id, .. } => format!("test {}", test_id),
|
||||
RunnableKind::TestMod { path } => format!("test-mod {}", path),
|
||||
RunnableKind::Bench { test_id } => format!("bench {}", test_id),
|
||||
RunnableKind::DocTest { test_id, .. } => format!("doctest {}", test_id),
|
||||
RunnableKind::Test { test_id, .. } => format!("test {test_id}"),
|
||||
RunnableKind::TestMod { path } => format!("test-mod {path}"),
|
||||
RunnableKind::Bench { test_id } => format!("bench {test_id}"),
|
||||
RunnableKind::DocTest { test_id, .. } => format!("doctest {test_id}"),
|
||||
RunnableKind::Bin => {
|
||||
target.map_or_else(|| "run binary".to_string(), |t| format!("run {}", t))
|
||||
target.map_or_else(|| "run binary".to_string(), |t| format!("run {t}"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -377,7 +377,7 @@ pub(crate) fn runnable_impl(
|
|||
} else {
|
||||
String::new()
|
||||
};
|
||||
let mut test_id = format!("{}{}", adt_name, params);
|
||||
let mut test_id = format!("{adt_name}{params}");
|
||||
test_id.retain(|c| c != ' ');
|
||||
let test_id = TestId::Path(test_id);
|
||||
|
||||
|
|
|
@ -233,13 +233,13 @@ mod tests {
|
|||
for (range, _) in f.tokens {
|
||||
let x = FileRange { file_id: f.file_id, range };
|
||||
if !range_set.contains(&x) {
|
||||
panic!("additional range {:?}", x);
|
||||
panic!("additional range {x:?}");
|
||||
}
|
||||
range_set.remove(&x);
|
||||
}
|
||||
}
|
||||
if !range_set.is_empty() {
|
||||
panic!("unfound ranges {:?}", range_set);
|
||||
panic!("unfound ranges {range_set:?}");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -254,13 +254,13 @@ mod tests {
|
|||
continue;
|
||||
}
|
||||
if !range_set.contains(&x) {
|
||||
panic!("additional definition {:?}", x);
|
||||
panic!("additional definition {x:?}");
|
||||
}
|
||||
range_set.remove(&x);
|
||||
}
|
||||
}
|
||||
if !range_set.is_empty() {
|
||||
panic!("unfound definitions {:?}", range_set);
|
||||
panic!("unfound definitions {range_set:?}");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,8 +52,8 @@ pub(crate) fn status(db: &RootDatabase, file_id: Option<FileId>) -> String {
|
|||
let crate_graph = db.crate_graph();
|
||||
for krate in crates {
|
||||
let display_crate = |krate: CrateId| match &crate_graph[krate].display_name {
|
||||
Some(it) => format!("{}({:?})", it, krate),
|
||||
None => format!("{:?}", krate),
|
||||
Some(it) => format!("{it}({krate:?})"),
|
||||
None => format!("{krate:?}"),
|
||||
};
|
||||
format_to!(buf, "Crate: {}\n", display_crate(krate));
|
||||
let deps = crate_graph[krate]
|
||||
|
|
|
@ -52,7 +52,7 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo
|
|||
let class = r.highlight.to_string().replace('.', " ");
|
||||
let color = match (rainbow, r.binding_hash) {
|
||||
(true, Some(hash)) => {
|
||||
format!(" data-binding-hash=\"{}\" style=\"color: {};\"", hash, rainbowify(hash))
|
||||
format!(" data-binding-hash=\"{hash}\" style=\"color: {};\"", rainbowify(hash))
|
||||
}
|
||||
_ => "".into(),
|
||||
};
|
||||
|
|
|
@ -32,7 +32,7 @@ pub(crate) fn syntax_tree(
|
|||
}
|
||||
};
|
||||
|
||||
format!("{:#?}", node)
|
||||
format!("{node:#?}")
|
||||
} else {
|
||||
format!("{:#?}", parse.tree().syntax())
|
||||
}
|
||||
|
|
|
@ -397,7 +397,7 @@ mod tests {
|
|||
|
||||
fn type_char(char_typed: char, ra_fixture_before: &str, ra_fixture_after: &str) {
|
||||
let actual = do_type_char(char_typed, ra_fixture_before)
|
||||
.unwrap_or_else(|| panic!("typing `{}` did nothing", char_typed));
|
||||
.unwrap_or_else(|| panic!("typing `{char_typed}` did nothing"));
|
||||
|
||||
assert_eq_text!(ra_fixture_after, &actual);
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@ fn on_enter_in_comment(
|
|||
}
|
||||
|
||||
let indent = node_indent(file, comment.syntax())?;
|
||||
let inserted = format!("\n{}{} $0", indent, prefix);
|
||||
let inserted = format!("\n{indent}{prefix} $0");
|
||||
let delete = if remove_trailing_whitespace {
|
||||
let trimmed_len = comment.text().trim_end().len() as u32;
|
||||
let trailing_whitespace_len = comment.text().len() as u32 - trimmed_len;
|
||||
|
@ -129,7 +129,7 @@ fn on_enter_in_block(block: ast::BlockExpr, position: FilePosition) -> Option<Te
|
|||
|
||||
let indent = IndentLevel::from_node(block.syntax());
|
||||
let mut edit = TextEdit::insert(position.offset, format!("\n{}$0", indent + 1));
|
||||
edit.union(TextEdit::insert(contents.text_range().end(), format!("\n{}", indent))).ok()?;
|
||||
edit.union(TextEdit::insert(contents.text_range().end(), format!("\n{indent}"))).ok()?;
|
||||
Some(edit)
|
||||
}
|
||||
|
||||
|
@ -140,11 +140,8 @@ fn on_enter_in_use_tree_list(list: ast::UseTreeList, position: FilePosition) ->
|
|||
|
||||
let indent = IndentLevel::from_node(list.syntax());
|
||||
let mut edit = TextEdit::insert(position.offset, format!("\n{}$0", indent + 1));
|
||||
edit.union(TextEdit::insert(
|
||||
list.r_curly_token()?.text_range().start(),
|
||||
format!("\n{}", indent),
|
||||
))
|
||||
.ok()?;
|
||||
edit.union(TextEdit::insert(list.r_curly_token()?.text_range().start(), format!("\n{indent}")))
|
||||
.ok()?;
|
||||
Some(edit)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue