Skip to content

Commit

Permalink
Auto merge of rust-lang#13835 - nyurik:inline_format_args, r=lnicola
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
bors committed Dec 25, 2022
2 parents 1927c2e + e16c76e commit 2872e05
Show file tree
Hide file tree
Showing 180 changed files with 487 additions and 501 deletions.
6 changes: 3 additions & 3 deletions crates/base-db/src/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,9 @@ fn parse_crate(crate_str: String) -> (String, CrateOrigin, Option<String>) {
Some((version, url)) => {
(version, CrateOrigin::CratesIo { repo: Some(url.to_owned()), name: None })
}
_ => panic!("Bad crates.io parameter: {}", data),
_ => panic!("Bad crates.io parameter: {data}"),
},
_ => panic!("Bad string for crate origin: {}", b),
_ => panic!("Bad string for crate origin: {b}"),
};
(a.to_owned(), origin, Some(version.to_string()))
} else {
Expand Down Expand Up @@ -439,7 +439,7 @@ impl From<Fixture> for FileMeta {
introduce_new_source_root: f.introduce_new_source_root.map(|kind| match &*kind {
"local" => SourceRootKind::Local,
"library" => SourceRootKind::Library,
invalid => panic!("invalid source root kind '{}'", invalid),
invalid => panic!("invalid source root kind '{invalid}'"),
}),
target_data_layout: f.target_data_layout,
}
Expand Down
4 changes: 2 additions & 2 deletions crates/base-db/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,8 @@ impl CyclicDependenciesError {
impl fmt::Display for CyclicDependenciesError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let render = |(id, name): &(CrateId, Option<CrateDisplayName>)| match name {
Some(it) => format!("{}({:?})", it, id),
None => format!("{:?}", id),
Some(it) => format!("{it}({id:?})"),
None => format!("{id:?}"),
};
let path = self.path.iter().rev().map(render).collect::<Vec<String>>().join(" -> ");
write!(
Expand Down
2 changes: 1 addition & 1 deletion crates/base-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub trait SourceDatabase: FileLoader + std::fmt::Debug {
}

fn parse_query(db: &dyn SourceDatabase, file_id: FileId) -> Parse<ast::SourceFile> {
let _p = profile::span("parse_query").detail(|| format!("{:?}", file_id));
let _p = profile::span("parse_query").detail(|| format!("{file_id:?}"));
let text = db.file_text(file_id);
SourceFile::parse(&text)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/cfg/src/cfg_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl fmt::Display for CfgAtom {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
CfgAtom::Flag(name) => name.fmt(f),
CfgAtom::KeyValue { key, value } => write!(f, "{} = {:?}", key, value),
CfgAtom::KeyValue { key, value } => write!(f, "{key} = {value:?}"),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/cfg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl fmt::Debug for CfgOptions {
.iter()
.map(|atom| match atom {
CfgAtom::Flag(it) => it.to_string(),
CfgAtom::KeyValue { key, value } => format!("{}={}", key, value),
CfgAtom::KeyValue { key, value } => format!("{key}={value}"),
})
.collect::<Vec<_>>();
items.sort();
Expand Down Expand Up @@ -175,7 +175,7 @@ impl fmt::Display for InactiveReason {
atom.fmt(f)?;
}
let is_are = if self.enabled.len() == 1 { "is" } else { "are" };
write!(f, " {} enabled", is_are)?;
write!(f, " {is_are} enabled")?;

if !self.disabled.is_empty() {
f.write_str(" and ")?;
Expand All @@ -194,7 +194,7 @@ impl fmt::Display for InactiveReason {
atom.fmt(f)?;
}
let is_are = if self.disabled.len() == 1 { "is" } else { "are" };
write!(f, " {} disabled", is_are)?;
write!(f, " {is_are} disabled")?;
}

Ok(())
Expand Down
6 changes: 3 additions & 3 deletions crates/flycheck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ pub enum FlycheckConfig {
impl fmt::Display for FlycheckConfig {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
FlycheckConfig::CargoCommand { command, .. } => write!(f, "cargo {}", command),
FlycheckConfig::CargoCommand { command, .. } => write!(f, "cargo {command}"),
FlycheckConfig::CustomCommand { command, args, .. } => {
write!(f, "{} {}", command, args.join(" "))
write!(f, "{command} {}", args.join(" "))
}
}
}
Expand Down Expand Up @@ -474,7 +474,7 @@ impl CargoActor {
);
match output {
Ok(_) => Ok((read_at_least_one_message, error)),
Err(e) => Err(io::Error::new(e.kind(), format!("{:?}: {}", e, error))),
Err(e) => Err(io::Error::new(e.kind(), format!("{e:?}: {error}"))),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ impl AttrSourceMap {
self.source
.get(ast_idx)
.map(|it| InFile::new(file_id, it))
.unwrap_or_else(|| panic!("cannot find attr at index {:?}", id))
.unwrap_or_else(|| panic!("cannot find attr at index {id:?}"))
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/hir-def/src/body/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub(super) fn print_body_hir(db: &dyn DefDatabase, body: &Body, owner: DefWithBo
Some(name) => name.to_string(),
None => "_".to_string(),
};
format!("const {} = ", name)
format!("const {name} = ")
}
DefWithBodyId::VariantId(it) => {
needs_semi = false;
Expand All @@ -42,7 +42,7 @@ pub(super) fn print_body_hir(db: &dyn DefDatabase, body: &Body, owner: DefWithBo
Some(name) => name.to_string(),
None => "_".to_string(),
};
format!("{}", name)
format!("{name}")
}
};

Expand Down
4 changes: 2 additions & 2 deletions crates/hir-def/src/find_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ mod tests {
fn check_found_path_(ra_fixture: &str, path: &str, prefix_kind: Option<PrefixKind>) {
let (db, pos) = TestDB::with_position(ra_fixture);
let module = db.module_at_position(pos);
let parsed_path_file = syntax::SourceFile::parse(&format!("use {};", path));
let parsed_path_file = syntax::SourceFile::parse(&format!("use {path};"));
let ast_path =
parsed_path_file.syntax_node().descendants().find_map(syntax::ast::Path::cast).unwrap();
let mod_path = ModPath::from_src(&db, ast_path, &Hygiene::new_unhygienic()).unwrap();
Expand All @@ -531,7 +531,7 @@ mod tests {

let found_path =
find_path_inner(&db, ItemInNs::Types(resolved), module, prefix_kind, false);
assert_eq!(found_path, Some(mod_path), "{:?}", prefix_kind);
assert_eq!(found_path, Some(mod_path), "{prefix_kind:?}");
}

fn check_found_path(
Expand Down
8 changes: 4 additions & 4 deletions crates/hir-def/src/import_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl fmt::Debug for ImportMap {
ItemInNs::Values(_) => "v",
ItemInNs::Macros(_) => "m",
};
format!("- {} ({})", info.path, ns)
format!("- {} ({ns})", info.path)
})
.collect();

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

let graph = db.crate_graph();
let import_maps: Vec<_> =
Expand Down Expand Up @@ -549,7 +549,7 @@ mod tests {
None
}
})?;
return Some(format!("{}::{}", dependency_imports.path_of(trait_)?, assoc_item_name));
return Some(format!("{}::{assoc_item_name}", dependency_imports.path_of(trait_)?));
}
None
}
Expand Down Expand Up @@ -589,7 +589,7 @@ mod tests {

let map = db.import_map(krate);

Some(format!("{}:\n{:?}\n", name, map))
Some(format!("{name}:\n{map:?}\n"))
})
.sorted()
.collect::<String>();
Expand Down
4 changes: 2 additions & 2 deletions crates/hir-def/src/item_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub struct ItemTree {

impl ItemTree {
pub(crate) fn file_item_tree_query(db: &dyn DefDatabase, file_id: HirFileId) -> Arc<ItemTree> {
let _p = profile::span("file_item_tree_query").detail(|| format!("{:?}", file_id));
let _p = profile::span("file_item_tree_query").detail(|| format!("{file_id:?}"));
let syntax = match db.parse_or_expand(file_id) {
Some(node) => node,
None => return Default::default(),
Expand All @@ -132,7 +132,7 @@ impl ItemTree {
ctx.lower_macro_stmts(stmts)
},
_ => {
panic!("cannot create item tree from {:?} {}", syntax, syntax);
panic!("cannot create item tree from {syntax:?} {syntax}");
},
}
};
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/macro_expansion_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub fn identity_when_valid(_attr: TokenStream, item: TokenStream) -> TokenStream
if tree {
let tree = format!("{:#?}", parse.syntax_node())
.split_inclusive('\n')
.map(|line| format!("// {}", line))
.map(|line| format!("// {line}"))
.collect::<String>();
format_to!(expn_text, "\n{}", tree)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/nameres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ impl DefMap {
for (name, child) in
map.modules[module].children.iter().sorted_by(|a, b| Ord::cmp(&a.0, &b.0))
{
let path = format!("{}::{}", path, name);
let path = format!("{path}::{name}");
buf.push('\n');
go(buf, map, &path, *child);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/nameres/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ impl DefCollector<'_> {
None => true,
Some(old_vis) => {
let max_vis = old_vis.max(vis, &self.def_map).unwrap_or_else(|| {
panic!("`Tr as _` imports with unrelated visibilities {:?} and {:?} (trait {:?})", old_vis, vis, tr);
panic!("`Tr as _` imports with unrelated visibilities {old_vis:?} and {vis:?} (trait {tr:?})");
});

if max_vis == old_vis {
Expand Down
12 changes: 6 additions & 6 deletions crates/hir-def/src/nameres/mod_resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ impl ModDir {
candidate_files.push(self.dir_path.join_attr(attr_path, self.root_non_dir_owner))
}
None if file_id.is_include_macro(db.upcast()) => {
candidate_files.push(format!("{}.rs", name));
candidate_files.push(format!("{}/mod.rs", name));
candidate_files.push(format!("{name}.rs"));
candidate_files.push(format!("{name}/mod.rs"));
}
None => {
candidate_files.push(format!("{}{}.rs", self.dir_path.0, name));
candidate_files.push(format!("{}{}/mod.rs", self.dir_path.0, name));
candidate_files.push(format!("{}{name}.rs", self.dir_path.0));
candidate_files.push(format!("{}{name}/mod.rs", self.dir_path.0));
}
};

Expand All @@ -91,7 +91,7 @@ impl ModDir {
let (dir_path, root_non_dir_owner) = if is_mod_rs || attr_path.is_some() {
(DirPath::empty(), false)
} else {
(DirPath::new(format!("{}/", name)), true)
(DirPath::new(format!("{name}/")), true)
};
if let Some(mod_dir) = self.child(dir_path, root_non_dir_owner) {
return Ok((file_id, is_mod_rs, mod_dir));
Expand Down Expand Up @@ -156,7 +156,7 @@ impl DirPath {
} else {
attr
};
let res = format!("{}{}", base, attr);
let res = format!("{base}{attr}");
res
}
}
4 changes: 2 additions & 2 deletions crates/hir-def/src/nameres/path_resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ impl DefMap {
) -> ResolvePathResult {
let graph = db.crate_graph();
let _cx = stdx::panic_context::enter(format!(
"DefMap {:?} crate_name={:?} block={:?} path={}",
self.krate, graph[self.krate].display_name, self.block, path
"DefMap {:?} crate_name={:?} block={:?} path={path}",
self.krate, graph[self.krate].display_name, self.block
));

let mut segments = path.segments().iter().enumerate();
Expand Down
8 changes: 4 additions & 4 deletions crates/hir-def/src/nameres/tests/incremental.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ fn check_def_map_is_not_recomputed(ra_fixture_initial: &str, ra_fixture_change:
let events = db.log_executed(|| {
db.crate_def_map(krate);
});
assert!(format!("{:?}", events).contains("crate_def_map"), "{:#?}", events)
assert!(format!("{events:?}").contains("crate_def_map"), "{events:#?}")
}
db.set_file_text(pos.file_id, Arc::new(ra_fixture_change.to_string()));

{
let events = db.log_executed(|| {
db.crate_def_map(krate);
});
assert!(!format!("{:?}", events).contains("crate_def_map"), "{:#?}", events)
assert!(!format!("{events:?}").contains("crate_def_map"), "{events:#?}")
}
}

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

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

Expand Down
8 changes: 4 additions & 4 deletions crates/hir-def/src/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub(crate) fn print_generic_args(generics: &GenericArgs, buf: &mut dyn Write) ->
pub(crate) fn print_generic_arg(arg: &GenericArg, buf: &mut dyn Write) -> fmt::Result {
match arg {
GenericArg::Type(ty) => print_type_ref(ty, buf),
GenericArg::Const(c) => write!(buf, "{}", c),
GenericArg::Const(c) => write!(buf, "{c}"),
GenericArg::Lifetime(lt) => write!(buf, "{}", lt.name),
}
}
Expand All @@ -118,7 +118,7 @@ pub(crate) fn print_type_ref(type_ref: &TypeRef, buf: &mut dyn Write) -> fmt::Re
Mutability::Shared => "*const",
Mutability::Mut => "*mut",
};
write!(buf, "{} ", mtbl)?;
write!(buf, "{mtbl} ")?;
print_type_ref(pointee, buf)?;
}
TypeRef::Reference(pointee, lt, mtbl) => {
Expand All @@ -130,13 +130,13 @@ pub(crate) fn print_type_ref(type_ref: &TypeRef, buf: &mut dyn Write) -> fmt::Re
if let Some(lt) = lt {
write!(buf, "{} ", lt.name)?;
}
write!(buf, "{}", mtbl)?;
write!(buf, "{mtbl}")?;
print_type_ref(pointee, buf)?;
}
TypeRef::Array(elem, len) => {
write!(buf, "[")?;
print_type_ref(elem, buf)?;
write!(buf, "; {}]", len)?;
write!(buf, "; {len}]")?;
}
TypeRef::Slice(elem) => {
write!(buf, "[")?;
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-expand/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ fn macro_expand(db: &dyn AstDatabase, id: MacroCallId) -> ExpandResult<Option<Ar
// be reported at the definition site (when we construct a def map).
Err(err) => {
return ExpandResult::only_err(ExpandError::Other(
format!("invalid macro definition: {}", err).into(),
format!("invalid macro definition: {err}").into(),
))
}
};
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-expand/src/eager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ pub fn expand_eager_macro(

Ok(Ok(db.intern_macro_call(loc)))
} else {
panic!("called `expand_eager_macro` on non-eager macro def {:?}", def);
panic!("called `expand_eager_macro` on non-eager macro def {def:?}");
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/hir-expand/src/fixup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ mod tests {
fixups.append,
);

let actual = format!("{}\n", tt);
let actual = format!("{tt}\n");

expect.indent(false);
expect.assert_eq(&actual);
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-expand/src/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ mod tests {

let quoted = quote!(#a);
assert_eq!(quoted.to_string(), "hello");
let t = format!("{:?}", quoted);
let t = format!("{quoted:?}");
assert_eq!(t, "SUBTREE $\n IDENT hello 4294967295");
}

Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl<D> TyBuilder<D> {
match (a.data(Interner), e) {
(chalk_ir::GenericArgData::Ty(_), ParamKind::Type)
| (chalk_ir::GenericArgData::Const(_), ParamKind::Const(_)) => (),
_ => panic!("Mismatched kinds: {:?}, {:?}, {:?}", a, self.vec, self.param_kinds),
_ => panic!("Mismatched kinds: {a:?}, {:?}, {:?}", self.vec, self.param_kinds),
}
}
}
Expand Down
Loading

0 comments on commit 2872e05

Please sign in to comment.