Skip to content

Commit 2872e05

Browse files
committed
Auto merge of #13835 - nyurik:inline_format_args, r=lnicola
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 ```
2 parents 1927c2e + e16c76e commit 2872e05

File tree

180 files changed

+487
-501
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

180 files changed

+487
-501
lines changed

crates/base-db/src/fixture.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,9 @@ fn parse_crate(crate_str: String) -> (String, CrateOrigin, Option<String>) {
407407
Some((version, url)) => {
408408
(version, CrateOrigin::CratesIo { repo: Some(url.to_owned()), name: None })
409409
}
410-
_ => panic!("Bad crates.io parameter: {}", data),
410+
_ => panic!("Bad crates.io parameter: {data}"),
411411
},
412-
_ => panic!("Bad string for crate origin: {}", b),
412+
_ => panic!("Bad string for crate origin: {b}"),
413413
};
414414
(a.to_owned(), origin, Some(version.to_string()))
415415
} else {
@@ -439,7 +439,7 @@ impl From<Fixture> for FileMeta {
439439
introduce_new_source_root: f.introduce_new_source_root.map(|kind| match &*kind {
440440
"local" => SourceRootKind::Local,
441441
"library" => SourceRootKind::Library,
442-
invalid => panic!("invalid source root kind '{}'", invalid),
442+
invalid => panic!("invalid source root kind '{invalid}'"),
443443
}),
444444
target_data_layout: f.target_data_layout,
445445
}

crates/base-db/src/input.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,8 +618,8 @@ impl CyclicDependenciesError {
618618
impl fmt::Display for CyclicDependenciesError {
619619
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
620620
let render = |(id, name): &(CrateId, Option<CrateDisplayName>)| match name {
621-
Some(it) => format!("{}({:?})", it, id),
622-
None => format!("{:?}", id),
621+
Some(it) => format!("{it}({id:?})"),
622+
None => format!("{id:?}"),
623623
};
624624
let path = self.path.iter().rev().map(render).collect::<Vec<String>>().join(" -> ");
625625
write!(

crates/base-db/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub trait SourceDatabase: FileLoader + std::fmt::Debug {
7575
}
7676

7777
fn parse_query(db: &dyn SourceDatabase, file_id: FileId) -> Parse<ast::SourceFile> {
78-
let _p = profile::span("parse_query").detail(|| format!("{:?}", file_id));
78+
let _p = profile::span("parse_query").detail(|| format!("{file_id:?}"));
7979
let text = db.file_text(file_id);
8080
SourceFile::parse(&text)
8181
}

crates/cfg/src/cfg_expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl fmt::Display for CfgAtom {
4444
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
4545
match self {
4646
CfgAtom::Flag(name) => name.fmt(f),
47-
CfgAtom::KeyValue { key, value } => write!(f, "{} = {:?}", key, value),
47+
CfgAtom::KeyValue { key, value } => write!(f, "{key} = {value:?}"),
4848
}
4949
}
5050
}

crates/cfg/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl fmt::Debug for CfgOptions {
3737
.iter()
3838
.map(|atom| match atom {
3939
CfgAtom::Flag(it) => it.to_string(),
40-
CfgAtom::KeyValue { key, value } => format!("{}={}", key, value),
40+
CfgAtom::KeyValue { key, value } => format!("{key}={value}"),
4141
})
4242
.collect::<Vec<_>>();
4343
items.sort();
@@ -175,7 +175,7 @@ impl fmt::Display for InactiveReason {
175175
atom.fmt(f)?;
176176
}
177177
let is_are = if self.enabled.len() == 1 { "is" } else { "are" };
178-
write!(f, " {} enabled", is_are)?;
178+
write!(f, " {is_are} enabled")?;
179179

180180
if !self.disabled.is_empty() {
181181
f.write_str(" and ")?;
@@ -194,7 +194,7 @@ impl fmt::Display for InactiveReason {
194194
atom.fmt(f)?;
195195
}
196196
let is_are = if self.disabled.len() == 1 { "is" } else { "are" };
197-
write!(f, " {} disabled", is_are)?;
197+
write!(f, " {is_are} disabled")?;
198198
}
199199

200200
Ok(())

crates/flycheck/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ pub enum FlycheckConfig {
6060
impl fmt::Display for FlycheckConfig {
6161
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
6262
match self {
63-
FlycheckConfig::CargoCommand { command, .. } => write!(f, "cargo {}", command),
63+
FlycheckConfig::CargoCommand { command, .. } => write!(f, "cargo {command}"),
6464
FlycheckConfig::CustomCommand { command, args, .. } => {
65-
write!(f, "{} {}", command, args.join(" "))
65+
write!(f, "{command} {}", args.join(" "))
6666
}
6767
}
6868
}
@@ -474,7 +474,7 @@ impl CargoActor {
474474
);
475475
match output {
476476
Ok(_) => Ok((read_at_least_one_message, error)),
477-
Err(e) => Err(io::Error::new(e.kind(), format!("{:?}: {}", e, error))),
477+
Err(e) => Err(io::Error::new(e.kind(), format!("{e:?}: {error}"))),
478478
}
479479
}
480480
}

crates/hir-def/src/attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ impl AttrSourceMap {
712712
self.source
713713
.get(ast_idx)
714714
.map(|it| InFile::new(file_id, it))
715-
.unwrap_or_else(|| panic!("cannot find attr at index {:?}", id))
715+
.unwrap_or_else(|| panic!("cannot find attr at index {id:?}"))
716716
}
717717
}
718718

crates/hir-def/src/body/pretty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub(super) fn print_body_hir(db: &dyn DefDatabase, body: &Body, owner: DefWithBo
3232
Some(name) => name.to_string(),
3333
None => "_".to_string(),
3434
};
35-
format!("const {} = ", name)
35+
format!("const {name} = ")
3636
}
3737
DefWithBodyId::VariantId(it) => {
3838
needs_semi = false;
@@ -42,7 +42,7 @@ pub(super) fn print_body_hir(db: &dyn DefDatabase, body: &Body, owner: DefWithBo
4242
Some(name) => name.to_string(),
4343
None => "_".to_string(),
4444
};
45-
format!("{}", name)
45+
format!("{name}")
4646
}
4747
};
4848

crates/hir-def/src/find_path.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ mod tests {
512512
fn check_found_path_(ra_fixture: &str, path: &str, prefix_kind: Option<PrefixKind>) {
513513
let (db, pos) = TestDB::with_position(ra_fixture);
514514
let module = db.module_at_position(pos);
515-
let parsed_path_file = syntax::SourceFile::parse(&format!("use {};", path));
515+
let parsed_path_file = syntax::SourceFile::parse(&format!("use {path};"));
516516
let ast_path =
517517
parsed_path_file.syntax_node().descendants().find_map(syntax::ast::Path::cast).unwrap();
518518
let mod_path = ModPath::from_src(&db, ast_path, &Hygiene::new_unhygienic()).unwrap();
@@ -531,7 +531,7 @@ mod tests {
531531

532532
let found_path =
533533
find_path_inner(&db, ItemInNs::Types(resolved), module, prefix_kind, false);
534-
assert_eq!(found_path, Some(mod_path), "{:?}", prefix_kind);
534+
assert_eq!(found_path, Some(mod_path), "{prefix_kind:?}");
535535
}
536536

537537
fn check_found_path(

crates/hir-def/src/import_map.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl fmt::Debug for ImportMap {
243243
ItemInNs::Values(_) => "v",
244244
ItemInNs::Macros(_) => "m",
245245
};
246-
format!("- {} ({})", info.path, ns)
246+
format!("- {} ({ns})", info.path)
247247
})
248248
.collect();
249249

@@ -398,7 +398,7 @@ pub fn search_dependencies<'a>(
398398
krate: CrateId,
399399
query: Query,
400400
) -> FxHashSet<ItemInNs> {
401-
let _p = profile::span("search_dependencies").detail(|| format!("{:?}", query));
401+
let _p = profile::span("search_dependencies").detail(|| format!("{query:?}"));
402402

403403
let graph = db.crate_graph();
404404
let import_maps: Vec<_> =
@@ -549,7 +549,7 @@ mod tests {
549549
None
550550
}
551551
})?;
552-
return Some(format!("{}::{}", dependency_imports.path_of(trait_)?, assoc_item_name));
552+
return Some(format!("{}::{assoc_item_name}", dependency_imports.path_of(trait_)?));
553553
}
554554
None
555555
}
@@ -589,7 +589,7 @@ mod tests {
589589

590590
let map = db.import_map(krate);
591591

592-
Some(format!("{}:\n{:?}\n", name, map))
592+
Some(format!("{name}:\n{map:?}\n"))
593593
})
594594
.sorted()
595595
.collect::<String>();

0 commit comments

Comments
 (0)