Rollup merge of #109913 - scottmcm:index-slice, r=WaffleLapkin
Doc-comment `IndexVec::from_elem` and use it in a few more places Since this PR is a reply to https://github.com/rust-lang/rust/pull/109819#discussion_r1156128164, r? ``@WaffleLapkin``
This commit is contained in:
commit
5485a54e19
@ -63,7 +63,7 @@ impl LocalUseMap {
|
|||||||
elements: &RegionValueElements,
|
elements: &RegionValueElements,
|
||||||
body: &Body<'_>,
|
body: &Body<'_>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let nones = IndexVec::from_elem_n(None, body.local_decls.len());
|
let nones = IndexVec::from_elem(None, &body.local_decls);
|
||||||
let mut local_use_map = LocalUseMap {
|
let mut local_use_map = LocalUseMap {
|
||||||
first_def_at: nones.clone(),
|
first_def_at: nones.clone(),
|
||||||
first_use_at: nones.clone(),
|
first_use_at: nones.clone(),
|
||||||
@ -76,7 +76,7 @@ impl LocalUseMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut locals_with_use_data: IndexVec<Local, bool> =
|
let mut locals_with_use_data: IndexVec<Local, bool> =
|
||||||
IndexVec::from_elem_n(false, body.local_decls.len());
|
IndexVec::from_elem(false, &body.local_decls);
|
||||||
live_locals.iter().for_each(|&local| locals_with_use_data[local] = true);
|
live_locals.iter().for_each(|&local| locals_with_use_data[local] = true);
|
||||||
|
|
||||||
LocalUseMapBuild { local_use_map: &mut local_use_map, elements, locals_with_use_data }
|
LocalUseMapBuild { local_use_map: &mut local_use_map, elements, locals_with_use_data }
|
||||||
|
@ -129,6 +129,17 @@ impl<I: Idx, T> IndexVec<I, T> {
|
|||||||
IndexVec { raw: Vec::with_capacity(capacity), _marker: PhantomData }
|
IndexVec { raw: Vec::with_capacity(capacity), _marker: PhantomData }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates a new vector with a copy of `elem` for each index in `universe`.
|
||||||
|
///
|
||||||
|
/// Thus `IndexVec::from_elem(elem, &universe)` is equivalent to
|
||||||
|
/// `IndexVec::<I, _>::from_elem_n(elem, universe.len())`. That can help
|
||||||
|
/// type inference as it ensures that the resulting vector uses the same
|
||||||
|
/// index type as `universe`, rather than something potentially surprising.
|
||||||
|
///
|
||||||
|
/// For example, if you want to store data for each local in a MIR body,
|
||||||
|
/// using `let mut uses = IndexVec::from_elem(vec![], &body.local_decls);`
|
||||||
|
/// ensures that `uses` is an `IndexVec<Local, _>`, and thus can give
|
||||||
|
/// better error messages later if one accidentally mismatches indices.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_elem<S>(elem: T, universe: &IndexSlice<I, S>) -> Self
|
pub fn from_elem<S>(elem: T, universe: &IndexSlice<I, S>) -> Self
|
||||||
where
|
where
|
||||||
|
@ -203,7 +203,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
|||||||
|
|
||||||
// Tracks the `VarSubVar` constraints generated for each region vid. We
|
// Tracks the `VarSubVar` constraints generated for each region vid. We
|
||||||
// later use this to expand across vids.
|
// later use this to expand across vids.
|
||||||
let mut constraints = IndexVec::from_elem_n(Vec::new(), var_values.values.len());
|
let mut constraints = IndexVec::from_elem(Vec::new(), &var_values.values);
|
||||||
// Tracks the changed region vids.
|
// Tracks the changed region vids.
|
||||||
let mut changes = Vec::new();
|
let mut changes = Vec::new();
|
||||||
for constraint in self.data.constraints.keys() {
|
for constraint in self.data.constraints.keys() {
|
||||||
|
@ -37,8 +37,7 @@ impl CoverageGraph {
|
|||||||
// `SwitchInt` to have multiple targets to the same destination `BasicBlock`, so
|
// `SwitchInt` to have multiple targets to the same destination `BasicBlock`, so
|
||||||
// de-duplication is required. This is done without reordering the successors.
|
// de-duplication is required. This is done without reordering the successors.
|
||||||
|
|
||||||
let bcbs_len = bcbs.len();
|
let mut seen = IndexVec::from_elem(false, &bcbs);
|
||||||
let mut seen = IndexVec::from_elem_n(false, bcbs_len);
|
|
||||||
let successors = IndexVec::from_fn_n(
|
let successors = IndexVec::from_fn_n(
|
||||||
|bcb| {
|
|bcb| {
|
||||||
for b in seen.iter_mut() {
|
for b in seen.iter_mut() {
|
||||||
@ -60,7 +59,7 @@ impl CoverageGraph {
|
|||||||
bcbs.len(),
|
bcbs.len(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut predecessors = IndexVec::from_elem_n(Vec::new(), bcbs.len());
|
let mut predecessors = IndexVec::from_elem(Vec::new(), &bcbs);
|
||||||
for (bcb, bcb_successors) in successors.iter_enumerated() {
|
for (bcb, bcb_successors) in successors.iter_enumerated() {
|
||||||
for &successor in bcb_successors {
|
for &successor in bcb_successors {
|
||||||
predecessors[successor].push(bcb);
|
predecessors[successor].push(bcb);
|
||||||
|
@ -522,7 +522,7 @@ fn generator_saved_local_eligibility(
|
|||||||
use SavedLocalEligibility::*;
|
use SavedLocalEligibility::*;
|
||||||
|
|
||||||
let mut assignments: IndexVec<GeneratorSavedLocal, SavedLocalEligibility> =
|
let mut assignments: IndexVec<GeneratorSavedLocal, SavedLocalEligibility> =
|
||||||
IndexVec::from_elem_n(Unassigned, info.field_tys.len());
|
IndexVec::from_elem(Unassigned, &info.field_tys);
|
||||||
|
|
||||||
// The saved locals not eligible for overlap. These will get
|
// The saved locals not eligible for overlap. These will get
|
||||||
// "promoted" to the prefix of our generator.
|
// "promoted" to the prefix of our generator.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user