Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 2872e05

Browse files
committed
Auto merge of rust-lang#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>();

crates/hir-def/src/item_tree.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub struct ItemTree {
105105

106106
impl ItemTree {
107107
pub(crate) fn file_item_tree_query(db: &dyn DefDatabase, file_id: HirFileId) -> Arc<ItemTree> {
108-
let _p = profile::span("file_item_tree_query").detail(|| format!("{:?}", file_id));
108+
let _p = profile::span("file_item_tree_query").detail(|| format!("{file_id:?}"));
109109
let syntax = match db.parse_or_expand(file_id) {
110110
Some(node) => node,
111111
None => return Default::default(),
@@ -132,7 +132,7 @@ impl ItemTree {
132132
ctx.lower_macro_stmts(stmts)
133133
},
134134
_ => {
135-
panic!("cannot create item tree from {:?} {}", syntax, syntax);
135+
panic!("cannot create item tree from {syntax:?} {syntax}");
136136
},
137137
}
138138
};

crates/hir-def/src/macro_expansion_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ pub fn identity_when_valid(_attr: TokenStream, item: TokenStream) -> TokenStream
179179
if tree {
180180
let tree = format!("{:#?}", parse.syntax_node())
181181
.split_inclusive('\n')
182-
.map(|line| format!("// {}", line))
182+
.map(|line| format!("// {line}"))
183183
.collect::<String>();
184184
format_to!(expn_text, "\n{}", tree)
185185
}

crates/hir-def/src/nameres.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ impl DefMap {
461461
for (name, child) in
462462
map.modules[module].children.iter().sorted_by(|a, b| Ord::cmp(&a.0, &b.0))
463463
{
464-
let path = format!("{}::{}", path, name);
464+
let path = format!("{path}::{name}");
465465
buf.push('\n');
466466
go(buf, map, &path, *child);
467467
}

crates/hir-def/src/nameres/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ impl DefCollector<'_> {
10171017
None => true,
10181018
Some(old_vis) => {
10191019
let max_vis = old_vis.max(vis, &self.def_map).unwrap_or_else(|| {
1020-
panic!("`Tr as _` imports with unrelated visibilities {:?} and {:?} (trait {:?})", old_vis, vis, tr);
1020+
panic!("`Tr as _` imports with unrelated visibilities {old_vis:?} and {vis:?} (trait {tr:?})");
10211021
});
10221022

10231023
if max_vis == old_vis {

crates/hir-def/src/nameres/mod_resolution.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ impl ModDir {
7474
candidate_files.push(self.dir_path.join_attr(attr_path, self.root_non_dir_owner))
7575
}
7676
None if file_id.is_include_macro(db.upcast()) => {
77-
candidate_files.push(format!("{}.rs", name));
78-
candidate_files.push(format!("{}/mod.rs", name));
77+
candidate_files.push(format!("{name}.rs"));
78+
candidate_files.push(format!("{name}/mod.rs"));
7979
}
8080
None => {
81-
candidate_files.push(format!("{}{}.rs", self.dir_path.0, name));
82-
candidate_files.push(format!("{}{}/mod.rs", self.dir_path.0, name));
81+
candidate_files.push(format!("{}{name}.rs", self.dir_path.0));
82+
candidate_files.push(format!("{}{name}/mod.rs", self.dir_path.0));
8383
}
8484
};
8585

@@ -91,7 +91,7 @@ impl ModDir {
9191
let (dir_path, root_non_dir_owner) = if is_mod_rs || attr_path.is_some() {
9292
(DirPath::empty(), false)
9393
} else {
94-
(DirPath::new(format!("{}/", name)), true)
94+
(DirPath::new(format!("{name}/")), true)
9595
};
9696
if let Some(mod_dir) = self.child(dir_path, root_non_dir_owner) {
9797
return Ok((file_id, is_mod_rs, mod_dir));
@@ -156,7 +156,7 @@ impl DirPath {
156156
} else {
157157
attr
158158
};
159-
let res = format!("{}{}", base, attr);
159+
let res = format!("{base}{attr}");
160160
res
161161
}
162162
}

crates/hir-def/src/nameres/path_resolution.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ impl DefMap {
170170
) -> ResolvePathResult {
171171
let graph = db.crate_graph();
172172
let _cx = stdx::panic_context::enter(format!(
173-
"DefMap {:?} crate_name={:?} block={:?} path={}",
174-
self.krate, graph[self.krate].display_name, self.block, path
173+
"DefMap {:?} crate_name={:?} block={:?} path={path}",
174+
self.krate, graph[self.krate].display_name, self.block
175175
));
176176

177177
let mut segments = path.segments().iter().enumerate();

crates/hir-def/src/nameres/tests/incremental.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ fn check_def_map_is_not_recomputed(ra_fixture_initial: &str, ra_fixture_change:
1313
let events = db.log_executed(|| {
1414
db.crate_def_map(krate);
1515
});
16-
assert!(format!("{:?}", events).contains("crate_def_map"), "{:#?}", events)
16+
assert!(format!("{events:?}").contains("crate_def_map"), "{events:#?}")
1717
}
1818
db.set_file_text(pos.file_id, Arc::new(ra_fixture_change.to_string()));
1919

2020
{
2121
let events = db.log_executed(|| {
2222
db.crate_def_map(krate);
2323
});
24-
assert!(!format!("{:?}", events).contains("crate_def_map"), "{:#?}", events)
24+
assert!(!format!("{events:?}").contains("crate_def_map"), "{events:#?}")
2525
}
2626
}
2727

@@ -94,7 +94,7 @@ fn typing_inside_a_macro_should_not_invalidate_def_map() {
9494
let (_, module_data) = crate_def_map.modules.iter().last().unwrap();
9595
assert_eq!(module_data.scope.resolutions().count(), 1);
9696
});
97-
assert!(format!("{:?}", events).contains("crate_def_map"), "{:#?}", events)
97+
assert!(format!("{events:?}").contains("crate_def_map"), "{events:#?}")
9898
}
9999
db.set_file_text(pos.file_id, Arc::new("m!(Y);".to_string()));
100100

@@ -104,7 +104,7 @@ fn typing_inside_a_macro_should_not_invalidate_def_map() {
104104
let (_, module_data) = crate_def_map.modules.iter().last().unwrap();
105105
assert_eq!(module_data.scope.resolutions().count(), 1);
106106
});
107-
assert!(!format!("{:?}", events).contains("crate_def_map"), "{:#?}", events)
107+
assert!(!format!("{events:?}").contains("crate_def_map"), "{events:#?}")
108108
}
109109
}
110110

crates/hir-def/src/pretty.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub(crate) fn print_generic_args(generics: &GenericArgs, buf: &mut dyn Write) ->
9292
pub(crate) fn print_generic_arg(arg: &GenericArg, buf: &mut dyn Write) -> fmt::Result {
9393
match arg {
9494
GenericArg::Type(ty) => print_type_ref(ty, buf),
95-
GenericArg::Const(c) => write!(buf, "{}", c),
95+
GenericArg::Const(c) => write!(buf, "{c}"),
9696
GenericArg::Lifetime(lt) => write!(buf, "{}", lt.name),
9797
}
9898
}
@@ -118,7 +118,7 @@ pub(crate) fn print_type_ref(type_ref: &TypeRef, buf: &mut dyn Write) -> fmt::Re
118118
Mutability::Shared => "*const",
119119
Mutability::Mut => "*mut",
120120
};
121-
write!(buf, "{} ", mtbl)?;
121+
write!(buf, "{mtbl} ")?;
122122
print_type_ref(pointee, buf)?;
123123
}
124124
TypeRef::Reference(pointee, lt, mtbl) => {
@@ -130,13 +130,13 @@ pub(crate) fn print_type_ref(type_ref: &TypeRef, buf: &mut dyn Write) -> fmt::Re
130130
if let Some(lt) = lt {
131131
write!(buf, "{} ", lt.name)?;
132132
}
133-
write!(buf, "{}", mtbl)?;
133+
write!(buf, "{mtbl}")?;
134134
print_type_ref(pointee, buf)?;
135135
}
136136
TypeRef::Array(elem, len) => {
137137
write!(buf, "[")?;
138138
print_type_ref(elem, buf)?;
139-
write!(buf, "; {}]", len)?;
139+
write!(buf, "; {len}]")?;
140140
}
141141
TypeRef::Slice(elem) => {
142142
write!(buf, "[")?;

crates/hir-expand/src/db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ fn macro_expand(db: &dyn AstDatabase, id: MacroCallId) -> ExpandResult<Option<Ar
444444
// be reported at the definition site (when we construct a def map).
445445
Err(err) => {
446446
return ExpandResult::only_err(ExpandError::Other(
447-
format!("invalid macro definition: {}", err).into(),
447+
format!("invalid macro definition: {err}").into(),
448448
))
449449
}
450450
};

crates/hir-expand/src/eager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ pub fn expand_eager_macro(
161161

162162
Ok(Ok(db.intern_macro_call(loc)))
163163
} else {
164-
panic!("called `expand_eager_macro` on non-eager macro def {:?}", def);
164+
panic!("called `expand_eager_macro` on non-eager macro def {def:?}");
165165
}
166166
}
167167

crates/hir-expand/src/fixup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ mod tests {
366366
fixups.append,
367367
);
368368

369-
let actual = format!("{}\n", tt);
369+
let actual = format!("{tt}\n");
370370

371371
expect.indent(false);
372372
expect.assert_eq(&actual);

crates/hir-expand/src/quote.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ mod tests {
233233

234234
let quoted = quote!(#a);
235235
assert_eq!(quoted.to_string(), "hello");
236-
let t = format!("{:?}", quoted);
236+
let t = format!("{quoted:?}");
237237
assert_eq!(t, "SUBTREE $\n IDENT hello 4294967295");
238238
}
239239

crates/hir-ty/src/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl<D> TyBuilder<D> {
142142
match (a.data(Interner), e) {
143143
(chalk_ir::GenericArgData::Ty(_), ParamKind::Type)
144144
| (chalk_ir::GenericArgData::Const(_), ParamKind::Const(_)) => (),
145-
_ => panic!("Mismatched kinds: {:?}, {:?}, {:?}", a, self.vec, self.param_kinds),
145+
_ => panic!("Mismatched kinds: {a:?}, {:?}, {:?}", self.vec, self.param_kinds),
146146
}
147147
}
148148
}

0 commit comments

Comments
 (0)