]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_metadata/index.rs
Rollup merge of #61409 - varkor:condition-trait-param-ice, r=oli-obk
[rust.git] / src / librustc_metadata / index.rs
index 4c1e39cd0a9e1a945c1ed3c18ebc8e8cdd1f0f45..dd2f59922ef9238ca34d6276dce219ab8fed9f03 100644 (file)
@@ -2,6 +2,7 @@
 
 use rustc::hir::def_id::{DefId, DefIndex};
 use rustc_serialize::opaque::Encoder;
+use std::marker::PhantomData;
 use std::u32;
 use log::debug;
 
@@ -74,26 +75,28 @@ fn write_to_bytes(self, b: &mut [u8]) {
 /// `u32::MAX`. Whenever an index is visited, we fill in the
 /// appropriate spot by calling `record_position`. We should never
 /// visit the same index twice.
-pub struct Index {
+pub struct Index<'tcx> {
     positions: Vec<u8>,
+    _marker: PhantomData<&'tcx ()>,
 }
 
-impl Index {
-    pub fn new(max_index: usize) -> Index {
+impl Index<'tcx> {
+    pub fn new(max_index: usize) -> Self {
         Index {
             positions: vec![0xff; max_index * 4],
+            _marker: PhantomData,
         }
     }
 
-    pub fn record(&mut self, def_id: DefId, entry: Lazy<Entry<'_>>) {
+    pub fn record(&mut self, def_id: DefId, entry: Lazy<Entry<'tcx>>) {
         assert!(def_id.is_local());
         self.record_index(def_id.index, entry);
     }
 
-    pub fn record_index(&mut self, item: DefIndex, entry: Lazy<Entry<'_>>) {
+    pub fn record_index(&mut self, item: DefIndex, entry: Lazy<Entry<'tcx>>) {
         assert!(entry.position < (u32::MAX as usize));
         let position = entry.position as u32;
-        let array_index = item.as_array_index();
+        let array_index = item.index();
 
         let positions = &mut self.positions;
         assert!(u32::read_from_bytes_at(positions, array_index) == u32::MAX,
@@ -105,7 +108,7 @@ pub fn record_index(&mut self, item: DefIndex, entry: Lazy<Entry<'_>>) {
         position.write_to_bytes_at(positions, array_index)
     }
 
-    pub fn write_index(&self, buf: &mut Encoder) -> LazySeq<Index> {
+    pub fn write_index(&self, buf: &mut Encoder) -> LazySeq<Self> {
         let pos = buf.position();
 
         // First we write the length of the lower range ...
@@ -116,7 +119,7 @@ pub fn write_index(&self, buf: &mut Encoder) -> LazySeq<Index> {
     }
 }
 
-impl<'tcx> LazySeq<Index> {
+impl LazySeq<Index<'tcx>> {
     /// Given the metadata, extract out the offset of a particular
     /// DefIndex (if any).
     #[inline(never)]
@@ -126,7 +129,7 @@ pub fn lookup(&self, bytes: &[u8], def_index: DefIndex) -> Option<Lazy<Entry<'tc
                def_index,
                self.len);
 
-        let position = u32::read_from_bytes_at(bytes, 1 + def_index.as_array_index());
+        let position = u32::read_from_bytes_at(bytes, 1 + def_index.index());
         if position == u32::MAX {
             debug!("Index::lookup: position=u32::MAX");
             None