Skip to content

Commit 83b3c39

Browse files
committed
rustc_metadata: use 0 in index::Index to indicate missing entries.
1 parent ea13456 commit 83b3c39

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

src/librustc_metadata/index.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use crate::schema::*;
22

33
use rustc::hir::def_id::{DefId, DefIndex};
44
use rustc_serialize::opaque::Encoder;
5+
use std::convert::TryInto;
56
use std::marker::PhantomData;
67
use std::num::NonZeroUsize;
7-
use std::u32;
88
use log::debug;
99

1010
/// Helper trait, for encoding to, and decoding from, a fixed number of bytes.
@@ -73,7 +73,7 @@ impl FixedSizeEncoding for u32 {
7373
/// of each DefIndex. It is not required that all definitions appear
7474
/// in the metadata, nor that they are serialized in order, and
7575
/// 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
7777
/// appropriate spot by calling `record_position`. We should never
7878
/// visit the same index twice.
7979
crate struct Index<'tcx> {
@@ -84,7 +84,7 @@ crate struct Index<'tcx> {
8484
impl Index<'tcx> {
8585
crate fn new(max_index: usize) -> Self {
8686
Index {
87-
positions: vec![0xff; max_index * 4],
87+
positions: vec![0; max_index * 4],
8888
_marker: PhantomData,
8989
}
9090
}
@@ -95,12 +95,11 @@ impl Index<'tcx> {
9595
}
9696

9797
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();
10099
let array_index = item.index();
101100

102101
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,
104103
"recorded position for item {:?} twice, first at {:?} and now at {:?}",
105104
item,
106105
u32::read_from_bytes_at(positions, array_index),
@@ -130,12 +129,7 @@ impl Lazy<[Index<'tcx>]> {
130129

131130
let bytes = &bytes[self.position.get()..][..self.meta * 4];
132131
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)
140134
}
141135
}

0 commit comments

Comments
 (0)