Skip to content

Commit 4058e29

Browse files
authored
Unrolled build for rust-lang#119800
Rollup merge of rust-lang#119800 - dev-ardi:tmp, r=wesleywiser Document `rustc_index::vec::IndexVec` Document a few of the methods. Part of rust-lang#93792.
2 parents c073f56 + 00ada8e commit 4058e29

File tree

1 file changed

+7
-0
lines changed
  • compiler/rustc_index/src

1 file changed

+7
-0
lines changed

compiler/rustc_index/src/vec.rs

+7
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ use std::vec;
1212
use crate::{Idx, IndexSlice};
1313

1414
/// An owned contiguous collection of `T`s, indexed by `I` rather than by `usize`.
15+
/// Its purpose is to avoid mixing indexes.
1516
///
1617
/// While it's possible to use `u32` or `usize` directly for `I`,
1718
/// you almost certainly want to use a [`newtype_index!`]-generated type instead.
1819
///
20+
/// This allows to index the IndexVec with the new index type.
21+
///
1922
/// [`newtype_index!`]: ../macro.newtype_index.html
2023
#[derive(Clone, PartialEq, Eq, Hash)]
2124
#[repr(transparent)]
@@ -25,11 +28,13 @@ pub struct IndexVec<I: Idx, T> {
2528
}
2629

2730
impl<I: Idx, T> IndexVec<I, T> {
31+
/// Constructs a new, empty `IndexVec<I, T>`.
2832
#[inline]
2933
pub const fn new() -> Self {
3034
IndexVec::from_raw(Vec::new())
3135
}
3236

37+
/// Constructs a new `IndexVec<I, T>` from a `Vec<T>`.
3338
#[inline]
3439
pub const fn from_raw(raw: Vec<T>) -> Self {
3540
IndexVec { raw, _marker: PhantomData }
@@ -59,6 +64,7 @@ impl<I: Idx, T> IndexVec<I, T> {
5964
IndexVec::from_raw(vec![elem; universe.len()])
6065
}
6166

67+
/// Creates a new IndexVec with n copies of the `elem`.
6268
#[inline]
6369
pub fn from_elem_n(elem: T, n: usize) -> Self
6470
where
@@ -85,6 +91,7 @@ impl<I: Idx, T> IndexVec<I, T> {
8591
IndexSlice::from_raw_mut(&mut self.raw)
8692
}
8793

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

0 commit comments

Comments
 (0)