@@ -4,7 +4,6 @@ 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
/// Helper trait, for encoding to, and decoding from, a fixed number of bytes.
@@ -73,7 +72,7 @@ impl FixedSizeEncoding for u32 {
73
72
/// of each DefIndex. It is not required that all definitions appear
74
73
/// in the metadata, nor that they are serialized in order, and
75
74
/// therefore we first allocate the vector here and fill it with
76
- /// `u32::MAX `. Whenever an index is visited, we fill in the
75
+ /// `0 `. Whenever an index is visited, we fill in the
77
76
/// appropriate spot by calling `record_position`. We should never
78
77
/// visit the same index twice.
79
78
pub struct Index < ' tcx > {
@@ -84,8 +83,8 @@ pub struct Index<'tcx> {
84
83
impl Index < ' tcx > {
85
84
pub fn new ( ( max_index_lo, max_index_hi) : ( usize , usize ) ) -> Self {
86
85
Index {
87
- positions : [ vec ! [ 0xff ; max_index_lo * 4 ] ,
88
- vec ! [ 0xff ; max_index_hi * 4 ] ] ,
86
+ positions : [ vec ! [ 0 ; max_index_lo * 4 ] ,
87
+ vec ! [ 0 ; max_index_hi * 4 ] ] ,
89
88
_marker : PhantomData ,
90
89
}
91
90
}
@@ -96,13 +95,13 @@ impl Index<'tcx> {
96
95
}
97
96
98
97
pub fn record_index ( & mut self , item : DefIndex , entry : Lazy < Entry < ' tcx > > ) {
99
- assert ! ( entry. position. get( ) < ( u32 :: MAX as usize ) ) ;
100
98
let position = entry. position . get ( ) as u32 ;
99
+ assert_eq ! ( position as usize , entry. position. get( ) ) ;
101
100
let space_index = item. address_space ( ) . index ( ) ;
102
101
let array_index = item. as_array_index ( ) ;
103
102
104
103
let positions = & mut self . positions [ space_index] ;
105
- assert ! ( u32 :: read_from_bytes_at( positions, array_index) == u32 :: MAX ,
104
+ assert ! ( u32 :: read_from_bytes_at( positions, array_index) == 0 ,
106
105
"recorded position for item {:?} twice, first at {:?} and now at {:?}" ,
107
106
item,
108
107
u32 :: read_from_bytes_at( positions, array_index) ,
@@ -147,12 +146,7 @@ impl Lazy<[Index<'tcx>]> {
147
146
} ;
148
147
149
148
let position = u32:: read_from_bytes_at ( bytes, 1 + i) ;
150
- if position == u32:: MAX {
151
- debug ! ( "Index::lookup: position=u32::MAX" ) ;
152
- None
153
- } else {
154
- debug ! ( "Index::lookup: position={:?}" , position) ;
155
- Some ( Lazy :: from_position ( NonZeroUsize :: new ( position as usize ) . unwrap ( ) ) )
156
- }
149
+ debug ! ( "Index::lookup: position={:?}" , position) ;
150
+ NonZeroUsize :: new ( position as usize ) . map ( Lazy :: from_position)
157
151
}
158
152
}
0 commit comments