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,9 +87,9 @@ impl flags::AnalysisStats {
load_workspace(workspace, &cargo_config.extra_env, &load_cargo_config)?;
let db = host.raw_database();
eprint!("{:<20} {}", "Database loaded:", db_load_sw.elapsed());
eprint!(" (metadata {}", metadata_time);
eprint!(" (metadata {metadata_time}");
if let Some(build_scripts_time) = build_scripts_time {
eprint!("; build {}", build_scripts_time);
eprint!("; build {build_scripts_time}");
}
eprintln!(")");
@@ -118,7 +118,7 @@ impl flags::AnalysisStats {
shuffle(&mut rng, &mut visit_queue);
}
eprint!(" crates: {}", num_crates);
eprint!(" crates: {num_crates}");
let mut num_decls = 0;
let mut funcs = Vec::new();
while let Some(module) = visit_queue.pop() {
@@ -142,7 +142,7 @@ impl flags::AnalysisStats {
}
}
}
eprintln!(", mods: {}, decls: {}, fns: {}", visited_modules.len(), num_decls, funcs.len());
eprintln!(", mods: {}, decls: {num_decls}, fns: {}", visited_modules.len(), funcs.len());
eprintln!("{:<20} {}", "Item Collection:", analysis_sw.elapsed());
if self.randomize {
@@ -154,7 +154,7 @@ impl flags::AnalysisStats {
}
let total_span = analysis_sw.elapsed();
eprintln!("{:<20} {}", "Total:", total_span);
eprintln!("{:<20} {total_span}", "Total:");
report_metric("total time", total_span.time.as_millis() as u64, "ms");
if let Some(instructions) = total_span.instructions {
report_metric("total instructions", instructions, "#instr");
@@ -179,7 +179,7 @@ impl flags::AnalysisStats {
total_macro_file_size += syntax_len(val.syntax_node())
}
}
eprintln!("source files: {}, macro files: {}", total_file_size, total_macro_file_size);
eprintln!("source files: {total_file_size}, macro files: {total_macro_file_size}");
}
if self.memory_usage && verbosity.is_verbose() {
@@ -239,7 +239,7 @@ impl flags::AnalysisStats {
continue;
}
}
let mut msg = format!("processing: {}", full_name);
let mut msg = format!("processing: {full_name}");
if verbosity.is_verbose() {
if let Some(src) = f.source(db) {
let original_file = src.file_id.original_file(db);
@@ -275,7 +275,7 @@ impl flags::AnalysisStats {
end.col,
));
} else {
bar.println(format!("{}: Unknown type", name,));
bar.println(format!("{name}: Unknown type",));
}
}
true
@@ -402,7 +402,7 @@ fn location_csv(
let text_range = original_range.range;
let (start, end) =
(line_index.line_col(text_range.start()), line_index.line_col(text_range.end()));
format!("{},{}:{},{}:{}", path, start.line + 1, start.col, end.line + 1, end.col)
format!("{path},{}:{},{}:{}", start.line + 1, start.col, end.line + 1, end.col)
}
fn expr_syntax_range(

View File

@@ -40,7 +40,7 @@ impl flags::Diagnostics {
if !visited_files.contains(&file_id) {
let crate_name =
module.krate().display_name(db).as_deref().unwrap_or("unknown").to_string();
println!("processing crate: {}, module: {}", crate_name, _vfs.file_path(file_id));
println!("processing crate: {crate_name}, module: {}", _vfs.file_path(file_id));
for diagnostic in analysis
.diagnostics(
&DiagnosticsConfig::test_sample(),
@@ -53,7 +53,7 @@ impl flags::Diagnostics {
found_error = true;
}
println!("{:?}", diagnostic);
println!("{diagnostic:?}");
}
visited_files.insert(file_id);

View File

@@ -255,7 +255,7 @@ impl FromStr for OutputFormat {
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"csv" => Ok(Self::Csv),
_ => Err(format!("unknown output format `{}`", s)),
_ => Err(format!("unknown output format `{s}`")),
}
}
}

View File

@@ -8,7 +8,7 @@ impl flags::Highlight {
pub fn run(self) -> anyhow::Result<()> {
let (analysis, file_id) = Analysis::from_single_file(read_stdin()?);
let html = analysis.highlight_as_html(file_id, self.rainbow).unwrap();
println!("{}", html);
println!("{html}");
Ok(())
}
}

View File

@@ -83,7 +83,7 @@ impl LsifManager<'_> {
// FIXME: support file in addition to stdout here
fn emit(&self, data: &str) {
println!("{}", data);
println!("{data}");
}
fn get_token_id(&mut self, id: TokenId) -> Id {

View File

@@ -67,7 +67,7 @@ impl ProgressReport {
return;
}
let percent = (self.curr * 100.0) as u32;
let text = format!("{}/{} {:3>}% {}", self.pos, self.len, percent, self.msg);
let text = format!("{}/{} {percent:3>}% {}", self.pos, self.len, self.msg);
self.update_text(&text);
}
@@ -114,7 +114,7 @@ impl ProgressReport {
// Fill all last text to space and return the cursor
let spaces = " ".repeat(self.text.len());
let backspaces = "\x08".repeat(self.text.len());
print!("{}{}{}", backspaces, spaces, backspaces);
print!("{backspaces}{spaces}{backspaces}");
let _ = io::stdout().flush();
self.text = String::new();

View File

@@ -28,7 +28,7 @@ impl flags::Scip {
let now = Instant::now();
let cargo_config = CargoConfig::default();
let no_progress = &|s| (eprintln!("rust-analyzer: Loading {}", s));
let no_progress = &|s| (eprintln!("rust-analyzer: Loading {s}"));
let load_cargo_config = LoadCargoConfig {
load_out_dirs_from_check: true,
with_proc_macro: true,
@@ -209,7 +209,7 @@ fn new_descriptor_str(
fn new_descriptor(name: Name, suffix: scip_types::descriptor::Suffix) -> scip_types::Descriptor {
let mut name = name.to_string();
if name.contains("'") {
name = format!("`{}`", name);
name = format!("`{name}`");
}
new_descriptor_str(name.as_str(), suffix)
@@ -303,11 +303,11 @@ mod test {
}
if expected == "" {
assert!(found_symbol.is_none(), "must have no symbols {:?}", found_symbol);
assert!(found_symbol.is_none(), "must have no symbols {found_symbol:?}");
return;
}
assert!(found_symbol.is_some(), "must have one symbol {:?}", found_symbol);
assert!(found_symbol.is_some(), "must have one symbol {found_symbol:?}");
let res = found_symbol.unwrap();
let formatted = format_symbol(res);
assert_eq!(formatted, expected);

View File

@@ -70,7 +70,7 @@ impl flags::Search {
let sr = db.source_root(root);
for file_id in sr.iter() {
for debug_info in match_finder.debug_where_text_equal(file_id, debug_snippet) {
println!("{:#?}", debug_info);
println!("{debug_info:#?}");
}
}
}

View File

@@ -9,7 +9,7 @@ impl flags::Symbols {
let (analysis, file_id) = Analysis::from_single_file(text);
let structure = analysis.file_structure(file_id).unwrap();
for s in structure {
println!("{:?}", s);
println!("{s:?}");
}
Ok(())
}