diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-03-28 23:32:25 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-03-30 09:23:40 -0700 |
| commit | 4abb45552992da2c30df9626c1b522b3d10f789b (patch) | |
| tree | efe03363d6478ade62621d10126662fd1a6cd821 /compiler/rustc_const_eval | |
| parent | 10338571cfa7c2be0aeed309141ced91454d41e1 (diff) | |
| download | rust-4abb45552992da2c30df9626c1b522b3d10f789b.tar.gz rust-4abb45552992da2c30df9626c1b522b3d10f789b.zip | |
Update `ty::VariantDef` to use `IndexVec<FieldIdx, FieldDef>`
And while doing the updates for that, also uses `FieldIdx` in `ProjectionKind::Field` and `TypeckResults::field_indices`. There's more places that could use it (like `rustc_const_eval` and `LayoutS`), but I tried to keep this PR from exploding to *even more* places. Part 2/? of https://github.com/rust-lang/compiler-team/issues/606
Diffstat (limited to 'compiler/rustc_const_eval')
| -rw-r--r-- | compiler/rustc_const_eval/src/const_eval/valtrees.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/validity.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_const_eval/src/transform/validate.rs | 2 |
3 files changed, 10 insertions, 5 deletions
diff --git a/compiler/rustc_const_eval/src/const_eval/valtrees.rs b/compiler/rustc_const_eval/src/const_eval/valtrees.rs index 8e4454d7cec..4d54c01830b 100644 --- a/compiler/rustc_const_eval/src/const_eval/valtrees.rs +++ b/compiler/rustc_const_eval/src/const_eval/valtrees.rs @@ -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, FIRST_VARIANT}; +use rustc_target::abi::{Align, FieldIdx, VariantIdx, FIRST_VARIANT}; #[instrument(skip(ecx), level = "debug")] fn branches<'tcx>( @@ -412,6 +412,7 @@ fn valtree_into_mplace<'tcx>( let inner_ty = match ty.kind() { ty::Adt(def, substs) => { + let i = FieldIdx::from_usize(i); def.variant(FIRST_VARIANT).fields[i].ty(tcx, substs) } ty::Tuple(inner_tys) => inner_tys[i], diff --git a/compiler/rustc_const_eval/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs index f7881c50960..93b5273e1b1 100644 --- a/compiler/rustc_const_eval/src/interpret/validity.rs +++ b/compiler/rustc_const_eval/src/interpret/validity.rs @@ -16,7 +16,9 @@ use rustc_middle::mir::interpret::InterpError; use rustc_middle::ty; use rustc_middle::ty::layout::{LayoutOf, TyAndLayout}; use rustc_span::symbol::{sym, Symbol}; -use rustc_target::abi::{Abi, Scalar as ScalarAbi, Size, VariantIdx, Variants, WrappingRange}; +use rustc_target::abi::{ + Abi, FieldIdx, Scalar as ScalarAbi, Size, VariantIdx, Variants, WrappingRange, +}; use std::hash::Hash; @@ -269,14 +271,16 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, ' match layout.variants { Variants::Single { index } => { // Inside a variant - PathElem::Field(def.variant(index).fields[field].name) + PathElem::Field(def.variant(index).fields[FieldIdx::from_usize(field)].name) } Variants::Multiple { .. } => bug!("we handled variants above"), } } // other ADTs - ty::Adt(def, _) => PathElem::Field(def.non_enum_variant().fields[field].name), + ty::Adt(def, _) => { + PathElem::Field(def.non_enum_variant().fields[FieldIdx::from_usize(field)].name) + } // arrays/slices ty::Array(..) | ty::Slice(..) => PathElem::ArrayElem(field), diff --git a/compiler/rustc_const_eval/src/transform/validate.rs b/compiler/rustc_const_eval/src/transform/validate.rs index 2be385d551e..cd5c92f7342 100644 --- a/compiler/rustc_const_eval/src/transform/validate.rs +++ b/compiler/rustc_const_eval/src/transform/validate.rs @@ -360,7 +360,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { } ty::Adt(adt_def, substs) => { let var = parent_ty.variant_index.unwrap_or(FIRST_VARIANT); - let Some(field) = adt_def.variant(var).fields.get(f.as_usize()) else { + let Some(field) = adt_def.variant(var).fields.get(f) else { fail_out_of_bounds(self, location); return; }; |
