mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-23 02:27:39 +03:00
Rollup merge of #54932 - ljedrz:a_handful_of_string_improvements, r=alexcrichton
A handful of random string-related improvements - remove a few allocations in `errors/diagnostic` - make `build_helper::gnu_target` return `Cow<str>`
This commit is contained in:
@@ -91,13 +91,13 @@ pub fn try_run_suppressed(cmd: &mut Command) -> bool {
|
||||
output.status.success()
|
||||
}
|
||||
|
||||
pub fn gnu_target(target: &str) -> String {
|
||||
pub fn gnu_target(target: &str) -> &str {
|
||||
match target {
|
||||
"i686-pc-windows-msvc" => "i686-pc-win32".to_string(),
|
||||
"x86_64-pc-windows-msvc" => "x86_64-pc-win32".to_string(),
|
||||
"i686-pc-windows-gnu" => "i686-w64-mingw32".to_string(),
|
||||
"x86_64-pc-windows-gnu" => "x86_64-w64-mingw32".to_string(),
|
||||
s => s.to_string(),
|
||||
"i686-pc-windows-msvc" => "i686-pc-win32",
|
||||
"x86_64-pc-windows-msvc" => "x86_64-pc-win32",
|
||||
"i686-pc-windows-gnu" => "i686-w64-mingw32",
|
||||
"x86_64-pc-windows-gnu" => "x86_64-w64-mingw32",
|
||||
s => s,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,9 +76,9 @@ pub enum StringPart {
|
||||
}
|
||||
|
||||
impl StringPart {
|
||||
pub fn content(&self) -> String {
|
||||
pub fn content(&self) -> &str {
|
||||
match self {
|
||||
&StringPart::Normal(ref s) | & StringPart::Highlighted(ref s) => s.to_owned()
|
||||
&StringPart::Normal(ref s) | & StringPart::Highlighted(ref s) => s
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -398,7 +398,7 @@ pub fn get_code(&self) -> Option<DiagnosticId> {
|
||||
}
|
||||
|
||||
pub fn message(&self) -> String {
|
||||
self.message.iter().map(|i| i.0.to_owned()).collect::<String>()
|
||||
self.message.iter().map(|i| i.0.as_str()).collect::<String>()
|
||||
}
|
||||
|
||||
pub fn styled_message(&self) -> &Vec<(String, Style)> {
|
||||
@@ -448,7 +448,7 @@ fn sub_with_highlights(&mut self,
|
||||
|
||||
impl SubDiagnostic {
|
||||
pub fn message(&self) -> String {
|
||||
self.message.iter().map(|i| i.0.to_owned()).collect::<String>()
|
||||
self.message.iter().map(|i| i.0.as_str()).collect::<String>()
|
||||
}
|
||||
|
||||
pub fn styled_message(&self) -> &Vec<(String, Style)> {
|
||||
|
||||
Reference in New Issue
Block a user