about summary refs log tree commit diff
path: root/compiler/rustc_serialize/src/serialize.rs
diff options
context:
space:
mode:
authorDavid Wood <david.wood@huawei.com>2022-03-26 07:27:43 +0000
committerDavid Wood <david.wood@huawei.com>2022-04-05 07:01:02 +0100
commit7f91697b5035f8620df4de47057024c3539b55a6 (patch)
treea7f6e303b30ec5b3d675c362d474e1de0f3419ad /compiler/rustc_serialize/src/serialize.rs
parentc45f29595df6f6a178b7998bc33c76099f3c12b7 (diff)
downloadrust-7f91697b5035f8620df4de47057024c3539b55a6.tar.gz
rust-7f91697b5035f8620df4de47057024c3539b55a6.zip
errors: implement fallback diagnostic translation
This commit updates the signatures of all diagnostic functions to accept
types that can be converted into a `DiagnosticMessage`. This enables
existing diagnostic calls to continue to work as before and Fluent
identifiers to be provided. The `SessionDiagnostic` derive just
generates normal diagnostic calls, so these APIs had to be modified to
accept Fluent identifiers.

In addition, loading of the "fallback" Fluent bundle, which contains the
built-in English messages, has been implemented.

Each diagnostic now has "arguments" which correspond to variables in the
Fluent messages (necessary to render a Fluent message) but no API for
adding arguments has been added yet. Therefore, diagnostics (that do not
require interpolation) can be converted to use Fluent identifiers and
will be output as before.
Diffstat (limited to 'compiler/rustc_serialize/src/serialize.rs')
-rw-r--r--compiler/rustc_serialize/src/serialize.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/compiler/rustc_serialize/src/serialize.rs b/compiler/rustc_serialize/src/serialize.rs
index 42bf6ff2a98..d5053034ed8 100644
--- a/compiler/rustc_serialize/src/serialize.rs
+++ b/compiler/rustc_serialize/src/serialize.rs
@@ -431,6 +431,20 @@ where
     }
 }
 
+impl<'a, S: Encoder> Encodable<S> for Cow<'a, str> {
+    fn encode(&self, s: &mut S) -> Result<(), S::Error> {
+        let val: &str = self;
+        val.encode(s)
+    }
+}
+
+impl<'a, D: Decoder> Decodable<D> for Cow<'a, str> {
+    fn decode(d: &mut D) -> Cow<'static, str> {
+        let v: String = Decodable::decode(d);
+        Cow::Owned(v)
+    }
+}
+
 impl<S: Encoder, T: Encodable<S>> Encodable<S> for Option<T> {
     fn encode(&self, s: &mut S) -> Result<(), S::Error> {
         s.emit_option(|s| match *self {