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(()) Ok(())
} else { } else {
Err(io::Error::new(io::ErrorKind::Other, format!( Err(io::Error::new(io::ErrorKind::Other, format!(
"Cargo watcher failed, the command produced no valid metadata (exit code: {:?}):\n{}", "Cargo watcher failed, the command produced no valid metadata (exit code: {exit_status:?}):\n{error}"
exit_status, error
))) )))
} }
} }

View file

@ -234,8 +234,7 @@ impl TraitData {
let item_tree = tree_id.item_tree(db); let item_tree = tree_id.item_tree(db);
let tr_def = &item_tree[tree_id.value]; let tr_def = &item_tree[tree_id.value];
let _cx = stdx::panic_context::enter(format!( let _cx = stdx::panic_context::enter(format!(
"trait_data_query({:?} -> {:?} -> {:?})", "trait_data_query({tr:?} -> {tr_loc:?} -> {tr_def:?})"
tr, tr_loc, tr_def
)); ));
let name = tr_def.name.clone(); let name = tr_def.name.clone();
let is_auto = tr_def.is_auto; 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 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 call = ast_id_map.get(call.ast_id).to_node(&root);
let _cx = stdx::panic_context::enter(format!( let _cx =
"collect_items MacroCall: {}", stdx::panic_context::enter(format!("collect_items MacroCall: {call}"));
call
));
let res = self.expander.enter_expand::<ast::MacroItems>(self.db, call); let res = self.expander.enter_expand::<ast::MacroItems>(self.db, call);
if let Ok(ExpandResult { value: Some((mark, _)), .. }) = res { 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 impl_data = db.impl_data(impl_id);
let resolver = impl_id.resolver(db.upcast()); let resolver = impl_id.resolver(db.upcast());
let _cx = stdx::panic_context::enter(format!( let _cx = stdx::panic_context::enter(format!(
"impl_self_ty_query({:?} -> {:?} -> {:?})", "impl_self_ty_query({impl_id:?} -> {impl_loc:?} -> {impl_data:?})"
impl_id, impl_loc, impl_data
)); ));
let generics = generics(db.upcast(), impl_id.into()); let generics = generics(db.upcast(), impl_id.into());
let ctx = 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 impl_data = db.impl_data(impl_id);
let resolver = impl_id.resolver(db.upcast()); let resolver = impl_id.resolver(db.upcast());
let _cx = stdx::panic_context::enter(format!( let _cx = stdx::panic_context::enter(format!(
"impl_trait_query({:?} -> {:?} -> {:?})", "impl_trait_query({impl_id:?} -> {impl_loc:?} -> {impl_data:?})"
impl_id, impl_loc, impl_data
)); ));
let ctx = let ctx =
TyLoweringContext::new(db, &resolver).with_type_param_mode(ParamLoweringMode::Variable); TyLoweringContext::new(db, &resolver).with_type_param_mode(ParamLoweringMode::Variable);

View file

@ -95,8 +95,7 @@ impl Assist {
let id = block.id; let id = block.id;
assert!( assert!(
id.chars().all(|it| it.is_ascii_lowercase() || it == '_'), id.chars().all(|it| it.is_ascii_lowercase() || it == '_'),
"invalid assist id: {:?}", "invalid assist id: {id:?}"
id
); );
let mut lines = block.contents.iter().peekable(); let mut lines = block.contents.iter().peekable();
let location = sourcegen::Location { file: path.to_path_buf(), line: block.line }; 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| { attrs.for_each(|next| {
assert!( assert!(
prev < next, prev < next,
r#"ATTRIBUTES array is not sorted, "{}" should come after "{}""#, r#"ATTRIBUTES array is not sorted, "{prev}" should come after "{next}""#
prev,
next
); );
prev = next; prev = next;
}); });

View file

@ -68,28 +68,26 @@ mod tests {
&format!( &format!(
r#" r#"
#[rustc_builtin_macro] #[rustc_builtin_macro]
macro_rules! {} {{ macro_rules! {macro_name} {{
($var:literal) => {{ 0 }} ($var:literal) => {{ 0 }}
}} }}
fn main() {{ fn main() {{
let foo = {}!("CAR$0"); let foo = {macro_name}!("CAR$0");
}} }}
"#, "#
macro_name, macro_name
), ),
&format!( &format!(
r#" r#"
#[rustc_builtin_macro] #[rustc_builtin_macro]
macro_rules! {} {{ macro_rules! {macro_name} {{
($var:literal) => {{ 0 }} ($var:literal) => {{ 0 }}
}} }}
fn main() {{ 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; struct T;
impl Test for T {{ impl Test for T {{
{} {hint}
{} {next_sibling}
}} }}
"#, "#
hint, next_sibling
), ),
&format!( &format!(
r#" r#"
@ -861,11 +860,10 @@ trait Test {{
struct T; struct T;
impl Test for T {{ impl Test for T {{
{} {completed}
{} {next_sibling}
}} }}
"#, "#
completed, next_sibling
), ),
) )
}; };
@ -905,10 +903,9 @@ struct T;
impl Foo for T {{ impl Foo for T {{
// Comment // Comment
#[bar] #[bar]
{} {hint}
}} }}
"#, "#
hint
), ),
&format!( &format!(
r#" r#"
@ -922,10 +919,9 @@ struct T;
impl Foo for T {{ impl Foo for T {{
// Comment // Comment
#[bar] #[bar]
{} {completed}
}} }}
"#, "#
completed
), ),
) )
}; };

View file

@ -153,8 +153,7 @@ pub(crate) fn complete_postfix(
"match", "match",
"match expr {}", "match expr {}",
&format!( &format!(
"match {} {{\n Some(${{1:_}}) => {{$2}},\n None => {{$0}},\n}}", "match {receiver_text} {{\n Some(${{1:_}}) => {{$2}},\n None => {{$0}},\n}}"
receiver_text
), ),
) )
.add_to(acc); .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 attr = attr.map(|attr| parse_string(attr).unwrap().into_subtree());
let res = expander.expand(macro_name, &fixture.into_subtree(), attr.as_ref()).unwrap(); 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> { pub(crate) fn list() -> Vec<String> {
let dylib_path = proc_macro_test_dylib_path(); let dylib_path = proc_macro_test_dylib_path();
let mut srv = ProcMacroSrv::default(); let mut srv = ProcMacroSrv::default();
let res = srv.list_macros(&dylib_path).unwrap(); 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!("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), Ok(it) => acc.push(it),
Err(err) => { Err(err) => {
push_err(&format!( push_err(&format!(
"invalid cfg from cargo-metadata: {}", "invalid cfg from cargo-metadata: {err}"
err
)); ));
return; 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'); let doc = doc.trim_end_matches('\n');
assert!( assert!(
doc.ends_with('.') && doc.starts_with(char::is_uppercase), doc.ends_with('.') && doc.starts_with(char::is_uppercase),
"bad docs for {}: {:?}", "bad docs for {field}: {doc:?}"
field,
doc
); );
let default = default.parse::<serde_json::Value>().unwrap(); 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); let doc = doc_comment_to_string(doc);
if default.contains('\n') { if default.contains('\n') {
format!( format!(
r#"[[{}]]{}:: r#"[[{name}]]{name}::
+ +
-- --
Default: Default:
---- ----
{} {default}
---- ----
{} {doc}
-- --
"#, "#
name, name, default, doc
) )
} else { } else {
format!("[[{name}]]{name} (default: `{default}`)::\n+\n--\n{doc}--\n") 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> { fn clippy_code_description(code: Option<&str>) -> Option<lsp_types::CodeDescription> {
code.and_then(|code| { code.and_then(|code| {
lsp_types::Url::parse(&format!( lsp_types::Url::parse(&format!(
"https://rust-lang.github.io/rust-clippy/master/index.html#{}", "https://rust-lang.github.io/rust-clippy/master/index.html#{code}"
code
)) ))
.ok() .ok()
.map(|href| lsp_types::CodeDescription { href }) .map(|href| lsp_types::CodeDescription { href })

View file

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

View file

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

View file

@ -56,12 +56,11 @@ fn check_lsp_extensions_docs() {
" "
lsp_ext.rs was changed without touching lsp-extensions.md. lsp_ext.rs was changed without touching lsp-extensions.md.
Expected hash: {:x} Expected hash: {expected_hash:x}
Actual hash: {:x} Actual hash: {actual_hash:x}
Please adjust docs/dev/lsp-extensions.md. 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); let first = block.contents.remove(0);
first.strip_prefix(&tag).map(|id| { first.strip_prefix(&tag).map(|id| {
if block.is_doc { if block.is_doc {
panic!( panic!("Use plain (non-doc) comments with tags like {tag}:\n {first}");
"Use plain (non-doc) comments with tags like {}:\n {}",
tag, first
);
} }
block.id = id.trim().to_string(); 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)))); .format_with("\n", |v, f| f(&format!("Line {}: {}", line_number(v), &fmt_syntax(v))));
let actual = format!( let actual = format!(
"insertions:\n\n{}\n\nreplacements:\n\n{}\n\ndeletions:\n\n{}\n", "insertions:\n\n{insertions}\n\nreplacements:\n\n{replacements}\n\ndeletions:\n\n{deletions}\n"
insertions, replacements, deletions
); );
expected_diff.assert_eq(&actual); expected_diff.assert_eq(&actual);

View file

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

View file

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

View file

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