Skip to content

Document rustc_index::vec::IndexVec #119800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix some mistakes + new doc
  • Loading branch information
oriongonza committed Jan 10, 2024
commit ee8510e4e13e723639e904cdc218e6f3013f0bb4
11 changes: 5 additions & 6 deletions compiler/rustc_index/src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ use crate::{Idx, IndexSlice};
/// While it's possible to use `u32` or `usize` directly for `I`,
/// you almost certainly want to use a [`newtype_index!`]-generated type instead.
///
/// This allows to index the IndexVec with the new index type
///
///
/// This allows to index the IndexVec with the new index type.
/// [`newtype_index!`]: ../macro.newtype_index.html
#[derive(Clone, PartialEq, Eq, Hash)]
#[repr(transparent)]
pub struct IndexVec<I: Idx, T> {
pub raw: Vec<T>,
_marker: PhantomData<I>,
_marker: PhantomData<fn(&I)>,
}

impl<I: Idx, T> IndexVec<I, T> {
Expand All @@ -35,7 +33,7 @@ impl<I: Idx, T> IndexVec<I, T> {
IndexVec::from_raw(Vec::new())
}

/// Constructs a new `IndexVec<I, T>` from a `Vec<T>`
/// Constructs a new `IndexVec<I, T>` from a `Vec<T>`.
#[inline]
pub const fn from_raw(raw: Vec<T>) -> Self {
IndexVec { raw, _marker: PhantomData }
Expand Down Expand Up @@ -65,7 +63,7 @@ impl<I: Idx, T> IndexVec<I, T> {
IndexVec::from_raw(vec![elem; universe.len()])
}

/// Creates a new IndexVec
/// Creates a new IndexVec with n copies of the `elem`.
#[inline]
pub fn from_elem_n(elem: T, n: usize) -> Self
where
Expand All @@ -92,6 +90,7 @@ impl<I: Idx, T> IndexVec<I, T> {
IndexSlice::from_raw_mut(&mut self.raw)
}

/// Pushes an element to the array returning the index where it was pushed to.
#[inline]
pub fn push(&mut self, d: T) -> I {
let idx = self.next_index();
Expand Down