Skip to content

Commit eb3e9c1

Browse files
committedMar 31, 2023
Auto merge of #109762 - scottmcm:variantdef-indexvec, r=WaffleLapkin
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 rust-lang/compiler-team#606
2 parents 276029d + 4abb455 commit eb3e9c1

File tree

47 files changed

+127
-104
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+127
-104
lines changed
 

‎compiler/rustc_borrowck/src/diagnostics/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
350350
if !including_tuple_field.0 && variant.ctor_kind() == Some(CtorKind::Fn) {
351351
return None;
352352
}
353-
Some(variant.fields[field.index()].name.to_string())
353+
Some(variant.fields[field].name.to_string())
354354
}
355355
ty::Tuple(_) => Some(field.index().to_string()),
356356
ty::Ref(_, ty, _) | ty::RawPtr(ty::TypeAndMut { ty, .. }) => {

‎compiler/rustc_borrowck/src/type_check/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
854854
},
855855
};
856856

857-
if let Some(field) = variant.fields.get(field.index()) {
857+
if let Some(field) = variant.fields.get(field) {
858858
Ok(self.cx.normalize(field.ty(tcx, substs), location))
859859
} else {
860860
Err(FieldAccessError::OutOfRange { field_count: variant.fields.len() })
@@ -1725,7 +1725,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
17251725
AggregateKind::Adt(adt_did, variant_index, substs, _, active_field_index) => {
17261726
let def = tcx.adt_def(adt_did);
17271727
let variant = &def.variant(variant_index);
1728-
let adj_field_index = active_field_index.unwrap_or(field_index);
1728+
let adj_field_index =
1729+
FieldIdx::from_usize(active_field_index.unwrap_or(field_index));
17291730
if let Some(field) = variant.fields.get(adj_field_index) {
17301731
Ok(self.normalize(field.ty(tcx, substs), location))
17311732
} else {

0 commit comments

Comments
 (0)
Please sign in to comment.