@@ -4,14 +4,13 @@ use rustc::hir::def_id::{DefId, DefIndex, DefIndexAddressSpace};
44use rustc_serialize:: opaque:: Encoder ;
55use std:: marker:: PhantomData ;
66use std:: num:: NonZeroUsize ;
7- use std:: u32;
87use log:: debug;
98
109/// While we are generating the metadata, we also track the position
1110/// of each DefIndex. It is not required that all definitions appear
1211/// in the metadata, nor that they are serialized in order, and
1312/// therefore we first allocate the vector here and fill it with
14- /// `u32::MAX `. Whenever an index is visited, we fill in the
13+ /// `0 `. Whenever an index is visited, we fill in the
1514/// appropriate spot by calling `record_position`. We should never
1615/// visit the same index twice.
1716pub struct Index < ' tcx > {
@@ -22,8 +21,8 @@ pub struct Index<'tcx> {
2221impl Index < ' tcx > {
2322 pub fn new ( ( max_index_lo, max_index_hi) : ( usize , usize ) ) -> Self {
2423 Index {
25- positions : [ vec ! [ 0xff ; max_index_lo * 4 ] ,
26- vec ! [ 0xff ; max_index_hi * 4 ] ] ,
24+ positions : [ vec ! [ 0 ; max_index_lo * 4 ] ,
25+ vec ! [ 0 ; max_index_hi * 4 ] ] ,
2726 _marker : PhantomData ,
2827 }
2928 }
@@ -34,13 +33,13 @@ impl Index<'tcx> {
3433 }
3534
3635 pub fn record_index ( & mut self , item : DefIndex , entry : Lazy < Entry < ' tcx > > ) {
37- assert ! ( entry. position. get( ) < ( u32 :: MAX as usize ) ) ;
3836 let position = entry. position . get ( ) as u32 ;
37+ assert_eq ! ( position as usize , entry. position. get( ) ) ;
3938 let space_index = item. address_space ( ) . index ( ) ;
4039 let array_index = item. as_array_index ( ) ;
4140
4241 let destination = & mut self . positions [ space_index] [ array_index * 4 ..] ;
43- assert ! ( read_le_u32( destination) == u32 :: MAX ,
42+ assert ! ( read_le_u32( destination) == 0 ,
4443 "recorded position for item {:?} twice, first at {:?} and now at {:?}" ,
4544 item,
4645 read_le_u32( destination) ,
@@ -84,13 +83,8 @@ impl Lazy<[Index<'tcx>]> {
8483 } ;
8584
8685 let position = read_le_u32 ( & bytes[ self . position . get ( ) + ( 1 + i) * 4 ..] ) ;
87- if position == u32:: MAX {
88- debug ! ( "Index::lookup: position=u32::MAX" ) ;
89- None
90- } else {
91- debug ! ( "Index::lookup: position={:?}" , position) ;
92- Some ( Lazy :: from_position ( NonZeroUsize :: new ( position as usize ) . unwrap ( ) ) )
93- }
86+ debug ! ( "Index::lookup: position={:?}" , position) ;
87+ NonZeroUsize :: new ( position as usize ) . map ( Lazy :: from_position)
9488 }
9589}
9690
0 commit comments