about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-03-28 00:26:52 -0700
committerbors <bors@rust-lang.org>2014-03-28 00:26:52 -0700
commitff64381c8bf6a49a0671287de5f5b7316ae2ef9c (patch)
tree8b506d4d1a0fe9b5242ed1ab4817c91890c929c3 /src/libsyntax/parse
parent5a68892507cdd42fdf6f1f645d6e38f6f5be67a4 (diff)
parentf1739b14a1346419a4598339aee32aab07e0d12e (diff)
downloadrust-ff64381c8bf6a49a0671287de5f5b7316ae2ef9c.tar.gz
rust-ff64381c8bf6a49a0671287de5f5b7316ae2ef9c.zip
auto merge of #13107 : seanmonstar/rust/encoder-errors, r=erickt
All of Decoder and Encoder's methods now return a Result.

Encodable.encode() and Decodable.decode() return a Result as well.

fixes #12292
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/mod.rs11
-rw-r--r--src/libsyntax/parse/token.rs17
2 files changed, 27 insertions, 1 deletions
diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs
index eb6b462fb94..2df93deea14 100644
--- a/src/libsyntax/parse/mod.rs
+++ b/src/libsyntax/parse/mod.rs
@@ -288,7 +288,8 @@ mod test {
     use util::parser_testing::{string_to_expr, string_to_item};
     use util::parser_testing::string_to_stmt;
 
-    #[cfg(test)]
+    // FIXME: remove stage0 to_json_str after snapshot
+    #[cfg(stage0)]
     fn to_json_str<'a, E: Encodable<json::Encoder<'a>>>(val: &E) -> ~str {
         let mut writer = MemWriter::new();
         let mut encoder = json::Encoder::new(&mut writer as &mut io::Writer);
@@ -296,6 +297,14 @@ mod test {
         str::from_utf8_owned(writer.unwrap()).unwrap()
     }
 
+    #[cfg(not(stage0))]
+    fn to_json_str<'a, E: Encodable<json::Encoder<'a>, io::IoError>>(val: &E) -> ~str {
+        let mut writer = MemWriter::new();
+        let mut encoder = json::Encoder::new(&mut writer as &mut io::Writer);
+        let _ = val.encode(&mut encoder);
+        str::from_utf8_owned(writer.unwrap()).unwrap()
+    }
+
     // produce a codemap::span
     fn sp(a: u32, b: u32) -> Span {
         Span{lo:BytePos(a),hi:BytePos(b),expn_info:None}
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs
index 15525912955..7bb920bdf56 100644
--- a/src/libsyntax/parse/token.rs
+++ b/src/libsyntax/parse/token.rs
@@ -602,18 +602,35 @@ impl<'a> Equiv<&'a str> for InternedString {
     }
 }
 
+// FIXME: remove stage0 Encodables/Decodables after snapshot
+#[cfg(stage0)]
 impl<D:Decoder> Decodable<D> for InternedString {
     fn decode(d: &mut D) -> InternedString {
         get_name(get_ident_interner().intern(d.read_str()))
     }
 }
 
+#[cfg(stage0)]
 impl<E:Encoder> Encodable<E> for InternedString {
     fn encode(&self, e: &mut E) {
         e.emit_str(self.string.as_slice())
     }
 }
 
+#[cfg(not(stage0))]
+impl<D:Decoder<E>, E> Decodable<D, E> for InternedString {
+    fn decode(d: &mut D) -> Result<InternedString, E> {
+        Ok(get_name(get_ident_interner().intern(try!(d.read_str()))))
+    }
+}
+
+#[cfg(not(stage0))]
+impl<S:Encoder<E>, E> Encodable<S, E> for InternedString {
+    fn encode(&self, s: &mut S) -> Result<(), E> {
+        s.emit_str(self.string.as_slice())
+    }
+}
+
 /// Returns the string contents of a name, using the task-local interner.
 #[inline]
 pub fn get_name(name: Name) -> InternedString {