use inline format args

This commit is contained in:
Daniel Eades 2022-12-30 07:59:11 +00:00
parent 17cc78f169
commit 77051679d7
21 changed files with 61 additions and 109 deletions

View file

@ -408,8 +408,7 @@ impl CargoHandle {
Ok(())
} else {
Err(io::Error::new(io::ErrorKind::Other, format!(
"Cargo watcher failed, the command produced no valid metadata (exit code: {:?}):\n{}",
exit_status, error
"Cargo watcher failed, the command produced no valid metadata (exit code: {exit_status:?}):\n{error}"
)))
}
}

View file

@ -234,8 +234,7 @@ impl TraitData {
let item_tree = tree_id.item_tree(db);
let tr_def = &item_tree[tree_id.value];
let _cx = stdx::panic_context::enter(format!(
"trait_data_query({:?} -> {:?} -> {:?})",
tr, tr_loc, tr_def
"trait_data_query({tr:?} -> {tr_loc:?} -> {tr_def:?})"
));
let name = tr_def.name.clone();
let is_auto = tr_def.is_auto;
@ -619,10 +618,8 @@ impl<'a> AssocItemCollector<'a> {
let ast_id_map = self.db.ast_id_map(self.expander.current_file_id());
let call = ast_id_map.get(call.ast_id).to_node(&root);
let _cx = stdx::panic_context::enter(format!(
"collect_items MacroCall: {}",
call
));
let _cx =
stdx::panic_context::enter(format!("collect_items MacroCall: {call}"));
let res = self.expander.enter_expand::<ast::MacroItems>(self.db, call);
if let Ok(ExpandResult { value: Some((mark, _)), .. }) = res {

View file

@ -1796,8 +1796,7 @@ pub(crate) fn impl_self_ty_query(db: &dyn HirDatabase, impl_id: ImplId) -> Binde
let impl_data = db.impl_data(impl_id);
let resolver = impl_id.resolver(db.upcast());
let _cx = stdx::panic_context::enter(format!(
"impl_self_ty_query({:?} -> {:?} -> {:?})",
impl_id, impl_loc, impl_data
"impl_self_ty_query({impl_id:?} -> {impl_loc:?} -> {impl_data:?})"
));
let generics = generics(db.upcast(), impl_id.into());
let ctx =
@ -1834,8 +1833,7 @@ pub(crate) fn impl_trait_query(db: &dyn HirDatabase, impl_id: ImplId) -> Option<
let impl_data = db.impl_data(impl_id);
let resolver = impl_id.resolver(db.upcast());
let _cx = stdx::panic_context::enter(format!(
"impl_trait_query({:?} -> {:?} -> {:?})",
impl_id, impl_loc, impl_data
"impl_trait_query({impl_id:?} -> {impl_loc:?} -> {impl_data:?})"
));
let ctx =
TyLoweringContext::new(db, &resolver).with_type_param_mode(ParamLoweringMode::Variable);

View file

@ -95,8 +95,7 @@ impl Assist {
let id = block.id;
assert!(
id.chars().all(|it| it.is_ascii_lowercase() || it == '_'),
"invalid assist id: {:?}",
id
"invalid assist id: {id:?}"
);
let mut lines = block.contents.iter().peekable();
let location = sourcegen::Location { file: path.to_path_buf(), line: block.line };

View file

@ -371,9 +371,7 @@ fn attributes_are_sorted() {
attrs.for_each(|next| {
assert!(
prev < next,
r#"ATTRIBUTES array is not sorted, "{}" should come after "{}""#,
prev,
next
r#"ATTRIBUTES array is not sorted, "{prev}" should come after "{next}""#
);
prev = next;
});

View file

@ -68,28 +68,26 @@ mod tests {
&format!(
r#"
#[rustc_builtin_macro]
macro_rules! {} {{
macro_rules! {macro_name} {{
($var:literal) => {{ 0 }}
}}
fn main() {{
let foo = {}!("CAR$0");
let foo = {macro_name}!("CAR$0");
}}
"#,
macro_name, macro_name
"#
),
&format!(
r#"
#[rustc_builtin_macro]
macro_rules! {} {{
macro_rules! {macro_name} {{
($var:literal) => {{ 0 }}
}}
fn main() {{
let foo = {}!("CARGO_BIN_NAME");
let foo = {macro_name}!("CARGO_BIN_NAME");
}}
"#,
macro_name, macro_name
"#
),
);
}

View file

@ -845,11 +845,10 @@ trait Test {{
struct T;
impl Test for T {{
{}
{}
{hint}
{next_sibling}
}}
"#,
hint, next_sibling
"#
),
&format!(
r#"
@ -861,11 +860,10 @@ trait Test {{
struct T;
impl Test for T {{
{}
{}
{completed}
{next_sibling}
}}
"#,
completed, next_sibling
"#
),
)
};
@ -905,10 +903,9 @@ struct T;
impl Foo for T {{
// Comment
#[bar]
{}
{hint}
}}
"#,
hint
"#
),
&format!(
r#"
@ -922,10 +919,9 @@ struct T;
impl Foo for T {{
// Comment
#[bar]
{}
{completed}
}}
"#,
completed
"#
),
)
};

View file

@ -153,8 +153,7 @@ pub(crate) fn complete_postfix(
"match",
"match expr {}",
&format!(
"match {} {{\n Some(${{1:_}}) => {{$2}},\n None => {{$0}},\n}}",
receiver_text
"match {receiver_text} {{\n Some(${{1:_}}) => {{$2}},\n None => {{$0}},\n}}"
),
)
.add_to(acc);

View file

@ -30,12 +30,12 @@ fn assert_expand_impl(macro_name: &str, input: &str, attr: Option<&str>, expect:
let attr = attr.map(|attr| parse_string(attr).unwrap().into_subtree());
let res = expander.expand(macro_name, &fixture.into_subtree(), attr.as_ref()).unwrap();
expect.assert_eq(&format!("{:?}", res));
expect.assert_eq(&format!("{res:?}"));
}
pub(crate) fn list() -> Vec<String> {
let dylib_path = proc_macro_test_dylib_path();
let mut srv = ProcMacroSrv::default();
let res = srv.list_macros(&dylib_path).unwrap();
res.into_iter().map(|(name, kind)| format!("{} [{:?}]", name, kind)).collect()
res.into_iter().map(|(name, kind)| format!("{name} [{kind:?}]")).collect()
}

View file

@ -118,7 +118,7 @@ impl Drop for CpuSpan {
eprintln!("Profile rendered to:\n\n {}\n", svg.display());
}
_ => {
eprintln!("Failed to run:\n\n {:?}\n", cmd);
eprintln!("Failed to run:\n\n {cmd:?}\n");
}
}
}

View file

@ -303,8 +303,7 @@ impl WorkspaceBuildScripts {
Ok(it) => acc.push(it),
Err(err) => {
push_err(&format!(
"invalid cfg from cargo-metadata: {}",
err
"invalid cfg from cargo-metadata: {err}"
));
return;
}

View file

@ -1908,9 +1908,7 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
let doc = doc.trim_end_matches('\n');
assert!(
doc.ends_with('.') && doc.starts_with(char::is_uppercase),
"bad docs for {}: {:?}",
field,
doc
"bad docs for {field}: {doc:?}"
);
let default = default.parse::<serde_json::Value>().unwrap();
@ -2213,17 +2211,16 @@ fn manual(fields: &[(&'static str, &'static str, &[&str], &str)]) -> String {
let doc = doc_comment_to_string(doc);
if default.contains('\n') {
format!(
r#"[[{}]]{}::
r#"[[{name}]]{name}::
+
--
Default:
----
{}
{default}
----
{}
{doc}
--
"#,
name, name, default, doc
"#
)
} else {
format!("[[{name}]]{name} (default: `{default}`)::\n+\n--\n{doc}--\n")

View file

@ -502,8 +502,7 @@ fn rustc_code_description(code: Option<&str>) -> Option<lsp_types::CodeDescripti
fn clippy_code_description(code: Option<&str>) -> Option<lsp_types::CodeDescription> {
code.and_then(|code| {
lsp_types::Url::parse(&format!(
"https://rust-lang.github.io/rust-clippy/master/index.html#{}",
code
"https://rust-lang.github.io/rust-clippy/master/index.html#{code}"
))
.ok()
.map(|href| lsp_types::CodeDescription { href })

View file

@ -414,10 +414,7 @@ impl GlobalState {
let loop_duration = loop_start.elapsed();
if loop_duration > Duration::from_millis(100) && was_quiescent {
tracing::warn!("overly long loop turn: {:?}", loop_duration);
self.poke_rust_analyzer_developer(format!(
"overly long loop turn: {:?}",
loop_duration
));
self.poke_rust_analyzer_developer(format!("overly long loop turn: {loop_duration:?}"));
}
Ok(())
}

View file

@ -528,14 +528,13 @@ fn test_missing_module_code_action_in_json_project() {
let code = format!(
r#"
//- /rust-project.json
{PROJECT}
{project}
//- /src/lib.rs
mod bar;
fn main() {{}}
"#,
PROJECT = project,
);
let server =
@ -605,13 +604,12 @@ name = "foo"
version = "0.0.0"
//- /src/lib.rs
{}
{librs}
{}
{libs}
fn main() {{}}
"#,
librs, libs
"#
))
.with_config(serde_json::json!({
"cargo": { "sysroot": "discover" }

View file

@ -56,12 +56,11 @@ fn check_lsp_extensions_docs() {
"
lsp_ext.rs was changed without touching lsp-extensions.md.
Expected hash: {:x}
Actual hash: {:x}
Expected hash: {expected_hash:x}
Actual hash: {actual_hash:x}
Please adjust docs/dev/lsp-extensions.md.
",
expected_hash, actual_hash
"
)
}
}

View file

@ -65,10 +65,7 @@ impl CommentBlock {
let first = block.contents.remove(0);
first.strip_prefix(&tag).map(|id| {
if block.is_doc {
panic!(
"Use plain (non-doc) comments with tags like {}:\n {}",
tag, first
);
panic!("Use plain (non-doc) comments with tags like {tag}:\n {first}");
}
block.id = id.trim().to_string();

View file

@ -646,8 +646,7 @@ fn main() {
.format_with("\n", |v, f| f(&format!("Line {}: {}", line_number(v), &fmt_syntax(v))));
let actual = format!(
"insertions:\n\n{}\n\nreplacements:\n\n{}\n\ndeletions:\n\n{}\n",
insertions, replacements, deletions
"insertions:\n\n{insertions}\n\nreplacements:\n\n{replacements}\n\ndeletions:\n\n{deletions}\n"
);
expected_diff.assert_eq(&actual);

View file

@ -135,11 +135,9 @@ impl Fixture {
if line.contains("//-") {
assert!(
line.starts_with("//-"),
"Metadata line {} has invalid indentation. \
"Metadata line {ix} has invalid indentation. \
All metadata lines need to have the same indentation.\n\
The offending line: {:?}",
ix,
line
The offending line: {line:?}"
);
}
@ -222,9 +220,7 @@ impl Fixture {
for prelude_dep in extern_prelude.iter().flatten() {
assert!(
deps.contains(prelude_dep),
"extern-prelude {:?} must be a subset of deps {:?}",
extern_prelude,
deps
"extern-prelude {extern_prelude:?} must be a subset of deps {deps:?}"
);
}
@ -348,11 +344,7 @@ impl MiniCore {
let mut keep = true;
for &region in &active_regions {
assert!(
!region.starts_with(' '),
"region marker starts with a space: {:?}",
region
);
assert!(!region.starts_with(' '), "region marker starts with a space: {region:?}");
self.assert_valid_flag(region);
seen_regions.push(region);
keep &= self.has_flag(region);

View file

@ -128,15 +128,11 @@ impl Connection {
self.sender.send(resp.into()).unwrap();
}
Ok(msg) => {
return Err(ProtocolError(format!(
"expected initialize request, got {:?}",
msg
)))
return Err(ProtocolError(format!("expected initialize request, got {msg:?}")))
}
Err(e) => {
return Err(ProtocolError(format!(
"expected initialize request, got error: {}",
e
"expected initialize request, got error: {e}"
)))
}
};
@ -154,15 +150,11 @@ impl Connection {
match &self.receiver.recv() {
Ok(Message::Notification(n)) if n.is_initialized() => (),
Ok(msg) => {
return Err(ProtocolError(format!(
"expected Message::Notification, got: {:?}",
msg,
)))
return Err(ProtocolError(format!("expected Message::Notification, got: {msg:?}",)))
}
Err(e) => {
return Err(ProtocolError(format!(
"expected initialized notification, got error: {}",
e,
"expected initialized notification, got error: {e}",
)))
}
}

View file

@ -63,31 +63,30 @@ pub(crate) fn get_changelog(
let contents = format!(
"\
= Changelog #{}
= Changelog #{changelog_n}
:sectanchors:
:experimental:
:page-layout: post
Commit: commit:{}[] +
Release: release:{}[]
Commit: commit:{commit}[] +
Release: release:{today}[]
== New Features
{}
{features}
== Fixes
{}
{fixes}
== Internal Improvements
{}
{internal}
== Others
{}
",
changelog_n, commit, today, features, fixes, internal, others
{others}
"
);
Ok(contents)
}