about summary refs log tree commit diff
path: root/compiler/rustc_error_messages/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_error_messages/src/lib.rs')
-rw-r--r--compiler/rustc_error_messages/src/lib.rs32
1 files changed, 14 insertions, 18 deletions
diff --git a/compiler/rustc_error_messages/src/lib.rs b/compiler/rustc_error_messages/src/lib.rs
index 0accb4ab96f..2a97c4ff7ae 100644
--- a/compiler/rustc_error_messages/src/lib.rs
+++ b/compiler/rustc_error_messages/src/lib.rs
@@ -263,8 +263,7 @@ type FluentId = Cow<'static, str>;
 #[rustc_diagnostic_item = "SubdiagnosticMessage"]
 pub enum SubdiagnosticMessage {
     /// Non-translatable diagnostic message.
-    // FIXME(davidtwco): can a `Cow<'static, str>` be used here?
-    Str(String),
+    Str(Cow<'static, str>),
     /// Translatable message which has already been translated eagerly.
     ///
     /// Some diagnostics have repeated subdiagnostics where the same interpolated variables would
@@ -275,8 +274,7 @@ pub enum SubdiagnosticMessage {
     /// incorrect diagnostics. Eager translation results in translation for a subdiagnostic
     /// happening immediately after the subdiagnostic derive's logic has been run. This variant
     /// stores messages which have been translated eagerly.
-    // FIXME(#100717): can a `Cow<'static, str>` be used here?
-    Eager(String),
+    Eager(Cow<'static, str>),
     /// Identifier of a Fluent message. Instances of this variant are generated by the
     /// `Subdiagnostic` derive.
     FluentIdentifier(FluentId),
@@ -290,17 +288,17 @@ pub enum SubdiagnosticMessage {
 
 impl From<String> for SubdiagnosticMessage {
     fn from(s: String) -> Self {
-        SubdiagnosticMessage::Str(s)
+        SubdiagnosticMessage::Str(Cow::Owned(s))
     }
 }
-impl<'a> From<&'a str> for SubdiagnosticMessage {
-    fn from(s: &'a str) -> Self {
-        SubdiagnosticMessage::Str(s.to_string())
+impl From<&'static str> for SubdiagnosticMessage {
+    fn from(s: &'static str) -> Self {
+        SubdiagnosticMessage::Str(Cow::Borrowed(s))
     }
 }
 impl From<Cow<'static, str>> for SubdiagnosticMessage {
     fn from(s: Cow<'static, str>) -> Self {
-        SubdiagnosticMessage::Str(s.to_string())
+        SubdiagnosticMessage::Str(s)
     }
 }
 
@@ -312,8 +310,7 @@ impl From<Cow<'static, str>> for SubdiagnosticMessage {
 #[rustc_diagnostic_item = "DiagnosticMessage"]
 pub enum DiagnosticMessage {
     /// Non-translatable diagnostic message.
-    // FIXME(#100717): can a `Cow<'static, str>` be used here?
-    Str(String),
+    Str(Cow<'static, str>),
     /// Translatable message which has already been translated eagerly.
     ///
     /// Some diagnostics have repeated subdiagnostics where the same interpolated variables would
@@ -324,8 +321,7 @@ pub enum DiagnosticMessage {
     /// incorrect diagnostics. Eager translation results in translation for a subdiagnostic
     /// happening immediately after the subdiagnostic derive's logic has been run. This variant
     /// stores messages which have been translated eagerly.
-    // FIXME(#100717): can a `Cow<'static, str>` be used here?
-    Eager(String),
+    Eager(Cow<'static, str>),
     /// Identifier for a Fluent message (with optional attribute) corresponding to the diagnostic
     /// message.
     ///
@@ -363,17 +359,17 @@ impl DiagnosticMessage {
 
 impl From<String> for DiagnosticMessage {
     fn from(s: String) -> Self {
-        DiagnosticMessage::Str(s)
+        DiagnosticMessage::Str(Cow::Owned(s))
     }
 }
-impl<'a> From<&'a str> for DiagnosticMessage {
-    fn from(s: &'a str) -> Self {
-        DiagnosticMessage::Str(s.to_string())
+impl From<&'static str> for DiagnosticMessage {
+    fn from(s: &'static str) -> Self {
+        DiagnosticMessage::Str(Cow::Borrowed(s))
     }
 }
 impl From<Cow<'static, str>> for DiagnosticMessage {
     fn from(s: Cow<'static, str>) -> Self {
-        DiagnosticMessage::Str(s.to_string())
+        DiagnosticMessage::Str(s)
     }
 }