Rollup merge of #113993 - nyurik:ref_format_errors, r=WaffleLapkin
Optimize format usage Per #112156, using `&` in `format!` may cause a small perf delay, so I tried to clean up one module at a time format usage. This PR includes a few removals of the ref in format (they do compile locally without the ref), as well as a few format inlining for consistency.
This commit is contained in:
commit
974a1c242f
@ -420,13 +420,13 @@ pub fn note_expected_found_extra(
|
|||||||
let expected_label = if expected_label.is_empty() {
|
let expected_label = if expected_label.is_empty() {
|
||||||
"expected".to_string()
|
"expected".to_string()
|
||||||
} else {
|
} else {
|
||||||
format!("expected {}", expected_label)
|
format!("expected {expected_label}")
|
||||||
};
|
};
|
||||||
let found_label = found_label.to_string();
|
let found_label = found_label.to_string();
|
||||||
let found_label = if found_label.is_empty() {
|
let found_label = if found_label.is_empty() {
|
||||||
"found".to_string()
|
"found".to_string()
|
||||||
} else {
|
} else {
|
||||||
format!("found {}", found_label)
|
format!("found {found_label}")
|
||||||
};
|
};
|
||||||
let (found_padding, expected_padding) = if expected_label.len() > found_label.len() {
|
let (found_padding, expected_padding) = if expected_label.len() > found_label.len() {
|
||||||
(expected_label.len() - found_label.len(), 0)
|
(expected_label.len() - found_label.len(), 0)
|
||||||
@ -439,13 +439,13 @@ pub fn note_expected_found_extra(
|
|||||||
StringPart::Normal(ref s) => (s.to_owned(), Style::NoStyle),
|
StringPart::Normal(ref s) => (s.to_owned(), Style::NoStyle),
|
||||||
StringPart::Highlighted(ref s) => (s.to_owned(), Style::Highlight),
|
StringPart::Highlighted(ref s) => (s.to_owned(), Style::Highlight),
|
||||||
}));
|
}));
|
||||||
msg.push((format!("`{}\n", expected_extra), Style::NoStyle));
|
msg.push((format!("`{expected_extra}\n"), Style::NoStyle));
|
||||||
msg.push((format!("{}{} `", " ".repeat(found_padding), found_label), Style::NoStyle));
|
msg.push((format!("{}{} `", " ".repeat(found_padding), found_label), Style::NoStyle));
|
||||||
msg.extend(found.0.iter().map(|x| match *x {
|
msg.extend(found.0.iter().map(|x| match *x {
|
||||||
StringPart::Normal(ref s) => (s.to_owned(), Style::NoStyle),
|
StringPart::Normal(ref s) => (s.to_owned(), Style::NoStyle),
|
||||||
StringPart::Highlighted(ref s) => (s.to_owned(), Style::Highlight),
|
StringPart::Highlighted(ref s) => (s.to_owned(), Style::Highlight),
|
||||||
}));
|
}));
|
||||||
msg.push((format!("`{}", found_extra), Style::NoStyle));
|
msg.push((format!("`{found_extra}"), Style::NoStyle));
|
||||||
|
|
||||||
// For now, just attach these as notes.
|
// For now, just attach these as notes.
|
||||||
self.highlighted_note(msg);
|
self.highlighted_note(msg);
|
||||||
@ -454,7 +454,7 @@ pub fn note_expected_found_extra(
|
|||||||
|
|
||||||
pub fn note_trait_signature(&mut self, name: Symbol, signature: String) -> &mut Self {
|
pub fn note_trait_signature(&mut self, name: Symbol, signature: String) -> &mut Self {
|
||||||
self.highlighted_note(vec![
|
self.highlighted_note(vec![
|
||||||
(format!("`{}` from trait: `", name), Style::NoStyle),
|
(format!("`{name}` from trait: `"), Style::NoStyle),
|
||||||
(signature, Style::Highlight),
|
(signature, Style::Highlight),
|
||||||
("`".to_string(), Style::NoStyle),
|
("`".to_string(), Style::NoStyle),
|
||||||
]);
|
]);
|
||||||
|
@ -102,7 +102,7 @@ fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
|||||||
|
|
||||||
impl IntoDiagnosticArg for char {
|
impl IntoDiagnosticArg for char {
|
||||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
||||||
DiagnosticArgValue::Str(Cow::Owned(format!("{:?}", self)))
|
DiagnosticArgValue::Str(Cow::Owned(format!("{self:?}")))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,12 +279,12 @@ fn primary_span_formatted<'a>(
|
|||||||
let msg = if substitution.is_empty() || sugg.style.hide_inline() {
|
let msg = if substitution.is_empty() || sugg.style.hide_inline() {
|
||||||
// This substitution is only removal OR we explicitly don't want to show the
|
// This substitution is only removal OR we explicitly don't want to show the
|
||||||
// code inline (`hide_inline`). Therefore, we don't show the substitution.
|
// code inline (`hide_inline`). Therefore, we don't show the substitution.
|
||||||
format!("help: {}", &msg)
|
format!("help: {msg}")
|
||||||
} else {
|
} else {
|
||||||
// Show the default suggestion text with the substitution
|
// Show the default suggestion text with the substitution
|
||||||
format!(
|
format!(
|
||||||
"help: {}{}: `{}`",
|
"help: {}{}: `{}`",
|
||||||
&msg,
|
msg,
|
||||||
if self.source_map().is_some_and(|sm| is_case_difference(
|
if self.source_map().is_some_and(|sm| is_case_difference(
|
||||||
sm,
|
sm,
|
||||||
substitution,
|
substitution,
|
||||||
|
@ -1485,7 +1485,7 @@ fn print_error_count(&mut self, registry: &Registry) {
|
|||||||
let _ = self.fatal(errors);
|
let _ = self.fatal(errors);
|
||||||
}
|
}
|
||||||
(_, _) => {
|
(_, _) => {
|
||||||
let _ = self.fatal(format!("{}; {}", &errors, &warnings));
|
let _ = self.fatal(format!("{errors}; {warnings}"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user