@@ -2,9 +2,9 @@ use crate::schema::*;
2
2
3
3
use rustc:: hir:: def_id:: { DefId , DefIndex } ;
4
4
use rustc_serialize:: opaque:: Encoder ;
5
+ use std:: convert:: TryInto ;
5
6
use std:: marker:: PhantomData ;
6
7
use std:: num:: NonZeroUsize ;
7
- use std:: u32;
8
8
use log:: debug;
9
9
10
10
/// Helper trait, for encoding to, and decoding from, a fixed number of bytes.
@@ -73,7 +73,7 @@ impl FixedSizeEncoding for u32 {
73
73
/// of each DefIndex. It is not required that all definitions appear
74
74
/// in the metadata, nor that they are serialized in order, and
75
75
/// therefore we first allocate the vector here and fill it with
76
- /// `u32::MAX `. Whenever an index is visited, we fill in the
76
+ /// `0 `. Whenever an index is visited, we fill in the
77
77
/// appropriate spot by calling `record_position`. We should never
78
78
/// visit the same index twice.
79
79
crate struct Index < ' tcx > {
@@ -84,7 +84,7 @@ crate struct Index<'tcx> {
84
84
impl Index < ' tcx > {
85
85
crate fn new ( max_index : usize ) -> Self {
86
86
Index {
87
- positions : vec ! [ 0xff ; max_index * 4 ] ,
87
+ positions : vec ! [ 0 ; max_index * 4 ] ,
88
88
_marker : PhantomData ,
89
89
}
90
90
}
@@ -95,12 +95,11 @@ impl Index<'tcx> {
95
95
}
96
96
97
97
fn record_index ( & mut self , item : DefIndex , entry : Lazy < Entry < ' tcx > > ) {
98
- assert ! ( entry. position. get( ) < ( u32 :: MAX as usize ) ) ;
99
- let position = entry. position . get ( ) as u32 ;
98
+ let position: u32 = entry. position . get ( ) . try_into ( ) . unwrap ( ) ;
100
99
let array_index = item. index ( ) ;
101
100
102
101
let positions = & mut self . positions ;
103
- assert ! ( u32 :: read_from_bytes_at( positions, array_index) == u32 :: MAX ,
102
+ assert ! ( u32 :: read_from_bytes_at( positions, array_index) == 0 ,
104
103
"recorded position for item {:?} twice, first at {:?} and now at {:?}" ,
105
104
item,
106
105
u32 :: read_from_bytes_at( positions, array_index) ,
@@ -130,12 +129,7 @@ impl Lazy<[Index<'tcx>]> {
130
129
131
130
let bytes = & bytes[ self . position . get ( ) ..] [ ..self . meta * 4 ] ;
132
131
let position = u32:: read_from_bytes_at ( bytes, def_index. index ( ) ) ;
133
- if position == u32:: MAX {
134
- debug ! ( "Index::lookup: position=u32::MAX" ) ;
135
- None
136
- } else {
137
- debug ! ( "Index::lookup: position={:?}" , position) ;
138
- Some ( Lazy :: from_position ( NonZeroUsize :: new ( position as usize ) . unwrap ( ) ) )
139
- }
132
+ debug ! ( "Index::lookup: position={:?}" , position) ;
133
+ NonZeroUsize :: new ( position as usize ) . map ( Lazy :: from_position)
140
134
}
141
135
}
0 commit comments