@@ -35,8 +35,6 @@ use rustc_data_structures::stable_hasher::StableHasher;
3535use rustc_serialize:: { Encodable , Encoder , SpecializedEncoder , opaque} ;
3636
3737use std:: hash:: Hash ;
38- use std:: io:: prelude:: * ;
39- use std:: io:: Cursor ;
4038use std:: path:: Path ;
4139use rustc_data_structures:: sync:: Lrc ;
4240use std:: u32;
@@ -52,7 +50,7 @@ use rustc::hir::intravisit::{Visitor, NestedVisitorMap};
5250use rustc:: hir:: intravisit;
5351
5452pub struct EncodeContext < ' a , ' tcx : ' a > {
55- opaque : opaque:: Encoder < ' a > ,
53+ opaque : opaque:: Encoder ,
5654 pub tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
5755 link_meta : & ' a LinkMeta ,
5856
@@ -76,7 +74,7 @@ macro_rules! encoder_methods {
7674}
7775
7876impl < ' a , ' tcx > Encoder for EncodeContext < ' a , ' tcx > {
79- type Error = <opaque:: Encoder < ' a > as Encoder >:: Error ;
77+ type Error = <opaque:: Encoder as Encoder >:: Error ;
8078
8179 fn emit_nil ( & mut self ) -> Result < ( ) , Self :: Error > {
8280 Ok ( ( ) )
@@ -480,7 +478,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
480478
481479 // Index the items
482480 i = self . position ( ) ;
483- let index = items. write_index ( & mut self . opaque . cursor ) ;
481+ let index = items. write_index ( & mut self . opaque ) ;
484482 let index_bytes = self . position ( ) - i;
485483
486484 let attrs = tcx. hir . krate_attrs ( ) ;
@@ -537,7 +535,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
537535
538536 if self . tcx . sess . meta_stats ( ) {
539537 let mut zero_bytes = 0 ;
540- for e in self . opaque . cursor . get_ref ( ) {
538+ for e in self . opaque . data . iter ( ) {
541539 if * e == 0 {
542540 zero_bytes += 1 ;
543541 }
@@ -1786,15 +1784,15 @@ pub fn encode_metadata<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
17861784 link_meta : & LinkMeta )
17871785 -> EncodedMetadata
17881786{
1789- let mut cursor = Cursor :: new ( vec ! [ ] ) ;
1790- cursor . write_all ( METADATA_HEADER ) . unwrap ( ) ;
1787+ let mut encoder = opaque :: Encoder :: new ( vec ! [ ] ) ;
1788+ encoder . emit_raw_bytes ( METADATA_HEADER ) ;
17911789
17921790 // Will be filled with the root position after encoding everything.
1793- cursor . write_all ( & [ 0 , 0 , 0 , 0 ] ) . unwrap ( ) ;
1791+ encoder . emit_raw_bytes ( & [ 0 , 0 , 0 , 0 ] ) ;
17941792
1795- let root = {
1793+ let ( root, mut result ) = {
17961794 let mut ecx = EncodeContext {
1797- opaque : opaque :: Encoder :: new ( & mut cursor ) ,
1795+ opaque : encoder ,
17981796 tcx,
17991797 link_meta,
18001798 lazy_state : LazyState :: NoNode ,
@@ -1810,9 +1808,9 @@ pub fn encode_metadata<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
18101808
18111809 // Encode all the entries and extra information in the crate,
18121810 // culminating in the `CrateRoot` which points to all of it.
1813- ecx. encode_crate_root ( )
1811+ let root = ecx. encode_crate_root ( ) ;
1812+ ( root, ecx. opaque . into_inner ( ) )
18141813 } ;
1815- let mut result = cursor. into_inner ( ) ;
18161814
18171815 // Encode the root position.
18181816 let header = METADATA_HEADER . len ( ) ;
0 commit comments