@@ -135,14 +135,14 @@ impl<'a, 'tcx: 'a, T: Decodable> Lazy<T> {
135
135
}
136
136
}
137
137
138
- impl < ' a , ' tcx : ' a , T : Decodable > LazySeq < T > {
138
+ impl < ' a , ' tcx : ' a , T : Decodable > Lazy < [ T ] > {
139
139
pub fn decode < M : Metadata < ' a , ' tcx > > (
140
140
self ,
141
141
meta : M ,
142
142
) -> impl Iterator < Item = T > + Captures < ' tcx > + ' a {
143
143
let mut dcx = meta. decoder ( self . position ) ;
144
144
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 ( ) )
146
146
}
147
147
}
148
148
@@ -155,18 +155,22 @@ impl<'a, 'tcx> DecodeContext<'a, 'tcx> {
155
155
self . cdata . expect ( "missing CrateMetadata in DecodeContext" )
156
156
}
157
157
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) ;
159
163
let distance = self . read_usize ( ) ?;
160
164
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" ) ,
162
166
LazyState :: NodeStart ( start) => {
163
167
assert ! ( distance + min_size <= start) ;
164
168
start - distance - min_size
165
169
}
166
170
LazyState :: Previous ( last_min_end) => last_min_end + distance,
167
171
} ;
168
172
self . lazy_state = LazyState :: Previous ( position + min_size) ;
169
- Ok ( position)
173
+ Ok ( Lazy :: from_position_and_meta ( position, meta ) )
170
174
}
171
175
}
172
176
@@ -232,19 +236,18 @@ impl<'a, 'tcx: 'a> TyDecoder<'a, 'tcx> for DecodeContext<'a, 'tcx> {
232
236
233
237
impl < ' a , ' tcx , T > SpecializedDecoder < Lazy < T > > for DecodeContext < ' a , ' tcx > {
234
238
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 ( ( ) )
236
240
}
237
241
}
238
242
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 > {
241
245
let len = self . read_usize ( ) ?;
242
- let position = if len == 0 {
243
- 0
246
+ if len == 0 {
247
+ Ok ( Lazy :: empty ( ) )
244
248
} 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
+ }
248
251
}
249
252
}
250
253
@@ -372,7 +375,7 @@ impl<'tcx> MetadataBlob {
372
375
}
373
376
374
377
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 )
376
379
}
377
380
378
381
pub fn get_root ( & self ) -> CrateRoot < ' tcx > {
@@ -381,7 +384,7 @@ impl<'tcx> MetadataBlob {
381
384
let pos = ( ( ( slice[ offset + 0 ] as u32 ) << 24 ) | ( ( slice[ offset + 1 ] as u32 ) << 16 ) |
382
385
( ( slice[ offset + 2 ] as u32 ) << 8 ) |
383
386
( ( slice[ offset + 3 ] as u32 ) << 0 ) ) as usize ;
384
- Lazy :: with_position ( pos) . decode ( self )
387
+ Lazy :: < CrateRoot < ' tcx > > :: from_position ( pos) . decode ( self )
385
388
}
386
389
387
390
pub fn list_crate_metadata ( & self ,
@@ -1109,7 +1112,7 @@ impl<'a, 'tcx> CrateMetadata {
1109
1112
EntryKind :: Fn ( data) |
1110
1113
EntryKind :: ForeignFn ( data) => data. decode ( self ) . arg_names ,
1111
1114
EntryKind :: Method ( data) => data. decode ( self ) . fn_data . arg_names ,
1112
- _ => LazySeq :: empty ( ) ,
1115
+ _ => Lazy :: empty ( ) ,
1113
1116
} ;
1114
1117
arg_names. decode ( self ) . collect ( )
1115
1118
}
0 commit comments