mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 11:59:49 +00:00
Avoid ref when using format! in compiler
Clean up a few minor refs in `format!` macro, as it has a performance cost. Apparently the compiler is unable to inline `format!("{}", &variable)`, and does a run-time double-reference instead (format macro already does one level referencing). Inlining format args prevents accidental `&` misuse.
This commit is contained in:
parent
9fd6c695da
commit
cc1aded86c
8 changed files with 13 additions and 13 deletions
|
@ -43,7 +43,7 @@ pub(crate) fn bind_unused_param(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
|
||||||
|
|
||||||
acc.add(
|
acc.add(
|
||||||
AssistId("bind_unused_param", AssistKind::QuickFix),
|
AssistId("bind_unused_param", AssistKind::QuickFix),
|
||||||
&format!("Bind as `let _ = {};`", &ident_pat),
|
&format!("Bind as `let _ = {ident_pat};`"),
|
||||||
param.syntax().text_range(),
|
param.syntax().text_range(),
|
||||||
|builder| {
|
|builder| {
|
||||||
let line_index = ctx.db().line_index(ctx.file_id().into());
|
let line_index = ctx.db().line_index(ctx.file_id().into());
|
||||||
|
|
|
@ -664,7 +664,7 @@ mod tests {
|
||||||
/// If provided vec![vec![a], vec![b, c], vec![d]], then this will assert:
|
/// If provided vec![vec![a], vec![b, c], vec![d]], then this will assert:
|
||||||
/// a.score < b.score == c.score < d.score
|
/// a.score < b.score == c.score < d.score
|
||||||
fn check_relevance_score_ordered(expected_relevance_order: Vec<Vec<CompletionRelevance>>) {
|
fn check_relevance_score_ordered(expected_relevance_order: Vec<Vec<CompletionRelevance>>) {
|
||||||
let expected = format!("{:#?}", &expected_relevance_order);
|
let expected = format!("{expected_relevance_order:#?}");
|
||||||
|
|
||||||
let actual_relevance_order = expected_relevance_order
|
let actual_relevance_order = expected_relevance_order
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -685,7 +685,7 @@ mod tests {
|
||||||
)
|
)
|
||||||
.1;
|
.1;
|
||||||
|
|
||||||
let actual = format!("{:#?}", &actual_relevance_order);
|
let actual = format!("{actual_relevance_order:#?}");
|
||||||
|
|
||||||
assert_eq_text!(&expected, &actual);
|
assert_eq_text!(&expected, &actual);
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::TypedHole) -> Option<Vec<Assist>
|
||||||
.unique()
|
.unique()
|
||||||
.map(|code| Assist {
|
.map(|code| Assist {
|
||||||
id: AssistId("typed-hole", AssistKind::QuickFix),
|
id: AssistId("typed-hole", AssistKind::QuickFix),
|
||||||
label: Label::new(format!("Replace `_` with `{}`", &code)),
|
label: Label::new(format!("Replace `_` with `{code}`")),
|
||||||
group: Some(GroupLabel("Replace `_` with a term".to_owned())),
|
group: Some(GroupLabel("Replace `_` with a term".to_owned())),
|
||||||
target: original_range.range,
|
target: original_range.range,
|
||||||
source_change: Some(SourceChange::from_text_edit(
|
source_change: Some(SourceChange::from_text_edit(
|
||||||
|
|
|
@ -516,7 +516,7 @@ mod tests {
|
||||||
match result {
|
match result {
|
||||||
Ok(RangeInfo { range, info: () }) => {
|
Ok(RangeInfo { range, info: () }) => {
|
||||||
let source = analysis.file_text(position.file_id).unwrap();
|
let source = analysis.file_text(position.file_id).unwrap();
|
||||||
expect.assert_eq(&format!("{range:?}: {}", &source[range]))
|
expect.assert_eq(&format!("{range:?}: {}", source[range]))
|
||||||
}
|
}
|
||||||
Err(RenameError(err)) => expect.assert_eq(&err),
|
Err(RenameError(err)) => expect.assert_eq(&err),
|
||||||
};
|
};
|
||||||
|
|
|
@ -422,7 +422,7 @@ impl flags::AnalysisStats {
|
||||||
if found_terms.is_empty() {
|
if found_terms.is_empty() {
|
||||||
acc.tail_expr_no_term += 1;
|
acc.tail_expr_no_term += 1;
|
||||||
acc.total_tail_exprs += 1;
|
acc.total_tail_exprs += 1;
|
||||||
// println!("\n{}\n", &original_text);
|
// println!("\n{original_text}\n");
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ impl GlobalState {
|
||||||
pub(crate) fn show_and_log_error(&mut self, message: String, additional_info: Option<String>) {
|
pub(crate) fn show_and_log_error(&mut self, message: String, additional_info: Option<String>) {
|
||||||
match additional_info {
|
match additional_info {
|
||||||
Some(additional_info) => {
|
Some(additional_info) => {
|
||||||
tracing::error!("{}:\n{}", &message, &additional_info);
|
tracing::error!("{message}:\n{additional_info}");
|
||||||
self.show_message(
|
self.show_message(
|
||||||
lsp_types::MessageType::ERROR,
|
lsp_types::MessageType::ERROR,
|
||||||
message,
|
message,
|
||||||
|
@ -87,7 +87,7 @@ impl GlobalState {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
tracing::error!("{}", &message);
|
tracing::error!("{message}");
|
||||||
self.send_notification::<lsp_types::notification::ShowMessage>(
|
self.send_notification::<lsp_types::notification::ShowMessage>(
|
||||||
lsp_types::ShowMessageParams { typ: lsp_types::MessageType::ERROR, message },
|
lsp_types::ShowMessageParams { typ: lsp_types::MessageType::ERROR, message },
|
||||||
);
|
);
|
||||||
|
|
|
@ -643,7 +643,7 @@ fn main() {
|
||||||
let deletions = diff
|
let deletions = diff
|
||||||
.deletions
|
.deletions
|
||||||
.iter()
|
.iter()
|
||||||
.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{insertions}\n\nreplacements:\n\n{replacements}\n\ndeletions:\n\n{deletions}\n"
|
"insertions:\n\n{insertions}\n\nreplacements:\n\n{replacements}\n\ndeletions:\n\n{deletions}\n"
|
||||||
|
|
|
@ -179,18 +179,18 @@ pub fn ty_alias(
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(list) = type_param_bounds {
|
if let Some(list) = type_param_bounds {
|
||||||
s.push_str(&format!(" : {}", &list));
|
s.push_str(&format!(" : {list}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(cl) = where_clause {
|
if let Some(cl) = where_clause {
|
||||||
s.push_str(&format!(" {}", &cl.to_string()));
|
s.push_str(&format!(" {cl}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(exp) = assignment {
|
if let Some(exp) = assignment {
|
||||||
if let Some(cl) = exp.1 {
|
if let Some(cl) = exp.1 {
|
||||||
s.push_str(&format!(" = {} {}", &exp.0.to_string(), &cl.to_string()));
|
s.push_str(&format!(" = {} {cl}", exp.0));
|
||||||
} else {
|
} else {
|
||||||
s.push_str(&format!(" = {}", &exp.0.to_string()));
|
s.push_str(&format!(" = {}", exp.0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue