Rollup merge of #123419 - petrochenkov:zeroindex, r=compiler-errors
rustc_index: Add a `ZERO` constant to index types It is commonly used.
This commit is contained in:
commit
25b0e84170
42 changed files with 80 additions and 90 deletions
|
@ -168,7 +168,7 @@ impl<'tcx> MutVisitor<'tcx> for PinArgVisitor<'tcx> {
|
|||
Place {
|
||||
local: SELF_ARG,
|
||||
projection: self.tcx().mk_place_elems(&[ProjectionElem::Field(
|
||||
FieldIdx::new(0),
|
||||
FieldIdx::ZERO,
|
||||
self.ref_coroutine_ty,
|
||||
)]),
|
||||
},
|
||||
|
@ -267,7 +267,7 @@ impl<'tcx> TransformVisitor<'tcx> {
|
|||
Rvalue::Aggregate(
|
||||
Box::new(AggregateKind::Adt(
|
||||
option_def_id,
|
||||
VariantIdx::from_usize(0),
|
||||
VariantIdx::ZERO,
|
||||
self.tcx.mk_args(&[self.old_yield_ty.into()]),
|
||||
None,
|
||||
None,
|
||||
|
@ -329,7 +329,7 @@ impl<'tcx> TransformVisitor<'tcx> {
|
|||
Rvalue::Aggregate(
|
||||
Box::new(AggregateKind::Adt(
|
||||
poll_def_id,
|
||||
VariantIdx::from_usize(0),
|
||||
VariantIdx::ZERO,
|
||||
args,
|
||||
None,
|
||||
None,
|
||||
|
@ -358,7 +358,7 @@ impl<'tcx> TransformVisitor<'tcx> {
|
|||
Rvalue::Aggregate(
|
||||
Box::new(AggregateKind::Adt(
|
||||
option_def_id,
|
||||
VariantIdx::from_usize(0),
|
||||
VariantIdx::ZERO,
|
||||
args,
|
||||
None,
|
||||
None,
|
||||
|
@ -420,7 +420,7 @@ impl<'tcx> TransformVisitor<'tcx> {
|
|||
Rvalue::Aggregate(
|
||||
Box::new(AggregateKind::Adt(
|
||||
coroutine_state_def_id,
|
||||
VariantIdx::from_usize(0),
|
||||
VariantIdx::ZERO,
|
||||
args,
|
||||
None,
|
||||
None,
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
//! Box is not actually a pointer so it is incorrect to dereference it directly.
|
||||
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_index::Idx;
|
||||
use rustc_middle::mir::patch::MirPatch;
|
||||
use rustc_middle::mir::visit::MutVisitor;
|
||||
use rustc_middle::mir::*;
|
||||
|
@ -32,9 +31,9 @@ pub fn build_projection<'tcx>(
|
|||
ptr_ty: Ty<'tcx>,
|
||||
) -> [PlaceElem<'tcx>; 3] {
|
||||
[
|
||||
PlaceElem::Field(FieldIdx::new(0), unique_ty),
|
||||
PlaceElem::Field(FieldIdx::new(0), nonnull_ty),
|
||||
PlaceElem::Field(FieldIdx::new(0), ptr_ty),
|
||||
PlaceElem::Field(FieldIdx::ZERO, unique_ty),
|
||||
PlaceElem::Field(FieldIdx::ZERO, nonnull_ty),
|
||||
PlaceElem::Field(FieldIdx::ZERO, ptr_ty),
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -91,15 +90,14 @@ pub struct ElaborateBoxDerefs;
|
|||
impl<'tcx> MirPass<'tcx> for ElaborateBoxDerefs {
|
||||
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||
if let Some(def_id) = tcx.lang_items().owned_box() {
|
||||
let unique_did =
|
||||
tcx.adt_def(def_id).non_enum_variant().fields[FieldIdx::from_u32(0)].did;
|
||||
let unique_did = tcx.adt_def(def_id).non_enum_variant().fields[FieldIdx::ZERO].did;
|
||||
|
||||
let Some(nonnull_def) = tcx.type_of(unique_did).instantiate_identity().ty_adt_def()
|
||||
else {
|
||||
span_bug!(tcx.def_span(unique_did), "expected Box to contain Unique")
|
||||
};
|
||||
|
||||
let nonnull_did = nonnull_def.non_enum_variant().fields[FieldIdx::from_u32(0)].did;
|
||||
let nonnull_did = nonnull_def.non_enum_variant().fields[FieldIdx::ZERO].did;
|
||||
|
||||
let patch = MirPatch::new(body);
|
||||
|
||||
|
|
|
@ -355,7 +355,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
|
|||
}
|
||||
|
||||
fn insert_tuple(&mut self, values: Vec<VnIndex>) -> VnIndex {
|
||||
self.insert(Value::Aggregate(AggregateTy::Tuple, VariantIdx::from_u32(0), values))
|
||||
self.insert(Value::Aggregate(AggregateTy::Tuple, VariantIdx::ZERO, values))
|
||||
}
|
||||
|
||||
#[instrument(level = "trace", skip(self), ret)]
|
||||
|
|
|
@ -13,7 +13,7 @@ use rustc_const_eval::interpret::{
|
|||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::HirId;
|
||||
use rustc_index::{bit_set::BitSet, Idx, IndexVec};
|
||||
use rustc_index::{bit_set::BitSet, IndexVec};
|
||||
use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor};
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::layout::{LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout};
|
||||
|
@ -124,10 +124,8 @@ impl<'tcx> Value<'tcx> {
|
|||
fields.ensure_contains_elem(*idx, || Value::Uninit)
|
||||
}
|
||||
(PlaceElem::Field(..), val @ Value::Uninit) => {
|
||||
*val = Value::Aggregate {
|
||||
variant: VariantIdx::new(0),
|
||||
fields: Default::default(),
|
||||
};
|
||||
*val =
|
||||
Value::Aggregate { variant: VariantIdx::ZERO, fields: Default::default() };
|
||||
val.project_mut(&[*proj])?
|
||||
}
|
||||
_ => return None,
|
||||
|
@ -572,7 +570,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
|||
self.use_ecx(|this| this.ecx.overflowing_binary_op(bin_op, &left, &right))?;
|
||||
let overflowed = ImmTy::from_bool(overflowed, self.tcx);
|
||||
Value::Aggregate {
|
||||
variant: VariantIdx::new(0),
|
||||
variant: VariantIdx::ZERO,
|
||||
fields: [Value::from(val), overflowed.into()].into_iter().collect(),
|
||||
}
|
||||
}
|
||||
|
@ -607,7 +605,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
|||
| AggregateKind::Tuple
|
||||
| AggregateKind::Closure(_, _)
|
||||
| AggregateKind::Coroutine(_, _)
|
||||
| AggregateKind::CoroutineClosure(_, _) => VariantIdx::new(0),
|
||||
| AggregateKind::CoroutineClosure(_, _) => VariantIdx::ZERO,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -415,7 +415,7 @@ fn make_local_map<V>(
|
|||
used_locals: &UsedLocals,
|
||||
) -> IndexVec<Local, Option<Local>> {
|
||||
let mut map: IndexVec<Local, Option<Local>> = IndexVec::from_elem(None, local_decls);
|
||||
let mut used = Local::new(0);
|
||||
let mut used = Local::ZERO;
|
||||
|
||||
for alive_index in local_decls.indices() {
|
||||
// `is_used` treats the `RETURN_PLACE` and arguments as used.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue