@@ -4,14 +4,13 @@ use rustc::hir::def_id::{DefId, DefIndex, DefIndexAddressSpace};
4
4
use rustc_serialize:: opaque:: Encoder ;
5
5
use std:: marker:: PhantomData ;
6
6
use std:: num:: NonZeroUsize ;
7
- use std:: u32;
8
7
use log:: debug;
9
8
10
9
/// While we are generating the metadata, we also track the position
11
10
/// of each DefIndex. It is not required that all definitions appear
12
11
/// in the metadata, nor that they are serialized in order, and
13
12
/// 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
15
14
/// appropriate spot by calling `record_position`. We should never
16
15
/// visit the same index twice.
17
16
pub struct Index < ' tcx > {
@@ -22,8 +21,8 @@ pub struct Index<'tcx> {
22
21
impl Index < ' tcx > {
23
22
pub fn new ( ( max_index_lo, max_index_hi) : ( usize , usize ) ) -> Self {
24
23
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 ] ] ,
27
26
_marker : PhantomData ,
28
27
}
29
28
}
@@ -34,13 +33,13 @@ impl Index<'tcx> {
34
33
}
35
34
36
35
pub fn record_index ( & mut self , item : DefIndex , entry : Lazy < Entry < ' tcx > > ) {
37
- assert ! ( entry. position. get( ) < ( u32 :: MAX as usize ) ) ;
38
36
let position = entry. position . get ( ) as u32 ;
37
+ assert_eq ! ( position as usize , entry. position. get( ) ) ;
39
38
let space_index = item. address_space ( ) . index ( ) ;
40
39
let array_index = item. as_array_index ( ) ;
41
40
42
41
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 ,
44
43
"recorded position for item {:?} twice, first at {:?} and now at {:?}" ,
45
44
item,
46
45
read_le_u32( destination) ,
@@ -84,13 +83,8 @@ impl Lazy<[Index<'tcx>]> {
84
83
} ;
85
84
86
85
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)
94
88
}
95
89
}
96
90
0 commit comments