@@ -135,14 +135,14 @@ impl<'a, 'tcx: 'a, T: Decodable> Lazy<T> {
135135 }
136136}
137137
138- impl < ' a , ' tcx : ' a , T : Decodable > LazySeq < T > {
138+ impl < ' a , ' tcx : ' a , T : Decodable > Lazy < [ T ] > {
139139 pub fn decode < M : Metadata < ' a , ' tcx > > (
140140 self ,
141141 meta : M ,
142142 ) -> impl Iterator < Item = T > + Captures < ' tcx > + ' a {
143143 let mut dcx = meta. decoder ( self . position ) ;
144144 dcx. lazy_state = LazyState :: NodeStart ( self . position ) ;
145- ( 0 ..self . len ) . map ( move |_| T :: decode ( & mut dcx) . unwrap ( ) )
145+ ( 0 ..self . meta ) . map ( move |_| T :: decode ( & mut dcx) . unwrap ( ) )
146146 }
147147}
148148
@@ -155,18 +155,22 @@ impl<'a, 'tcx> DecodeContext<'a, 'tcx> {
155155 self . cdata . expect ( "missing CrateMetadata in DecodeContext" )
156156 }
157157
158- fn read_lazy_distance ( & mut self , min_size : usize ) -> Result < usize , <Self as Decoder >:: Error > {
158+ fn read_lazy_with_meta < T : ?Sized + LazyMeta > (
159+ & mut self ,
160+ meta : T :: Meta ,
161+ ) -> Result < Lazy < T > , <Self as Decoder >:: Error > {
162+ let min_size = T :: min_size ( meta) ;
159163 let distance = self . read_usize ( ) ?;
160164 let position = match self . lazy_state {
161- LazyState :: NoNode => bug ! ( "read_lazy_distance : outside of a metadata node" ) ,
165+ LazyState :: NoNode => bug ! ( "read_lazy_with_meta : outside of a metadata node" ) ,
162166 LazyState :: NodeStart ( start) => {
163167 assert ! ( distance + min_size <= start) ;
164168 start - distance - min_size
165169 }
166170 LazyState :: Previous ( last_min_end) => last_min_end + distance,
167171 } ;
168172 self . lazy_state = LazyState :: Previous ( position + min_size) ;
169- Ok ( position)
173+ Ok ( Lazy :: from_position_and_meta ( position, meta ) )
170174 }
171175}
172176
@@ -232,19 +236,18 @@ impl<'a, 'tcx: 'a> TyDecoder<'a, 'tcx> for DecodeContext<'a, 'tcx> {
232236
233237impl < ' a , ' tcx , T > SpecializedDecoder < Lazy < T > > for DecodeContext < ' a , ' tcx > {
234238 fn specialized_decode ( & mut self ) -> Result < Lazy < T > , Self :: Error > {
235- Ok ( Lazy :: with_position ( self . read_lazy_distance ( Lazy :: < T > :: min_size ( ) ) ? ) )
239+ self . read_lazy_with_meta ( ( ) )
236240 }
237241}
238242
239- impl < ' a , ' tcx , T > SpecializedDecoder < LazySeq < T > > for DecodeContext < ' a , ' tcx > {
240- fn specialized_decode ( & mut self ) -> Result < LazySeq < T > , Self :: Error > {
243+ impl < ' a , ' tcx , T > SpecializedDecoder < Lazy < [ T ] > > for DecodeContext < ' a , ' tcx > {
244+ fn specialized_decode ( & mut self ) -> Result < Lazy < [ T ] > , Self :: Error > {
241245 let len = self . read_usize ( ) ?;
242- let position = if len == 0 {
243- 0
246+ if len == 0 {
247+ Ok ( Lazy :: empty ( ) )
244248 } else {
245- self . read_lazy_distance ( LazySeq :: < T > :: min_size ( len) ) ?
246- } ;
247- Ok ( LazySeq :: with_position_and_length ( position, len) )
249+ self . read_lazy_with_meta ( len)
250+ }
248251 }
249252}
250253
@@ -372,7 +375,7 @@ impl<'tcx> MetadataBlob {
372375 }
373376
374377 pub fn get_rustc_version ( & self ) -> String {
375- Lazy :: with_position ( METADATA_HEADER . len ( ) + 4 ) . decode ( self )
378+ Lazy :: < String > :: from_position ( METADATA_HEADER . len ( ) + 4 ) . decode ( self )
376379 }
377380
378381 pub fn get_root ( & self ) -> CrateRoot < ' tcx > {
@@ -381,7 +384,7 @@ impl<'tcx> MetadataBlob {
381384 let pos = ( ( ( slice[ offset + 0 ] as u32 ) << 24 ) | ( ( slice[ offset + 1 ] as u32 ) << 16 ) |
382385 ( ( slice[ offset + 2 ] as u32 ) << 8 ) |
383386 ( ( slice[ offset + 3 ] as u32 ) << 0 ) ) as usize ;
384- Lazy :: with_position ( pos) . decode ( self )
387+ Lazy :: < CrateRoot < ' tcx > > :: from_position ( pos) . decode ( self )
385388 }
386389
387390 pub fn list_crate_metadata ( & self ,
@@ -1098,7 +1101,7 @@ impl<'a, 'tcx> CrateMetadata {
10981101 EntryKind :: Fn ( data) |
10991102 EntryKind :: ForeignFn ( data) => data. decode ( self ) . arg_names ,
11001103 EntryKind :: Method ( data) => data. decode ( self ) . fn_data . arg_names ,
1101- _ => LazySeq :: empty ( ) ,
1104+ _ => Lazy :: empty ( ) ,
11021105 } ;
11031106 arg_names. decode ( self ) . collect ( )
11041107 }
0 commit comments