Refactor: VariantIdx::from_u32(0)
-> FIRST_VARIANT
Since structs are always `VariantIdx(0)`, there's a bunch of files where the only reason they had `VariantIdx` or `vec::Idx` imported at all was to get the first variant. So this uses a constant for that, and adds some doc-comments to `VariantIdx` while I'm there, since it doesn't have any today.
This commit is contained in:
parent
96bd50dd47
commit
0439d13176
25 changed files with 80 additions and 78 deletions
|
@ -8,7 +8,7 @@ use crate::interpret::{
|
|||
use crate::interpret::{MPlaceTy, Value};
|
||||
use rustc_middle::ty::{self, ScalarInt, Ty, TyCtxt};
|
||||
use rustc_span::source_map::DUMMY_SP;
|
||||
use rustc_target::abi::{Align, VariantIdx};
|
||||
use rustc_target::abi::{Align, VariantIdx, FIRST_VARIANT};
|
||||
|
||||
#[instrument(skip(ecx), level = "debug")]
|
||||
fn branches<'tcx>(
|
||||
|
@ -412,7 +412,7 @@ fn valtree_into_mplace<'tcx>(
|
|||
|
||||
let inner_ty = match ty.kind() {
|
||||
ty::Adt(def, substs) => {
|
||||
def.variant(VariantIdx::from_u32(0)).fields[i].ty(tcx, substs)
|
||||
def.variant(FIRST_VARIANT).fields[i].ty(tcx, substs)
|
||||
}
|
||||
ty::Tuple(inner_tys) => inner_tys[i],
|
||||
_ => bug!("unexpected unsized type {:?}", ty),
|
||||
|
|
|
@ -8,7 +8,7 @@ use rustc_ast::Mutability;
|
|||
use rustc_middle::mir;
|
||||
use rustc_middle::ty;
|
||||
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
|
||||
use rustc_target::abi::{self, Abi, Align, HasDataLayout, Size, VariantIdx};
|
||||
use rustc_target::abi::{self, Abi, Align, HasDataLayout, Size, FIRST_VARIANT};
|
||||
|
||||
use super::{
|
||||
alloc_range, mir_assign_valid_types, AllocId, AllocRef, AllocRefMut, CheckInAllocMsg,
|
||||
|
@ -796,7 +796,7 @@ where
|
|||
let variant_dest = self.place_downcast(&dest, variant_index)?;
|
||||
(variant_index, variant_dest, active_field_index)
|
||||
}
|
||||
_ => (VariantIdx::from_u32(0), dest.clone(), None),
|
||||
_ => (FIRST_VARIANT, dest.clone(), None),
|
||||
};
|
||||
if active_field_index.is_some() {
|
||||
assert_eq!(operands.len(), 1);
|
||||
|
|
|
@ -17,7 +17,7 @@ use rustc_middle::ty::{self, InstanceDef, ParamEnv, Ty, TyCtxt, TypeVisitableExt
|
|||
use rustc_mir_dataflow::impls::MaybeStorageLive;
|
||||
use rustc_mir_dataflow::storage::always_storage_live_locals;
|
||||
use rustc_mir_dataflow::{Analysis, ResultsCursor};
|
||||
use rustc_target::abi::{Size, VariantIdx};
|
||||
use rustc_target::abi::{Size, FIRST_VARIANT};
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
enum EdgeKind {
|
||||
|
@ -359,7 +359,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
|
|||
check_equal(self, location, *f_ty);
|
||||
}
|
||||
ty::Adt(adt_def, substs) => {
|
||||
let var = parent_ty.variant_index.unwrap_or(VariantIdx::from_u32(0));
|
||||
let var = parent_ty.variant_index.unwrap_or(FIRST_VARIANT);
|
||||
let Some(field) = adt_def.variant(var).fields.get(f.as_usize()) else {
|
||||
fail_out_of_bounds(self, location);
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue