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
|
@ -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:?}"))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -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}")
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
@ -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(
|
||||
|
|
|
@ -243,7 +243,7 @@ impl fmt::Debug for ImportMap {
|
|||
ItemInNs::Values(_) => "v",
|
||||
ItemInNs::Macros(_) => "m",
|
||||
};
|
||||
format!("- {} ({})", info.path, ns)
|
||||
format!("- {} ({ns})", info.path)
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
@ -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<_> =
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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>();
|
||||
|
|
|
@ -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(),
|
||||
|
@ -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}");
|
||||
},
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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));
|
||||
|
@ -156,7 +156,7 @@ impl DirPath {
|
|||
} else {
|
||||
attr
|
||||
};
|
||||
let res = format!("{}{}", base, attr);
|
||||
let res = format!("{base}{attr}");
|
||||
res
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -13,7 +13,7 @@ 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()));
|
||||
|
||||
|
@ -21,7 +21,7 @@ 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:#?}")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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()));
|
||||
|
||||
|
@ -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:#?}")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
@ -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) => {
|
||||
|
@ -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, "[")?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue