1
Fork 0

Use &IndexSlice instead of &IndexVec where possible

All the same reasons as for `[T]`: more general, less pointer chasing, and `&mut IndexSlice` emphasizes that it doesn't change *length*.
This commit is contained in:
Scott McMurray 2023-03-31 00:32:44 -07:00
parent a93bcdc307
commit a2ee7592d6
42 changed files with 168 additions and 118 deletions

View file

@ -289,7 +289,7 @@ pub trait LayoutCalculator {
fn layout_of_struct_or_enum( fn layout_of_struct_or_enum(
&self, &self,
repr: &ReprOptions, repr: &ReprOptions,
variants: &IndexVec<VariantIdx, Vec<Layout<'_>>>, variants: &IndexSlice<VariantIdx, Vec<Layout<'_>>>,
is_enum: bool, is_enum: bool,
is_unsafe_cell: bool, is_unsafe_cell: bool,
scalar_valid_range: (Bound<u128>, Bound<u128>), scalar_valid_range: (Bound<u128>, Bound<u128>),
@ -883,7 +883,7 @@ pub trait LayoutCalculator {
fn layout_of_union( fn layout_of_union(
&self, &self,
repr: &ReprOptions, repr: &ReprOptions,
variants: &IndexVec<VariantIdx, Vec<Layout<'_>>>, variants: &IndexSlice<VariantIdx, Vec<Layout<'_>>>,
) -> Option<LayoutS> { ) -> Option<LayoutS> {
let dl = self.current_data_layout(); let dl = self.current_data_layout();
let dl = dl.borrow(); let dl = dl.borrow();

View file

@ -11,7 +11,7 @@ use bitflags::bitflags;
use rustc_data_structures::intern::Interned; use rustc_data_structures::intern::Interned;
#[cfg(feature = "nightly")] #[cfg(feature = "nightly")]
use rustc_data_structures::stable_hasher::StableOrd; use rustc_data_structures::stable_hasher::StableOrd;
use rustc_index::vec::{Idx, IndexVec}; use rustc_index::vec::{Idx, IndexSlice, IndexVec};
#[cfg(feature = "nightly")] #[cfg(feature = "nightly")]
use rustc_macros::HashStable_Generic; use rustc_macros::HashStable_Generic;
#[cfg(feature = "nightly")] #[cfg(feature = "nightly")]

View file

@ -12,7 +12,7 @@ use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID}; use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
use rustc_hir::PredicateOrigin; use rustc_hir::PredicateOrigin;
use rustc_index::vec::{Idx, IndexVec}; use rustc_index::vec::{Idx, IndexSlice, IndexVec};
use rustc_middle::ty::{ResolverAstLowering, TyCtxt}; use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
use rustc_span::edit_distance::find_best_match_for_name; use rustc_span::edit_distance::find_best_match_for_name;
use rustc_span::source_map::DesugaringKind; use rustc_span::source_map::DesugaringKind;
@ -25,7 +25,7 @@ use thin_vec::ThinVec;
pub(super) struct ItemLowerer<'a, 'hir> { pub(super) struct ItemLowerer<'a, 'hir> {
pub(super) tcx: TyCtxt<'hir>, pub(super) tcx: TyCtxt<'hir>,
pub(super) resolver: &'a mut ResolverAstLowering, pub(super) resolver: &'a mut ResolverAstLowering,
pub(super) ast_index: &'a IndexVec<LocalDefId, AstOwner<'a>>, pub(super) ast_index: &'a IndexSlice<LocalDefId, AstOwner<'a>>,
pub(super) owners: &'a mut IndexVec<LocalDefId, hir::MaybeOwner<&'hir hir::OwnerInfo<'hir>>>, pub(super) owners: &'a mut IndexVec<LocalDefId, hir::MaybeOwner<&'hir hir::OwnerInfo<'hir>>>,
} }

View file

@ -60,7 +60,7 @@ use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID}; use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
use rustc_hir::definitions::DefPathData; use rustc_hir::definitions::DefPathData;
use rustc_hir::{ConstArg, GenericArg, ItemLocalId, ParamName, TraitCandidate}; use rustc_hir::{ConstArg, GenericArg, ItemLocalId, ParamName, TraitCandidate};
use rustc_index::vec::{Idx, IndexVec}; use rustc_index::vec::{Idx, IndexSlice, IndexVec};
use rustc_macros::fluent_messages; use rustc_macros::fluent_messages;
use rustc_middle::{ use rustc_middle::{
span_bug, span_bug,
@ -414,7 +414,7 @@ fn index_crate<'a>(
/// This hash will then be part of the crate_hash which is stored in the metadata. /// This hash will then be part of the crate_hash which is stored in the metadata.
fn compute_hir_hash( fn compute_hir_hash(
tcx: TyCtxt<'_>, tcx: TyCtxt<'_>,
owners: &IndexVec<LocalDefId, hir::MaybeOwner<&hir::OwnerInfo<'_>>>, owners: &IndexSlice<LocalDefId, hir::MaybeOwner<&hir::OwnerInfo<'_>>>,
) -> Fingerprint { ) -> Fingerprint {
let mut hir_body_nodes: Vec<_> = owners let mut hir_body_nodes: Vec<_> = owners
.iter_enumerated() .iter_enumerated()

View file

@ -2,7 +2,7 @@
#![deny(rustc::diagnostic_outside_of_impl)] #![deny(rustc::diagnostic_outside_of_impl)]
use rustc_data_structures::graph::scc::Sccs; use rustc_data_structures::graph::scc::Sccs;
use rustc_index::vec::IndexVec; use rustc_index::vec::{IndexSlice, IndexVec};
use rustc_middle::mir::ConstraintCategory; use rustc_middle::mir::ConstraintCategory;
use rustc_middle::ty::{RegionVid, VarianceDiagInfo}; use rustc_middle::ty::{RegionVid, VarianceDiagInfo};
use rustc_span::Span; use rustc_span::Span;
@ -60,7 +60,9 @@ impl<'tcx> OutlivesConstraintSet<'tcx> {
Sccs::new(region_graph) Sccs::new(region_graph)
} }
pub(crate) fn outlives(&self) -> &IndexVec<OutlivesConstraintIndex, OutlivesConstraint<'tcx>> { pub(crate) fn outlives(
&self,
) -> &IndexSlice<OutlivesConstraintIndex, OutlivesConstraint<'tcx>> {
&self.outlives &self.outlives
} }
} }

View file

@ -3,7 +3,7 @@
//! This file provides API for compiler consumers. //! This file provides API for compiler consumers.
use rustc_hir::def_id::LocalDefId; use rustc_hir::def_id::LocalDefId;
use rustc_index::vec::IndexVec; use rustc_index::vec::IndexSlice;
use rustc_infer::infer::{DefiningAnchor, TyCtxtInferExt}; use rustc_infer::infer::{DefiningAnchor, TyCtxtInferExt};
use rustc_middle::mir::Body; use rustc_middle::mir::Body;
use rustc_middle::ty::{self, TyCtxt}; use rustc_middle::ty::{self, TyCtxt};
@ -35,6 +35,6 @@ pub fn get_body_with_borrowck_facts(
let (input_body, promoted) = tcx.mir_promoted(def); let (input_body, promoted) = tcx.mir_promoted(def);
let infcx = tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bind(def.did)).build(); let infcx = tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bind(def.did)).build();
let input_body: &Body<'_> = &input_body.borrow(); let input_body: &Body<'_> = &input_body.borrow();
let promoted: &IndexVec<_, _> = &promoted.borrow(); let promoted: &IndexSlice<_, _> = &promoted.borrow();
*super::do_mir_borrowck(&infcx, input_body, promoted, true).1.unwrap() *super::do_mir_borrowck(&infcx, input_body, promoted, true).1.unwrap()
} }

View file

@ -3,7 +3,7 @@
use rustc_errors::{Applicability, Diagnostic}; use rustc_errors::{Applicability, Diagnostic};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::intravisit::Visitor; use rustc_hir::intravisit::Visitor;
use rustc_index::vec::IndexVec; use rustc_index::vec::IndexSlice;
use rustc_infer::infer::NllRegionVariableOrigin; use rustc_infer::infer::NllRegionVariableOrigin;
use rustc_middle::mir::{ use rustc_middle::mir::{
Body, CastKind, ConstraintCategory, FakeReadCause, Local, LocalInfo, Location, Operand, Place, Body, CastKind, ConstraintCategory, FakeReadCause, Local, LocalInfo, Location, Operand, Place,
@ -60,7 +60,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
&self, &self,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
body: &Body<'tcx>, body: &Body<'tcx>,
local_names: &IndexVec<Local, Option<Symbol>>, local_names: &IndexSlice<Local, Option<Symbol>>,
err: &mut Diagnostic, err: &mut Diagnostic,
borrow_desc: &str, borrow_desc: &str,
borrow_span: Option<Span>, borrow_span: Option<Span>,

View file

@ -3,7 +3,7 @@
use crate::Upvar; use crate::Upvar;
use crate::{nll::ToRegionVid, region_infer::RegionInferenceContext}; use crate::{nll::ToRegionVid, region_infer::RegionInferenceContext};
use rustc_index::vec::{Idx, IndexVec}; use rustc_index::vec::{Idx, IndexSlice};
use rustc_middle::mir::{Body, Local}; use rustc_middle::mir::{Body, Local};
use rustc_middle::ty::{RegionVid, TyCtxt}; use rustc_middle::ty::{RegionVid, TyCtxt};
use rustc_span::source_map::Span; use rustc_span::source_map::Span;
@ -14,7 +14,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
&self, &self,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
body: &Body<'tcx>, body: &Body<'tcx>,
local_names: &IndexVec<Local, Option<Symbol>>, local_names: &IndexSlice<Local, Option<Symbol>>,
upvars: &[Upvar<'tcx>], upvars: &[Upvar<'tcx>],
fr: RegionVid, fr: RegionVid,
) -> Option<(Option<Symbol>, Span)> { ) -> Option<(Option<Symbol>, Span)> {
@ -113,7 +113,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
pub(crate) fn get_argument_name_and_span_for_region( pub(crate) fn get_argument_name_and_span_for_region(
&self, &self,
body: &Body<'tcx>, body: &Body<'tcx>,
local_names: &IndexVec<Local, Option<Symbol>>, local_names: &IndexSlice<Local, Option<Symbol>>,
argument_index: usize, argument_index: usize,
) -> (Option<Symbol>, Span) { ) -> (Option<Symbol>, Span) {
let implicit_inputs = self.universal_regions().defining_ty.implicit_inputs(); let implicit_inputs = self.universal_regions().defining_ty.implicit_inputs();

View file

@ -23,7 +23,7 @@ use rustc_errors::{Diagnostic, DiagnosticBuilder, DiagnosticMessage, Subdiagnost
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::LocalDefId; use rustc_hir::def_id::LocalDefId;
use rustc_index::bit_set::ChunkedBitSet; use rustc_index::bit_set::ChunkedBitSet;
use rustc_index::vec::IndexVec; use rustc_index::vec::{IndexSlice, IndexVec};
use rustc_infer::infer::{ use rustc_infer::infer::{
DefiningAnchor, InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin, TyCtxtInferExt, DefiningAnchor, InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin, TyCtxtInferExt,
}; };
@ -154,7 +154,7 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> &Bor
let infcx = let infcx =
tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bind(hir_owner.def_id)).build(); tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bind(hir_owner.def_id)).build();
let input_body: &Body<'_> = &input_body.borrow(); let input_body: &Body<'_> = &input_body.borrow();
let promoted: &IndexVec<_, _> = &promoted.borrow(); let promoted: &IndexSlice<_, _> = &promoted.borrow();
let opt_closure_req = do_mir_borrowck(&infcx, input_body, promoted, false).0; let opt_closure_req = do_mir_borrowck(&infcx, input_body, promoted, false).0;
debug!("mir_borrowck done"); debug!("mir_borrowck done");
@ -170,7 +170,7 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> &Bor
fn do_mir_borrowck<'tcx>( fn do_mir_borrowck<'tcx>(
infcx: &InferCtxt<'tcx>, infcx: &InferCtxt<'tcx>,
input_body: &Body<'tcx>, input_body: &Body<'tcx>,
input_promoted: &IndexVec<Promoted, Body<'tcx>>, input_promoted: &IndexSlice<Promoted, Body<'tcx>>,
return_body_with_facts: bool, return_body_with_facts: bool,
) -> (BorrowCheckResult<'tcx>, Option<Box<BodyWithBorrowckFacts<'tcx>>>) { ) -> (BorrowCheckResult<'tcx>, Option<Box<BodyWithBorrowckFacts<'tcx>>>) {
let def = input_body.source.with_opt_param().as_local().unwrap(); let def = input_body.source.with_opt_param().as_local().unwrap();
@ -223,7 +223,7 @@ fn do_mir_borrowck<'tcx>(
// be modified (in place) to contain non-lexical lifetimes. It // be modified (in place) to contain non-lexical lifetimes. It
// will have a lifetime tied to the inference context. // will have a lifetime tied to the inference context.
let mut body_owned = input_body.clone(); let mut body_owned = input_body.clone();
let mut promoted = input_promoted.clone(); let mut promoted = input_promoted.to_owned();
let free_regions = let free_regions =
nll::replace_regions_in_mir(&infcx, param_env, &mut body_owned, &mut promoted); nll::replace_regions_in_mir(&infcx, param_env, &mut body_owned, &mut promoted);
let body = &body_owned; // no further changes let body = &body_owned; // no further changes

View file

@ -2,7 +2,7 @@
#![deny(rustc::diagnostic_outside_of_impl)] #![deny(rustc::diagnostic_outside_of_impl)]
use rustc_data_structures::captures::Captures; use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::fx::FxIndexMap;
use rustc_index::vec::IndexVec; use rustc_index::vec::{IndexSlice, IndexVec};
use rustc_middle::infer::MemberConstraint; use rustc_middle::infer::MemberConstraint;
use rustc_middle::ty::{self, Ty}; use rustc_middle::ty::{self, Ty};
use rustc_span::Span; use rustc_span::Span;
@ -215,7 +215,7 @@ where
/// target_list: A -> B -> C -> D -> E -> F -> (None) /// target_list: A -> B -> C -> D -> E -> F -> (None)
/// ``` /// ```
fn append_list( fn append_list(
constraints: &mut IndexVec<NllMemberConstraintIndex, NllMemberConstraint<'_>>, constraints: &mut IndexSlice<NllMemberConstraintIndex, NllMemberConstraint<'_>>,
target_list: NllMemberConstraintIndex, target_list: NllMemberConstraintIndex,
source_list: NllMemberConstraintIndex, source_list: NllMemberConstraintIndex,
) { ) {

View file

@ -4,7 +4,7 @@
use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::fx::FxIndexMap;
use rustc_hir::def_id::LocalDefId; use rustc_hir::def_id::LocalDefId;
use rustc_index::vec::IndexVec; use rustc_index::vec::IndexSlice;
use rustc_middle::mir::{create_dump_file, dump_enabled, dump_mir, PassWhere}; use rustc_middle::mir::{create_dump_file, dump_enabled, dump_mir, PassWhere};
use rustc_middle::mir::{ use rustc_middle::mir::{
BasicBlock, Body, ClosureOutlivesSubject, ClosureRegionRequirements, LocalKind, Location, BasicBlock, Body, ClosureOutlivesSubject, ClosureRegionRequirements, LocalKind, Location,
@ -59,7 +59,7 @@ pub(crate) fn replace_regions_in_mir<'tcx>(
infcx: &BorrowckInferCtxt<'_, 'tcx>, infcx: &BorrowckInferCtxt<'_, 'tcx>,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
body: &mut Body<'tcx>, body: &mut Body<'tcx>,
promoted: &mut IndexVec<Promoted, Body<'tcx>>, promoted: &mut IndexSlice<Promoted, Body<'tcx>>,
) -> UniversalRegions<'tcx> { ) -> UniversalRegions<'tcx> {
let def = body.source.with_opt_param().as_local().unwrap(); let def = body.source.with_opt_param().as_local().unwrap();
@ -158,7 +158,7 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
infcx: &BorrowckInferCtxt<'_, 'tcx>, infcx: &BorrowckInferCtxt<'_, 'tcx>,
universal_regions: UniversalRegions<'tcx>, universal_regions: UniversalRegions<'tcx>,
body: &Body<'tcx>, body: &Body<'tcx>,
promoted: &IndexVec<Promoted, Body<'tcx>>, promoted: &IndexSlice<Promoted, Body<'tcx>>,
location_table: &LocationTable, location_table: &LocationTable,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
flow_inits: &mut ResultsCursor<'cx, 'tcx, MaybeInitializedPlaces<'cx, 'tcx>>, flow_inits: &mut ResultsCursor<'cx, 'tcx, MaybeInitializedPlaces<'cx, 'tcx>>,

View file

@ -7,7 +7,7 @@ use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_data_structures::graph::scc::Sccs; use rustc_data_structures::graph::scc::Sccs;
use rustc_errors::Diagnostic; use rustc_errors::Diagnostic;
use rustc_hir::def_id::CRATE_DEF_ID; use rustc_hir::def_id::CRATE_DEF_ID;
use rustc_index::vec::IndexVec; use rustc_index::vec::{IndexSlice, IndexVec};
use rustc_infer::infer::outlives::test_type_match; use rustc_infer::infer::outlives::test_type_match;
use rustc_infer::infer::region_constraints::{GenericKind, VarInfos, VerifyBound, VerifyIfEq}; use rustc_infer::infer::region_constraints::{GenericKind, VarInfos, VerifyBound, VerifyIfEq};
use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin}; use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin};
@ -399,7 +399,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// the minimum, or narrowest, universe. /// the minimum, or narrowest, universe.
fn compute_scc_universes( fn compute_scc_universes(
constraint_sccs: &Sccs<RegionVid, ConstraintSccIndex>, constraint_sccs: &Sccs<RegionVid, ConstraintSccIndex>,
definitions: &IndexVec<RegionVid, RegionDefinition<'tcx>>, definitions: &IndexSlice<RegionVid, RegionDefinition<'tcx>>,
) -> IndexVec<ConstraintSccIndex, ty::UniverseIndex> { ) -> IndexVec<ConstraintSccIndex, ty::UniverseIndex> {
let num_sccs = constraint_sccs.num_sccs(); let num_sccs = constraint_sccs.num_sccs();
let mut scc_universes = IndexVec::from_elem_n(ty::UniverseIndex::MAX, num_sccs); let mut scc_universes = IndexVec::from_elem_n(ty::UniverseIndex::MAX, num_sccs);
@ -486,7 +486,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// more details. /// more details.
fn compute_scc_representatives( fn compute_scc_representatives(
constraints_scc: &Sccs<RegionVid, ConstraintSccIndex>, constraints_scc: &Sccs<RegionVid, ConstraintSccIndex>,
definitions: &IndexVec<RegionVid, RegionDefinition<'tcx>>, definitions: &IndexSlice<RegionVid, RegionDefinition<'tcx>>,
) -> IndexVec<ConstraintSccIndex, ty::RegionVid> { ) -> IndexVec<ConstraintSccIndex, ty::RegionVid> {
let num_sccs = constraints_scc.num_sccs(); let num_sccs = constraints_scc.num_sccs();
let next_region_vid = definitions.next_index(); let next_region_vid = definitions.next_index();

View file

@ -1,7 +1,7 @@
#![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)] #![deny(rustc::diagnostic_outside_of_impl)]
use crate::BorrowckInferCtxt; use crate::BorrowckInferCtxt;
use rustc_index::vec::IndexVec; use rustc_index::vec::IndexSlice;
use rustc_infer::infer::NllRegionVariableOrigin; use rustc_infer::infer::NllRegionVariableOrigin;
use rustc_middle::mir::visit::{MutVisitor, TyContext}; use rustc_middle::mir::visit::{MutVisitor, TyContext};
use rustc_middle::mir::Constant; use rustc_middle::mir::Constant;
@ -16,7 +16,7 @@ use rustc_span::{Span, Symbol};
pub fn renumber_mir<'tcx>( pub fn renumber_mir<'tcx>(
infcx: &BorrowckInferCtxt<'_, 'tcx>, infcx: &BorrowckInferCtxt<'_, 'tcx>,
body: &mut Body<'tcx>, body: &mut Body<'tcx>,
promoted: &mut IndexVec<Promoted, Body<'tcx>>, promoted: &mut IndexSlice<Promoted, Body<'tcx>>,
) { ) {
debug!(?body.arg_count); debug!(?body.arg_count);

View file

@ -125,7 +125,7 @@ pub(crate) fn type_check<'mir, 'tcx>(
infcx: &BorrowckInferCtxt<'_, 'tcx>, infcx: &BorrowckInferCtxt<'_, 'tcx>,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
body: &Body<'tcx>, body: &Body<'tcx>,
promoted: &IndexVec<Promoted, Body<'tcx>>, promoted: &IndexSlice<Promoted, Body<'tcx>>,
universal_regions: &Rc<UniversalRegions<'tcx>>, universal_regions: &Rc<UniversalRegions<'tcx>>,
location_table: &LocationTable, location_table: &LocationTable,
borrow_set: &BorrowSet<'tcx>, borrow_set: &BorrowSet<'tcx>,
@ -292,7 +292,7 @@ enum FieldAccessError {
/// is a problem. /// is a problem.
struct TypeVerifier<'a, 'b, 'tcx> { struct TypeVerifier<'a, 'b, 'tcx> {
cx: &'a mut TypeChecker<'b, 'tcx>, cx: &'a mut TypeChecker<'b, 'tcx>,
promoted: &'b IndexVec<Promoted, Body<'tcx>>, promoted: &'b IndexSlice<Promoted, Body<'tcx>>,
last_span: Span, last_span: Span,
errors_reported: bool, errors_reported: bool,
} }
@ -493,7 +493,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
fn new( fn new(
cx: &'a mut TypeChecker<'b, 'tcx>, cx: &'a mut TypeChecker<'b, 'tcx>,
promoted: &'b IndexVec<Promoted, Body<'tcx>>, promoted: &'b IndexSlice<Promoted, Body<'tcx>>,
) -> Self { ) -> Self {
TypeVerifier { promoted, last_span: cx.body.span, cx, errors_reported: false } TypeVerifier { promoted, last_span: cx.body.span, cx, errors_reported: false }
} }

View file

@ -3,7 +3,7 @@ use rustc_codegen_ssa::debuginfo::{
wants_c_like_enum_debuginfo, wants_c_like_enum_debuginfo,
}; };
use rustc_hir::def::CtorKind; use rustc_hir::def::CtorKind;
use rustc_index::vec::IndexVec; use rustc_index::vec::IndexSlice;
use rustc_middle::{ use rustc_middle::{
bug, bug,
mir::{GeneratorLayout, GeneratorSavedLocal}, mir::{GeneratorLayout, GeneratorSavedLocal},
@ -323,7 +323,7 @@ pub fn build_generator_variant_struct_type_di_node<'ll, 'tcx>(
generator_type_and_layout: TyAndLayout<'tcx>, generator_type_and_layout: TyAndLayout<'tcx>,
generator_type_di_node: &'ll DIType, generator_type_di_node: &'ll DIType,
generator_layout: &GeneratorLayout<'tcx>, generator_layout: &GeneratorLayout<'tcx>,
state_specific_upvar_names: &IndexVec<GeneratorSavedLocal, Option<Symbol>>, state_specific_upvar_names: &IndexSlice<GeneratorSavedLocal, Option<Symbol>>,
common_upvar_names: &[String], common_upvar_names: &[String],
) -> &'ll DIType { ) -> &'ll DIType {
let variant_name = GeneratorSubsts::variant_name(variant_index); let variant_name = GeneratorSubsts::variant_name(variant_index);

View file

@ -1,6 +1,6 @@
pub use super::ffi::*; pub use super::ffi::*;
use rustc_index::vec::IndexVec; use rustc_index::vec::{IndexSlice, IndexVec};
use rustc_middle::mir::coverage::{ use rustc_middle::mir::coverage::{
CodeRegion, CounterValueReference, ExpressionOperandId, InjectedExpressionId, CodeRegion, CounterValueReference, ExpressionOperandId, InjectedExpressionId,
InjectedExpressionIndex, MappedExpressionIndex, Op, InjectedExpressionIndex, MappedExpressionIndex, Op,
@ -205,7 +205,7 @@ impl<'tcx> FunctionCoverage<'tcx> {
// `expression_index`s lower than the referencing `Expression`. Therefore, it is // `expression_index`s lower than the referencing `Expression`. Therefore, it is
// reasonable to look up the new index of an expression operand while the `new_indexes` // reasonable to look up the new index of an expression operand while the `new_indexes`
// vector is only complete up to the current `ExpressionIndex`. // vector is only complete up to the current `ExpressionIndex`.
let id_to_counter = |new_indexes: &IndexVec< let id_to_counter = |new_indexes: &IndexSlice<
InjectedExpressionIndex, InjectedExpressionIndex,
Option<MappedExpressionIndex>, Option<MappedExpressionIndex>,
>, >,

View file

@ -5,7 +5,7 @@ use super::FunctionCx;
use crate::traits::*; use crate::traits::*;
use rustc_data_structures::graph::dominators::Dominators; use rustc_data_structures::graph::dominators::Dominators;
use rustc_index::bit_set::BitSet; use rustc_index::bit_set::BitSet;
use rustc_index::vec::IndexVec; use rustc_index::vec::{IndexSlice, IndexVec};
use rustc_middle::mir::traversal; use rustc_middle::mir::traversal;
use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor};
use rustc_middle::mir::{self, Location, TerminatorKind}; use rustc_middle::mir::{self, Location, TerminatorKind};
@ -277,7 +277,7 @@ impl CleanupKind {
/// Recover that structure in an analyze pass. /// Recover that structure in an analyze pass.
pub fn cleanup_kinds(mir: &mir::Body<'_>) -> IndexVec<mir::BasicBlock, CleanupKind> { pub fn cleanup_kinds(mir: &mir::Body<'_>) -> IndexVec<mir::BasicBlock, CleanupKind> {
fn discover_masters<'tcx>( fn discover_masters<'tcx>(
result: &mut IndexVec<mir::BasicBlock, CleanupKind>, result: &mut IndexSlice<mir::BasicBlock, CleanupKind>,
mir: &mir::Body<'tcx>, mir: &mir::Body<'tcx>,
) { ) {
for (bb, data) in mir.basic_blocks.iter_enumerated() { for (bb, data) in mir.basic_blocks.iter_enumerated() {
@ -308,7 +308,10 @@ pub fn cleanup_kinds(mir: &mir::Body<'_>) -> IndexVec<mir::BasicBlock, CleanupKi
} }
} }
fn propagate<'tcx>(result: &mut IndexVec<mir::BasicBlock, CleanupKind>, mir: &mir::Body<'tcx>) { fn propagate<'tcx>(
result: &mut IndexSlice<mir::BasicBlock, CleanupKind>,
mir: &mir::Body<'tcx>,
) {
let mut funclet_succs = IndexVec::from_elem(None, &mir.basic_blocks); let mut funclet_succs = IndexVec::from_elem(None, &mir.basic_blocks);
let mut set_successor = |funclet: mir::BasicBlock, succ| match funclet_succs[funclet] { let mut set_successor = |funclet: mir::BasicBlock, succ| match funclet_succs[funclet] {

View file

@ -21,7 +21,7 @@ use rustc_middle::ty::subst::InternalSubsts;
use rustc_middle::ty::{self, List, TyCtxt, TypeVisitableExt}; use rustc_middle::ty::{self, List, TyCtxt, TypeVisitableExt};
use rustc_span::Span; use rustc_span::Span;
use rustc_index::vec::{Idx, IndexVec}; use rustc_index::vec::{Idx, IndexSlice, IndexVec};
use std::cell::Cell; use std::cell::Cell;
use std::{cmp, iter, mem}; use std::{cmp, iter, mem};
@ -184,7 +184,7 @@ pub fn collect_temps_and_candidates<'tcx>(
/// This wraps an `Item`, and has access to all fields of that `Item` via `Deref` coercion. /// This wraps an `Item`, and has access to all fields of that `Item` via `Deref` coercion.
struct Validator<'a, 'tcx> { struct Validator<'a, 'tcx> {
ccx: &'a ConstCx<'a, 'tcx>, ccx: &'a ConstCx<'a, 'tcx>,
temps: &'a mut IndexVec<Local, TempState>, temps: &'a mut IndexSlice<Local, TempState>,
} }
impl<'a, 'tcx> std::ops::Deref for Validator<'a, 'tcx> { impl<'a, 'tcx> std::ops::Deref for Validator<'a, 'tcx> {
@ -669,7 +669,7 @@ impl<'tcx> Validator<'_, 'tcx> {
// FIXME(eddyb) remove the differences for promotability in `static`, `const`, `const fn`. // FIXME(eddyb) remove the differences for promotability in `static`, `const`, `const fn`.
pub fn validate_candidates( pub fn validate_candidates(
ccx: &ConstCx<'_, '_>, ccx: &ConstCx<'_, '_>,
temps: &mut IndexVec<Local, TempState>, temps: &mut IndexSlice<Local, TempState>,
candidates: &[Candidate], candidates: &[Candidate],
) -> Vec<Candidate> { ) -> Vec<Candidate> {
let mut validator = Validator { ccx, temps }; let mut validator = Validator { ccx, temps };

View file

@ -10,7 +10,7 @@
//! <https://www.cs.princeton.edu/courses/archive/spr03/cs423/download/dominators.pdf> //! <https://www.cs.princeton.edu/courses/archive/spr03/cs423/download/dominators.pdf>
use super::ControlFlowGraph; use super::ControlFlowGraph;
use rustc_index::vec::{Idx, IndexVec}; use rustc_index::vec::{Idx, IndexSlice, IndexVec};
use std::cmp::Ordering; use std::cmp::Ordering;
#[cfg(test)] #[cfg(test)]
@ -256,10 +256,10 @@ pub fn dominators<G: ControlFlowGraph>(graph: G) -> Dominators<G::Node> {
/// where `+>` is a proper ancestor and `*>` is just an ancestor. /// where `+>` is a proper ancestor and `*>` is just an ancestor.
#[inline] #[inline]
fn eval( fn eval(
ancestor: &mut IndexVec<PreorderIndex, PreorderIndex>, ancestor: &mut IndexSlice<PreorderIndex, PreorderIndex>,
lastlinked: Option<PreorderIndex>, lastlinked: Option<PreorderIndex>,
semi: &IndexVec<PreorderIndex, PreorderIndex>, semi: &IndexSlice<PreorderIndex, PreorderIndex>,
label: &mut IndexVec<PreorderIndex, PreorderIndex>, label: &mut IndexSlice<PreorderIndex, PreorderIndex>,
node: PreorderIndex, node: PreorderIndex,
) -> PreorderIndex { ) -> PreorderIndex {
if is_processed(node, lastlinked) { if is_processed(node, lastlinked) {
@ -277,10 +277,10 @@ fn is_processed(v: PreorderIndex, lastlinked: Option<PreorderIndex>) -> bool {
#[inline] #[inline]
fn compress( fn compress(
ancestor: &mut IndexVec<PreorderIndex, PreorderIndex>, ancestor: &mut IndexSlice<PreorderIndex, PreorderIndex>,
lastlinked: Option<PreorderIndex>, lastlinked: Option<PreorderIndex>,
semi: &IndexVec<PreorderIndex, PreorderIndex>, semi: &IndexSlice<PreorderIndex, PreorderIndex>,
label: &mut IndexVec<PreorderIndex, PreorderIndex>, label: &mut IndexSlice<PreorderIndex, PreorderIndex>,
v: PreorderIndex, v: PreorderIndex,
) { ) {
assert!(is_processed(v, lastlinked)); assert!(is_processed(v, lastlinked));

View file

@ -1,6 +1,6 @@
use super::{DirectedGraph, WithNumNodes, WithStartNode, WithSuccessors}; use super::{DirectedGraph, WithNumNodes, WithStartNode, WithSuccessors};
use rustc_index::bit_set::BitSet; use rustc_index::bit_set::BitSet;
use rustc_index::vec::IndexVec; use rustc_index::vec::{IndexSlice, IndexVec};
use std::ops::ControlFlow; use std::ops::ControlFlow;
#[cfg(test)] #[cfg(test)]
@ -31,7 +31,7 @@ fn post_order_walk<G: DirectedGraph + WithSuccessors + WithNumNodes>(
graph: &G, graph: &G,
node: G::Node, node: G::Node,
result: &mut Vec<G::Node>, result: &mut Vec<G::Node>,
visited: &mut IndexVec<G::Node, bool>, visited: &mut IndexSlice<G::Node, bool>,
) { ) {
struct PostOrderFrame<Node, Iter> { struct PostOrderFrame<Node, Iter> {
node: Node, node: Node,

View file

@ -8,7 +8,7 @@
use crate::fx::FxHashSet; use crate::fx::FxHashSet;
use crate::graph::vec_graph::VecGraph; use crate::graph::vec_graph::VecGraph;
use crate::graph::{DirectedGraph, GraphSuccessors, WithNumEdges, WithNumNodes, WithSuccessors}; use crate::graph::{DirectedGraph, GraphSuccessors, WithNumEdges, WithNumNodes, WithSuccessors};
use rustc_index::vec::{Idx, IndexVec}; use rustc_index::vec::{Idx, IndexSlice, IndexVec};
use std::ops::Range; use std::ops::Range;
#[cfg(test)] #[cfg(test)]
@ -43,7 +43,7 @@ impl<N: Idx, S: Idx + Ord> Sccs<N, S> {
SccsConstruction::construct(graph) SccsConstruction::construct(graph)
} }
pub fn scc_indices(&self) -> &IndexVec<N, S> { pub fn scc_indices(&self) -> &IndexSlice<N, S> {
&self.scc_indices &self.scc_indices
} }
@ -123,7 +123,7 @@ impl<S: Idx> SccData<S> {
self.ranges.len() self.ranges.len()
} }
pub fn ranges(&self) -> &IndexVec<S, Range<usize>> { pub fn ranges(&self) -> &IndexSlice<S, Range<usize>> {
&self.ranges &self.ranges
} }

View file

@ -1,6 +1,7 @@
#[cfg(feature = "rustc_serialize")] #[cfg(feature = "rustc_serialize")]
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
use std::borrow::{Borrow, BorrowMut};
use std::fmt; use std::fmt;
use std::fmt::Debug; use std::fmt::Debug;
use std::hash::Hash; use std::hash::Hash;
@ -51,6 +52,12 @@ impl Idx for u32 {
} }
} }
/// An owned contiguous collection of `T`s, indexed by `I` rather than by `usize`.
///
/// While it's possible to use `u32` or `usize` directly for `I`,
/// you almost certainly want to use a [`newtype_index!`]-generated type instead.
///
/// [`newtype_index!`]: ../macro.newtype_index.html
#[derive(Clone, PartialEq, Eq, Hash)] #[derive(Clone, PartialEq, Eq, Hash)]
#[repr(transparent)] #[repr(transparent)]
pub struct IndexVec<I: Idx, T> { pub struct IndexVec<I: Idx, T> {
@ -58,6 +65,13 @@ pub struct IndexVec<I: Idx, T> {
_marker: PhantomData<fn(&I)>, _marker: PhantomData<fn(&I)>,
} }
/// A view into contiguous `T`s, indexed by `I` rather than by `usize`.
///
/// One common pattern you'll see is code that uses [`IndexVec::from_elem`]
/// to create the storage needed for a particular "universe" (aka the set of all
/// the possible keys that need an associated value) then passes that working
/// area as `&mut IndexSlice<I, T>` to clarify that nothing will be added nor
/// removed during processing (and, as a bonus, to chase fewer pointers).
#[derive(PartialEq, Eq, Hash)] #[derive(PartialEq, Eq, Hash)]
#[repr(transparent)] #[repr(transparent)]
pub struct IndexSlice<I: Idx, T> { pub struct IndexSlice<I: Idx, T> {
@ -116,7 +130,7 @@ impl<I: Idx, T> IndexVec<I, T> {
} }
#[inline] #[inline]
pub fn from_elem<S>(elem: T, universe: &IndexVec<I, S>) -> Self pub fn from_elem<S>(elem: T, universe: &IndexSlice<I, S>) -> Self
where where
T: Clone, T: Clone,
{ {
@ -244,6 +258,30 @@ impl<I: Idx, T> DerefMut for IndexVec<I, T> {
} }
} }
impl<I: Idx, T> Borrow<IndexSlice<I, T>> for IndexVec<I, T> {
fn borrow(&self) -> &IndexSlice<I, T> {
self
}
}
impl<I: Idx, T> BorrowMut<IndexSlice<I, T>> for IndexVec<I, T> {
fn borrow_mut(&mut self) -> &mut IndexSlice<I, T> {
self
}
}
impl<I: Idx, T: Clone> ToOwned for IndexSlice<I, T> {
type Owned = IndexVec<I, T>;
fn to_owned(&self) -> IndexVec<I, T> {
IndexVec::from_raw(self.raw.to_owned())
}
fn clone_into(&self, target: &mut IndexVec<I, T>) {
self.raw.clone_into(&mut target.raw)
}
}
impl<I: Idx, T> IndexSlice<I, T> { impl<I: Idx, T> IndexSlice<I, T> {
#[inline] #[inline]
pub fn from_raw(raw: &[T]) -> &Self { pub fn from_raw(raw: &[T]) -> &Self {
@ -388,7 +426,7 @@ impl<I: Idx, T: Clone> IndexVec<I, T> {
} }
} }
impl<I: Idx, T: Ord> IndexVec<I, T> { impl<I: Idx, T: Ord> IndexSlice<I, T> {
#[inline] #[inline]
pub fn binary_search(&self, value: &T) -> Result<I, I> { pub fn binary_search(&self, value: &T) -> Result<I, I> {
match self.raw.binary_search(value) { match self.raw.binary_search(value) {

View file

@ -13,7 +13,7 @@ use rustc_data_structures::graph::implementation::{
Direction, Graph, NodeIndex, INCOMING, OUTGOING, Direction, Graph, NodeIndex, INCOMING, OUTGOING,
}; };
use rustc_data_structures::intern::Interned; use rustc_data_structures::intern::Interned;
use rustc_index::vec::IndexVec; use rustc_index::vec::{IndexSlice, IndexVec};
use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::PlaceholderRegion; use rustc_middle::ty::PlaceholderRegion;
use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::ty::{self, Ty, TyCtxt};
@ -723,7 +723,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
fn collect_error_for_expanding_node( fn collect_error_for_expanding_node(
&self, &self,
graph: &RegionGraph<'tcx>, graph: &RegionGraph<'tcx>,
dup_vec: &mut IndexVec<RegionVid, Option<RegionVid>>, dup_vec: &mut IndexSlice<RegionVid, Option<RegionVid>>,
node_idx: RegionVid, node_idx: RegionVid,
errors: &mut Vec<RegionResolutionError<'tcx>>, errors: &mut Vec<RegionResolutionError<'tcx>>,
) { ) {
@ -846,7 +846,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
graph: &RegionGraph<'tcx>, graph: &RegionGraph<'tcx>,
orig_node_idx: RegionVid, orig_node_idx: RegionVid,
dir: Direction, dir: Direction,
mut dup_vec: Option<&mut IndexVec<RegionVid, Option<RegionVid>>>, mut dup_vec: Option<&mut IndexSlice<RegionVid, Option<RegionVid>>>,
) -> (Vec<RegionAndOrigin<'tcx>>, FxHashSet<RegionVid>, bool) { ) -> (Vec<RegionAndOrigin<'tcx>>, FxHashSet<RegionVid>, bool) {
struct WalkState<'tcx> { struct WalkState<'tcx> {
set: FxHashSet<RegionVid>, set: FxHashSet<RegionVid>,

View file

@ -6,7 +6,7 @@ use rustc_data_structures::graph;
use rustc_data_structures::graph::dominators::{dominators, Dominators}; use rustc_data_structures::graph::dominators::{dominators, Dominators};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::sync::OnceCell; use rustc_data_structures::sync::OnceCell;
use rustc_index::vec::IndexVec; use rustc_index::vec::{IndexSlice, IndexVec};
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
use smallvec::SmallVec; use smallvec::SmallVec;
@ -124,10 +124,10 @@ impl<'tcx> BasicBlocks<'tcx> {
} }
impl<'tcx> std::ops::Deref for BasicBlocks<'tcx> { impl<'tcx> std::ops::Deref for BasicBlocks<'tcx> {
type Target = IndexVec<BasicBlock, BasicBlockData<'tcx>>; type Target = IndexSlice<BasicBlock, BasicBlockData<'tcx>>;
#[inline] #[inline]
fn deref(&self) -> &IndexVec<BasicBlock, BasicBlockData<'tcx>> { fn deref(&self) -> &IndexSlice<BasicBlock, BasicBlockData<'tcx>> {
&self.basic_blocks &self.basic_blocks
} }
} }

View file

@ -27,7 +27,7 @@ use polonius_engine::Atom;
pub use rustc_ast::Mutability; pub use rustc_ast::Mutability;
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::graph::dominators::Dominators; use rustc_data_structures::graph::dominators::Dominators;
use rustc_index::vec::{Idx, IndexVec}; use rustc_index::vec::{Idx, IndexSlice, IndexVec};
use rustc_serialize::{Decodable, Encodable}; use rustc_serialize::{Decodable, Encodable};
use rustc_span::symbol::Symbol; use rustc_span::symbol::Symbol;
use rustc_span::{Span, DUMMY_SP}; use rustc_span::{Span, DUMMY_SP};
@ -70,12 +70,19 @@ pub use self::pretty::{
}; };
/// Types for locals /// Types for locals
pub type LocalDecls<'tcx> = IndexVec<Local, LocalDecl<'tcx>>; pub type LocalDecls<'tcx> = IndexSlice<Local, LocalDecl<'tcx>>;
pub trait HasLocalDecls<'tcx> { pub trait HasLocalDecls<'tcx> {
fn local_decls(&self) -> &LocalDecls<'tcx>; fn local_decls(&self) -> &LocalDecls<'tcx>;
} }
impl<'tcx> HasLocalDecls<'tcx> for IndexVec<Local, LocalDecl<'tcx>> {
#[inline]
fn local_decls(&self) -> &LocalDecls<'tcx> {
self
}
}
impl<'tcx> HasLocalDecls<'tcx> for LocalDecls<'tcx> { impl<'tcx> HasLocalDecls<'tcx> for LocalDecls<'tcx> {
#[inline] #[inline]
fn local_decls(&self) -> &LocalDecls<'tcx> { fn local_decls(&self) -> &LocalDecls<'tcx> {
@ -250,7 +257,7 @@ pub struct Body<'tcx> {
/// The first local is the return value pointer, followed by `arg_count` /// The first local is the return value pointer, followed by `arg_count`
/// locals for the function arguments, followed by any user-declared /// locals for the function arguments, followed by any user-declared
/// variables and temporaries. /// variables and temporaries.
pub local_decls: LocalDecls<'tcx>, pub local_decls: IndexVec<Local, LocalDecl<'tcx>>,
/// User type annotations. /// User type annotations.
pub user_type_annotations: ty::CanonicalUserTypeAnnotations<'tcx>, pub user_type_annotations: ty::CanonicalUserTypeAnnotations<'tcx>,
@ -311,7 +318,7 @@ impl<'tcx> Body<'tcx> {
source: MirSource<'tcx>, source: MirSource<'tcx>,
basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>, basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
source_scopes: IndexVec<SourceScope, SourceScopeData<'tcx>>, source_scopes: IndexVec<SourceScope, SourceScopeData<'tcx>>,
local_decls: LocalDecls<'tcx>, local_decls: IndexVec<Local, LocalDecl<'tcx>>,
user_type_annotations: ty::CanonicalUserTypeAnnotations<'tcx>, user_type_annotations: ty::CanonicalUserTypeAnnotations<'tcx>,
arg_count: usize, arg_count: usize,
var_debug_info: Vec<VarDebugInfo<'tcx>>, var_debug_info: Vec<VarDebugInfo<'tcx>>,
@ -1779,7 +1786,7 @@ impl SourceScope {
/// from the function that was inlined instead of the function call site. /// from the function that was inlined instead of the function call site.
pub fn lint_root( pub fn lint_root(
self, self,
source_scopes: &IndexVec<SourceScope, SourceScopeData<'_>>, source_scopes: &IndexSlice<SourceScope, SourceScopeData<'_>>,
) -> Option<HirId> { ) -> Option<HirId> {
let mut data = &source_scopes[self]; let mut data = &source_scopes[self];
// FIXME(oli-obk): we should be able to just walk the `inlined_parent_scope`, but it // FIXME(oli-obk): we should be able to just walk the `inlined_parent_scope`, but it
@ -1799,7 +1806,7 @@ impl SourceScope {
#[inline] #[inline]
pub fn inlined_instance<'tcx>( pub fn inlined_instance<'tcx>(
self, self,
source_scopes: &IndexVec<SourceScope, SourceScopeData<'tcx>>, source_scopes: &IndexSlice<SourceScope, SourceScopeData<'tcx>>,
) -> Option<ty::Instance<'tcx>> { ) -> Option<ty::Instance<'tcx>> {
let scope_data = &source_scopes[self]; let scope_data = &source_scopes[self];
if let Some((inlined_instance, _)) = scope_data.inlined { if let Some((inlined_instance, _)) = scope_data.inlined {

View file

@ -116,7 +116,7 @@ impl<'tcx> PlaceTy<'tcx> {
} }
impl<'tcx> Place<'tcx> { impl<'tcx> Place<'tcx> {
pub fn ty_from<D>( pub fn ty_from<D: ?Sized>(
local: Local, local: Local,
projection: &[PlaceElem<'tcx>], projection: &[PlaceElem<'tcx>],
local_decls: &D, local_decls: &D,
@ -132,7 +132,7 @@ impl<'tcx> Place<'tcx> {
}) })
} }
pub fn ty<D>(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> PlaceTy<'tcx> pub fn ty<D: ?Sized>(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> PlaceTy<'tcx>
where where
D: HasLocalDecls<'tcx>, D: HasLocalDecls<'tcx>,
{ {
@ -141,7 +141,7 @@ impl<'tcx> Place<'tcx> {
} }
impl<'tcx> PlaceRef<'tcx> { impl<'tcx> PlaceRef<'tcx> {
pub fn ty<D>(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> PlaceTy<'tcx> pub fn ty<D: ?Sized>(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> PlaceTy<'tcx>
where where
D: HasLocalDecls<'tcx>, D: HasLocalDecls<'tcx>,
{ {
@ -155,7 +155,7 @@ pub enum RvalueInitializationState {
} }
impl<'tcx> Rvalue<'tcx> { impl<'tcx> Rvalue<'tcx> {
pub fn ty<D>(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> Ty<'tcx> pub fn ty<D: ?Sized>(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> Ty<'tcx>
where where
D: HasLocalDecls<'tcx>, D: HasLocalDecls<'tcx>,
{ {
@ -217,7 +217,7 @@ impl<'tcx> Rvalue<'tcx> {
} }
impl<'tcx> Operand<'tcx> { impl<'tcx> Operand<'tcx> {
pub fn ty<D>(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> Ty<'tcx> pub fn ty<D: ?Sized>(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> Ty<'tcx>
where where
D: HasLocalDecls<'tcx>, D: HasLocalDecls<'tcx>,
{ {

View file

@ -101,7 +101,7 @@ impl<'a, 'tcx> Iterator for Preorder<'a, 'tcx> {
/// ///
/// A Postorder traversal of this graph is `D B C A` or `D C B A` /// A Postorder traversal of this graph is `D B C A` or `D C B A`
pub struct Postorder<'a, 'tcx> { pub struct Postorder<'a, 'tcx> {
basic_blocks: &'a IndexVec<BasicBlock, BasicBlockData<'tcx>>, basic_blocks: &'a IndexSlice<BasicBlock, BasicBlockData<'tcx>>,
visited: BitSet<BasicBlock>, visited: BitSet<BasicBlock>,
visit_stack: Vec<(BasicBlock, Successors<'a>)>, visit_stack: Vec<(BasicBlock, Successors<'a>)>,
root_is_start_block: bool, root_is_start_block: bool,
@ -109,7 +109,7 @@ pub struct Postorder<'a, 'tcx> {
impl<'a, 'tcx> Postorder<'a, 'tcx> { impl<'a, 'tcx> Postorder<'a, 'tcx> {
pub fn new( pub fn new(
basic_blocks: &'a IndexVec<BasicBlock, BasicBlockData<'tcx>>, basic_blocks: &'a IndexSlice<BasicBlock, BasicBlockData<'tcx>>,
root: BasicBlock, root: BasicBlock,
) -> Postorder<'a, 'tcx> { ) -> Postorder<'a, 'tcx> {
let mut po = Postorder { let mut po = Postorder {

View file

@ -10,7 +10,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::def::{CtorKind, DefKind, Res};
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_index::vec::IndexVec; use rustc_index::vec::{IndexSlice, IndexVec};
use rustc_query_system::ich::StableHashingContext; use rustc_query_system::ich::StableHashingContext;
use rustc_session::DataTypeKind; use rustc_session::DataTypeKind;
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
@ -168,7 +168,7 @@ impl<'tcx> AdtDef<'tcx> {
} }
#[inline] #[inline]
pub fn variants(self) -> &'tcx IndexVec<VariantIdx, VariantDef> { pub fn variants(self) -> &'tcx IndexSlice<VariantIdx, VariantDef> {
&self.0.0.variants &self.0.0.variants
} }

View file

@ -21,7 +21,7 @@ use rustc_ast::Attribute;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::HirId; use rustc_hir::HirId;
use rustc_index::vec::IndexVec; use rustc_index::vec::{IndexSlice, IndexVec};
use rustc_middle::{ use rustc_middle::{
mir::*, mir::*,
thir::*, thir::*,
@ -37,7 +37,7 @@ pub(super) fn build_custom_mir<'tcx>(
hir_id: HirId, hir_id: HirId,
thir: &Thir<'tcx>, thir: &Thir<'tcx>,
expr: ExprId, expr: ExprId,
params: &IndexVec<ParamId, Param<'tcx>>, params: &IndexSlice<ParamId, Param<'tcx>>,
return_ty: Ty<'tcx>, return_ty: Ty<'tcx>,
return_ty_span: Span, return_ty_span: Span,
span: Span, span: Span,
@ -49,7 +49,7 @@ pub(super) fn build_custom_mir<'tcx>(
phase: MirPhase::Built, phase: MirPhase::Built,
source_scopes: IndexVec::new(), source_scopes: IndexVec::new(),
generator: None, generator: None,
local_decls: LocalDecls::new(), local_decls: IndexVec::new(),
user_type_annotations: IndexVec::new(), user_type_annotations: IndexVec::new(),
arg_count: params.len(), arg_count: params.len(),
spread_arg: None, spread_arg: None,

View file

@ -1,4 +1,4 @@
use rustc_index::vec::IndexVec; use rustc_index::vec::IndexSlice;
use rustc_middle::{mir::*, thir::*, ty::Ty}; use rustc_middle::{mir::*, thir::*, ty::Ty};
use rustc_span::Span; use rustc_span::Span;
@ -81,7 +81,7 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
} }
} }
pub fn parse_args(&mut self, params: &IndexVec<ParamId, Param<'tcx>>) -> PResult<()> { pub fn parse_args(&mut self, params: &IndexSlice<ParamId, Param<'tcx>>) -> PResult<()> {
for param in params.iter() { for param in params.iter() {
let (var, span) = { let (var, span) = {
let pat = param.pat.as_ref().unwrap(); let pat = param.pat.as_ref().unwrap();

View file

@ -11,7 +11,7 @@ use rustc_hir as hir;
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::{GeneratorKind, Node}; use rustc_hir::{GeneratorKind, Node};
use rustc_index::vec::{Idx, IndexVec}; use rustc_index::vec::{Idx, IndexSlice, IndexVec};
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
use rustc_middle::hir::place::PlaceBase as HirPlaceBase; use rustc_middle::hir::place::PlaceBase as HirPlaceBase;
use rustc_middle::middle::region; use rustc_middle::middle::region;
@ -821,7 +821,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
fn args_and_body( fn args_and_body(
&mut self, &mut self,
mut block: BasicBlock, mut block: BasicBlock,
arguments: &IndexVec<ParamId, Param<'tcx>>, arguments: &IndexSlice<ParamId, Param<'tcx>>,
argument_scope: region::Scope, argument_scope: region::Scope,
expr: &Expr<'tcx>, expr: &Expr<'tcx>,
) -> BlockAnd<()> { ) -> BlockAnd<()> {

View file

@ -86,7 +86,7 @@ use std::mem;
use crate::build::{BlockAnd, BlockAndExtension, BlockFrame, Builder, CFG}; use crate::build::{BlockAnd, BlockAndExtension, BlockFrame, Builder, CFG};
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_hir::HirId; use rustc_hir::HirId;
use rustc_index::vec::IndexVec; use rustc_index::vec::{IndexSlice, IndexVec};
use rustc_middle::middle::region; use rustc_middle::middle::region;
use rustc_middle::mir::*; use rustc_middle::mir::*;
use rustc_middle::thir::{Expr, LintLevel}; use rustc_middle::thir::{Expr, LintLevel};
@ -360,7 +360,7 @@ impl DropTree {
fn link_blocks<'tcx>( fn link_blocks<'tcx>(
&self, &self,
cfg: &mut CFG<'tcx>, cfg: &mut CFG<'tcx>,
blocks: &IndexVec<DropIdx, Option<BasicBlock>>, blocks: &IndexSlice<DropIdx, Option<BasicBlock>>,
) { ) {
for (drop_idx, drop_data) in self.drops.iter_enumerated().rev() { for (drop_idx, drop_data) in self.drops.iter_enumerated().rev() {
let Some(block) = blocks[drop_idx] else { continue }; let Some(block) = blocks[drop_idx] else { continue };

View file

@ -1,6 +1,6 @@
use crate::move_paths::builder::MoveDat; use crate::move_paths::builder::MoveDat;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_index::vec::IndexVec; use rustc_index::vec::{IndexSlice, IndexVec};
use rustc_middle::mir::*; use rustc_middle::mir::*;
use rustc_middle::ty::{ParamEnv, Ty, TyCtxt}; use rustc_middle::ty::{ParamEnv, Ty, TyCtxt};
use rustc_span::Span; use rustc_span::Span;
@ -64,7 +64,7 @@ impl<'tcx> MovePath<'tcx> {
/// Returns an iterator over the parents of `self`. /// Returns an iterator over the parents of `self`.
pub fn parents<'a>( pub fn parents<'a>(
&self, &self,
move_paths: &'a IndexVec<MovePathIndex, MovePath<'tcx>>, move_paths: &'a IndexSlice<MovePathIndex, MovePath<'tcx>>,
) -> impl 'a + Iterator<Item = (MovePathIndex, &'a MovePath<'tcx>)> { ) -> impl 'a + Iterator<Item = (MovePathIndex, &'a MovePath<'tcx>)> {
let first = self.parent.map(|mpi| (mpi, &move_paths[mpi])); let first = self.parent.map(|mpi| (mpi, &move_paths[mpi]));
MovePathLinearIter { MovePathLinearIter {
@ -78,7 +78,7 @@ impl<'tcx> MovePath<'tcx> {
/// Returns an iterator over the immediate children of `self`. /// Returns an iterator over the immediate children of `self`.
pub fn children<'a>( pub fn children<'a>(
&self, &self,
move_paths: &'a IndexVec<MovePathIndex, MovePath<'tcx>>, move_paths: &'a IndexSlice<MovePathIndex, MovePath<'tcx>>,
) -> impl 'a + Iterator<Item = (MovePathIndex, &'a MovePath<'tcx>)> { ) -> impl 'a + Iterator<Item = (MovePathIndex, &'a MovePath<'tcx>)> {
let first = self.first_child.map(|mpi| (mpi, &move_paths[mpi])); let first = self.first_child.map(|mpi| (mpi, &move_paths[mpi]));
MovePathLinearIter { MovePathLinearIter {
@ -95,7 +95,7 @@ impl<'tcx> MovePath<'tcx> {
/// `f` will **not** be called on `self`. /// `f` will **not** be called on `self`.
pub fn find_descendant( pub fn find_descendant(
&self, &self,
move_paths: &IndexVec<MovePathIndex, MovePath<'_>>, move_paths: &IndexSlice<MovePathIndex, MovePath<'_>>,
f: impl Fn(MovePathIndex) -> bool, f: impl Fn(MovePathIndex) -> bool,
) -> Option<MovePathIndex> { ) -> Option<MovePathIndex> {
let mut todo = if let Some(child) = self.first_child { let mut todo = if let Some(child) = self.first_child {

View file

@ -36,7 +36,7 @@ use std::fmt::{Debug, Formatter};
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_index::bit_set::BitSet; use rustc_index::bit_set::BitSet;
use rustc_index::vec::IndexVec; use rustc_index::vec::{IndexSlice, IndexVec};
use rustc_middle::mir::visit::{MutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::visit::{MutatingUseContext, PlaceContext, Visitor};
use rustc_middle::mir::*; use rustc_middle::mir::*;
use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::ty::{self, Ty, TyCtxt};
@ -1028,8 +1028,8 @@ where
fn debug_with_context_rec<V: Debug + Eq>( fn debug_with_context_rec<V: Debug + Eq>(
place: PlaceIndex, place: PlaceIndex,
place_str: &str, place_str: &str,
new: &IndexVec<ValueIndex, V>, new: &IndexSlice<ValueIndex, V>,
old: Option<&IndexVec<ValueIndex, V>>, old: Option<&IndexSlice<ValueIndex, V>>,
map: &Map, map: &Map,
f: &mut Formatter<'_>, f: &mut Formatter<'_>,
) -> std::fmt::Result { ) -> std::fmt::Result {
@ -1069,8 +1069,8 @@ fn debug_with_context_rec<V: Debug + Eq>(
} }
fn debug_with_context<V: Debug + Eq>( fn debug_with_context<V: Debug + Eq>(
new: &IndexVec<ValueIndex, V>, new: &IndexSlice<ValueIndex, V>,
old: Option<&IndexVec<ValueIndex, V>>, old: Option<&IndexSlice<ValueIndex, V>>,
map: &Map, map: &Map,
f: &mut Formatter<'_>, f: &mut Formatter<'_>,
) -> std::fmt::Result { ) -> std::fmt::Result {

View file

@ -128,7 +128,7 @@ fn split_block(
fn insert_alignment_check<'tcx>( fn insert_alignment_check<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
local_decls: &mut LocalDecls<'tcx>, local_decls: &mut IndexVec<Local, LocalDecl<'tcx>>,
block_data: &mut BasicBlockData<'tcx>, block_data: &mut BasicBlockData<'tcx>,
pointer: Place<'tcx>, pointer: Place<'tcx>,
pointee_ty: Ty<'tcx>, pointee_ty: Ty<'tcx>,

View file

@ -7,7 +7,7 @@ use rustc_const_eval::const_eval::CheckAlignment;
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
use rustc_index::bit_set::BitSet; use rustc_index::bit_set::BitSet;
use rustc_index::vec::IndexVec; use rustc_index::vec::{IndexSlice, IndexVec};
use rustc_middle::mir::visit::{ use rustc_middle::mir::visit::{
MutVisitor, MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor, MutVisitor, MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor,
}; };
@ -127,7 +127,7 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
let dummy_body = &Body::new( let dummy_body = &Body::new(
body.source, body.source,
(*body.basic_blocks).clone(), (*body.basic_blocks).to_owned(),
body.source_scopes.clone(), body.source_scopes.clone(),
body.local_decls.clone(), body.local_decls.clone(),
Default::default(), Default::default(),
@ -319,7 +319,7 @@ struct ConstPropagator<'mir, 'tcx> {
ecx: InterpCx<'mir, 'tcx, ConstPropMachine<'mir, 'tcx>>, ecx: InterpCx<'mir, 'tcx, ConstPropMachine<'mir, 'tcx>>,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
param_env: ParamEnv<'tcx>, param_env: ParamEnv<'tcx>,
local_decls: &'mir IndexVec<Local, LocalDecl<'tcx>>, local_decls: &'mir IndexSlice<Local, LocalDecl<'tcx>>,
} }
impl<'tcx> LayoutOfHelpers<'tcx> for ConstPropagator<'_, 'tcx> { impl<'tcx> LayoutOfHelpers<'tcx> for ConstPropagator<'_, 'tcx> {

View file

@ -9,7 +9,7 @@ use rustc_const_eval::interpret::{
}; };
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
use rustc_hir::HirId; use rustc_hir::HirId;
use rustc_index::vec::IndexVec; use rustc_index::vec::IndexSlice;
use rustc_middle::mir::visit::Visitor; use rustc_middle::mir::visit::Visitor;
use rustc_middle::mir::*; use rustc_middle::mir::*;
use rustc_middle::ty::layout::{LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout}; use rustc_middle::ty::layout::{LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout};
@ -103,7 +103,7 @@ impl<'tcx> MirLint<'tcx> for ConstProp {
let dummy_body = &Body::new( let dummy_body = &Body::new(
body.source, body.source,
(*body.basic_blocks).clone(), (*body.basic_blocks).to_owned(),
body.source_scopes.clone(), body.source_scopes.clone(),
body.local_decls.clone(), body.local_decls.clone(),
Default::default(), Default::default(),
@ -130,8 +130,8 @@ struct ConstPropagator<'mir, 'tcx> {
ecx: InterpCx<'mir, 'tcx, ConstPropMachine<'mir, 'tcx>>, ecx: InterpCx<'mir, 'tcx, ConstPropMachine<'mir, 'tcx>>,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
param_env: ParamEnv<'tcx>, param_env: ParamEnv<'tcx>,
source_scopes: &'mir IndexVec<SourceScope, SourceScopeData<'tcx>>, source_scopes: &'mir IndexSlice<SourceScope, SourceScopeData<'tcx>>,
local_decls: &'mir IndexVec<Local, LocalDecl<'tcx>>, local_decls: &'mir IndexSlice<Local, LocalDecl<'tcx>>,
// Because we have `MutVisitor` we can't obtain the `SourceInfo` from a `Location`. So we store // Because we have `MutVisitor` we can't obtain the `SourceInfo` from a `Location`. So we store
// the last known `SourceInfo` here and just keep revisiting it. // the last known `SourceInfo` here and just keep revisiting it.
source_info: Option<SourceInfo>, source_info: Option<SourceInfo>,

View file

@ -1,5 +1,5 @@
use rustc_index::bit_set::BitSet; use rustc_index::bit_set::BitSet;
use rustc_index::vec::IndexVec; use rustc_index::vec::IndexSlice;
use rustc_middle::mir::visit::*; use rustc_middle::mir::visit::*;
use rustc_middle::mir::*; use rustc_middle::mir::*;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
@ -102,7 +102,7 @@ struct Replacer<'a, 'tcx> {
fully_moved: BitSet<Local>, fully_moved: BitSet<Local>,
storage_to_remove: BitSet<Local>, storage_to_remove: BitSet<Local>,
borrowed_locals: BitSet<Local>, borrowed_locals: BitSet<Local>,
copy_classes: &'a IndexVec<Local, Local>, copy_classes: &'a IndexSlice<Local, Local>,
} }
impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> { impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> {

View file

@ -5,7 +5,7 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::graph::dominators::{self, Dominators}; use rustc_data_structures::graph::dominators::{self, Dominators};
use rustc_data_structures::graph::{self, GraphSuccessors, WithNumNodes, WithStartNode}; use rustc_data_structures::graph::{self, GraphSuccessors, WithNumNodes, WithStartNode};
use rustc_index::bit_set::BitSet; use rustc_index::bit_set::BitSet;
use rustc_index::vec::IndexVec; use rustc_index::vec::{IndexSlice, IndexVec};
use rustc_middle::mir::coverage::*; use rustc_middle::mir::coverage::*;
use rustc_middle::mir::{self, BasicBlock, BasicBlockData, Terminator, TerminatorKind}; use rustc_middle::mir::{self, BasicBlock, BasicBlockData, Terminator, TerminatorKind};
@ -176,10 +176,10 @@ impl CoverageGraph {
fn add_basic_coverage_block( fn add_basic_coverage_block(
bcbs: &mut IndexVec<BasicCoverageBlock, BasicCoverageBlockData>, bcbs: &mut IndexVec<BasicCoverageBlock, BasicCoverageBlockData>,
bb_to_bcb: &mut IndexVec<BasicBlock, Option<BasicCoverageBlock>>, bb_to_bcb: &mut IndexSlice<BasicBlock, Option<BasicCoverageBlock>>,
basic_blocks: Vec<BasicBlock>, basic_blocks: Vec<BasicBlock>,
) { ) {
let bcb = BasicCoverageBlock::from_usize(bcbs.len()); let bcb = bcbs.next_index();
for &bb in basic_blocks.iter() { for &bb in basic_blocks.iter() {
bb_to_bcb[bb] = Some(bcb); bb_to_bcb[bb] = Some(bcb);
} }

View file

@ -3,7 +3,7 @@
use crate::MirPass; use crate::MirPass;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_index::vec::IndexVec; use rustc_index::vec::IndexSlice;
use rustc_middle::mir::*; use rustc_middle::mir::*;
use rustc_middle::ty::{self, TyCtxt}; use rustc_middle::ty::{self, TyCtxt};
@ -42,7 +42,7 @@ struct SliceLenPatchInformation<'tcx> {
fn lower_slice_len_call<'tcx>( fn lower_slice_len_call<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
block: &mut BasicBlockData<'tcx>, block: &mut BasicBlockData<'tcx>,
local_decls: &IndexVec<Local, LocalDecl<'tcx>>, local_decls: &IndexSlice<Local, LocalDecl<'tcx>>,
slice_len_fn_item_def_id: DefId, slice_len_fn_item_def_id: DefId,
) { ) {
let mut patch_found: Option<SliceLenPatchInformation<'_>> = None; let mut patch_found: Option<SliceLenPatchInformation<'_>> = None;

View file

@ -29,7 +29,7 @@
use crate::MirPass; use crate::MirPass;
use rustc_data_structures::fx::{FxHashSet, FxIndexSet}; use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
use rustc_index::vec::{Idx, IndexVec}; use rustc_index::vec::{Idx, IndexSlice, IndexVec};
use rustc_middle::mir::coverage::*; use rustc_middle::mir::coverage::*;
use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Visitor};
use rustc_middle::mir::*; use rustc_middle::mir::*;
@ -67,7 +67,7 @@ impl<'tcx> MirPass<'tcx> for SimplifyCfg {
} }
pub struct CfgSimplifier<'a, 'tcx> { pub struct CfgSimplifier<'a, 'tcx> {
basic_blocks: &'a mut IndexVec<BasicBlock, BasicBlockData<'tcx>>, basic_blocks: &'a mut IndexSlice<BasicBlock, BasicBlockData<'tcx>>,
pred_count: IndexVec<BasicBlock, u32>, pred_count: IndexVec<BasicBlock, u32>,
} }
@ -369,8 +369,8 @@ pub fn remove_dead_blocks<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
/// instances in a single body, so the strategy described above is applied to /// instances in a single body, so the strategy described above is applied to
/// coverage counters from each instance individually. /// coverage counters from each instance individually.
fn save_unreachable_coverage( fn save_unreachable_coverage(
basic_blocks: &mut IndexVec<BasicBlock, BasicBlockData<'_>>, basic_blocks: &mut IndexSlice<BasicBlock, BasicBlockData<'_>>,
source_scopes: &IndexVec<SourceScope, SourceScopeData<'_>>, source_scopes: &IndexSlice<SourceScope, SourceScopeData<'_>>,
first_dead_block: usize, first_dead_block: usize,
) { ) {
// Identify instances that still have some live coverage counters left. // Identify instances that still have some live coverage counters left.
@ -489,7 +489,7 @@ fn make_local_map<V>(
local_decls: &mut IndexVec<Local, V>, local_decls: &mut IndexVec<Local, V>,
used_locals: &UsedLocals, used_locals: &UsedLocals,
) -> IndexVec<Local, Option<Local>> { ) -> IndexVec<Local, Option<Local>> {
let mut map: IndexVec<Local, Option<Local>> = IndexVec::from_elem(None, &*local_decls); let mut map: IndexVec<Local, Option<Local>> = IndexVec::from_elem(None, local_decls);
let mut used = Local::new(0); let mut used = Local::new(0);
for alive_index in local_decls.indices() { for alive_index in local_decls.indices() {

View file

@ -1,7 +1,7 @@
use either::Either; use either::Either;
use rustc_data_structures::graph::dominators::Dominators; use rustc_data_structures::graph::dominators::Dominators;
use rustc_index::bit_set::BitSet; use rustc_index::bit_set::BitSet;
use rustc_index::vec::IndexVec; use rustc_index::vec::{IndexSlice, IndexVec};
use rustc_middle::middle::resolve_bound_vars::Set1; use rustc_middle::middle::resolve_bound_vars::Set1;
use rustc_middle::mir::visit::*; use rustc_middle::mir::visit::*;
use rustc_middle::mir::*; use rustc_middle::mir::*;
@ -135,7 +135,7 @@ impl SsaLocals {
/// _d => _a // transitively through _c /// _d => _a // transitively through _c
/// ///
/// Exception: we do not see through the return place, as it cannot be substituted. /// Exception: we do not see through the return place, as it cannot be substituted.
pub fn copy_classes(&self) -> &IndexVec<Local, Local> { pub fn copy_classes(&self) -> &IndexSlice<Local, Local> {
&self.copy_classes &self.copy_classes
} }