about summary refs log tree commit diff
path: root/src/librustc/middle/astencode.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-01-03 22:24:50 -0800
committerAlex Crichton <alex@alexcrichton.com>2015-01-04 22:59:26 -0800
commit0cb7a4062a3c69bb0c54f0c9136889a1006e4f62 (patch)
tree63d90c804529054b3f8e13a8296cc10b330d2593 /src/librustc/middle/astencode.rs
parented22606c8382822efc555f72f895c560289a5c70 (diff)
downloadrust-0cb7a4062a3c69bb0c54f0c9136889a1006e4f62.tar.gz
rust-0cb7a4062a3c69bb0c54f0c9136889a1006e4f62.zip
serialize: Use assoc types + less old_orphan_check
This commit moves the libserialize crate (and will force the hand of the
rustc-serialize crate) to not require the `old_orphan_check` feature gate as
well as using associated types wherever possible. Concretely, the following
changes were made:

* The error type of `Encoder` and `Decoder` is now an associated type, meaning
  that these traits have no type parameters.

* The `Encoder` and `Decoder` type parameters on the `Encodable` and `Decodable`
  traits have moved to the corresponding method of the trait. This movement
  alleviates the dependency on `old_orphan_check` but implies that
  implementations can no longer be specialized for the type of encoder/decoder
  being implemented.

Due to the trait definitions changing, this is a:

[breaking-change]
Diffstat (limited to 'src/librustc/middle/astencode.rs')
-rw-r--r--src/librustc/middle/astencode.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs
index e4d407d66a2..269b09a5f2e 100644
--- a/src/librustc/middle/astencode.rs
+++ b/src/librustc/middle/astencode.rs
@@ -263,18 +263,27 @@ trait def_id_encoder_helpers {
     fn emit_def_id(&mut self, did: ast::DefId);
 }
 
+#[cfg(stage0)]
 impl<S:serialize::Encoder<E>, E> def_id_encoder_helpers for S {
     fn emit_def_id(&mut self, did: ast::DefId) {
         did.encode(self).ok().unwrap()
     }
 }
 
+#[cfg(not(stage0))]
+impl<S:serialize::Encoder> def_id_encoder_helpers for S {
+    fn emit_def_id(&mut self, did: ast::DefId) {
+        did.encode(self).ok().unwrap()
+    }
+}
+
 trait def_id_decoder_helpers {
     fn read_def_id(&mut self, dcx: &DecodeContext) -> ast::DefId;
     fn read_def_id_nodcx(&mut self,
                          cdata: &cstore::crate_metadata) -> ast::DefId;
 }
 
+#[cfg(stage0)]
 impl<D:serialize::Decoder<E>, E> def_id_decoder_helpers for D {
     fn read_def_id(&mut self, dcx: &DecodeContext) -> ast::DefId {
         let did: ast::DefId = Decodable::decode(self).ok().unwrap();
@@ -288,6 +297,20 @@ impl<D:serialize::Decoder<E>, E> def_id_decoder_helpers for D {
     }
 }
 
+#[cfg(not(stage0))]
+impl<D:serialize::Decoder> def_id_decoder_helpers for D {
+    fn read_def_id(&mut self, dcx: &DecodeContext) -> ast::DefId {
+        let did: ast::DefId = Decodable::decode(self).ok().unwrap();
+        did.tr(dcx)
+    }
+
+    fn read_def_id_nodcx(&mut self,
+                         cdata: &cstore::crate_metadata) -> ast::DefId {
+        let did: ast::DefId = Decodable::decode(self).ok().unwrap();
+        decoder::translate_def_id(cdata, did)
+    }
+}
+
 // ______________________________________________________________________
 // Encoding and decoding the AST itself
 //