Skip to content

Commit

Permalink
avoid &str to String conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
TaKO8Ki committed Jul 20, 2022
1 parent 57a155b commit 56e7777
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
15 changes: 7 additions & 8 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,18 +390,17 @@ impl Diagnostic {
expected: DiagnosticStyledString,
found: DiagnosticStyledString,
) -> &mut Self {
let mut msg: Vec<_> =
vec![("required when trying to coerce from type `".to_string(), Style::NoStyle)];
let mut msg: Vec<_> = vec![("required when trying to coerce from type `", Style::NoStyle)];
msg.extend(expected.0.iter().map(|x| match *x {
StringPart::Normal(ref s) => (s.to_owned(), Style::NoStyle),
StringPart::Highlighted(ref s) => (s.to_owned(), Style::Highlight),
StringPart::Normal(ref s) => (s.as_str(), Style::NoStyle),
StringPart::Highlighted(ref s) => (s.as_str(), Style::Highlight),
}));
msg.push(("` to type '".to_string(), Style::NoStyle));
msg.push(("` to type '", Style::NoStyle));
msg.extend(found.0.iter().map(|x| match *x {
StringPart::Normal(ref s) => (s.to_owned(), Style::NoStyle),
StringPart::Highlighted(ref s) => (s.to_owned(), Style::Highlight),
StringPart::Normal(ref s) => (s.as_str(), Style::NoStyle),
StringPart::Highlighted(ref s) => (s.as_str(), Style::Highlight),
}));
msg.push(("`".to_string(), Style::NoStyle));
msg.push(("`", Style::NoStyle));

// For now, just attach these as notes
self.highlighted_note(msg);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2603,9 +2603,9 @@ fn show_candidates(
.skip(1)
.all(|(_, descr, _, _)| descr == descr_first)
{
descr_first.to_string()
descr_first
} else {
"item".to_string()
"item"
};
let plural_descr =
if descr.ends_with("s") { format!("{}es", descr) } else { format!("{}s", descr) };
Expand Down

0 comments on commit 56e7777

Please sign in to comment.