Skip to content

Commit 5bbaead

Browse files
committedMar 29, 2023
Move mir::Fieldabi::FieldIdx
The first PR for rust-lang/compiler-team#606 This is just the move-and-rename, because it's plenty big-and-bitrotty already. Future PRs will start using `FieldIdx` more broadly, and concomitantly removing `FieldIdx::new`s.
1 parent acd27bb commit 5bbaead

File tree

46 files changed

+192
-157
lines changed

Some content is hidden

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

46 files changed

+192
-157
lines changed
 

‎compiler/rustc_abi/src/lib.rs

+26
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,32 @@ impl Scalar {
10571057
}
10581058
}
10591059

1060+
rustc_index::newtype_index! {
1061+
/// The *source-order* index of a field in a variant.
1062+
///
1063+
/// This is how most code after type checking refers to fields, rather than
1064+
/// using names (as names have hygiene complications and more complex lookup).
1065+
///
1066+
/// Particularly for `repr(Rust)` types, this may not be the same as *layout* order.
1067+
/// (It is for `repr(C)` `struct`s, however.)
1068+
///
1069+
/// For example, in the following types,
1070+
/// ```rust
1071+
/// # enum Never {}
1072+
/// # #[repr(u16)]
1073+
/// enum Demo1 {
1074+
/// Variant0 { a: Never, b: i32 } = 100,
1075+
/// Variant1 { c: u8, d: u64 } = 10,
1076+
/// }
1077+
/// struct Demo2 { e: u8, f: u16, g: u8 }
1078+
/// ```
1079+
/// `b` is `FieldIdx(1)` in `VariantIdx(0)`,
1080+
/// `d` is `FieldIdx(1)` in `VariantIdx(1)`, and
1081+
/// `f` is `FieldIdx(1)` in `VariantIdx(0)`.
1082+
#[derive(HashStable_Generic)]
1083+
pub struct FieldIdx {}
1084+
}
1085+
10601086
/// Describes how the fields of a type are located in memory.
10611087
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
10621088
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ use rustc_hir::GeneratorKind;
99
use rustc_infer::infer::{LateBoundRegionConversionTime, TyCtxtInferExt};
1010
use rustc_middle::mir::tcx::PlaceTy;
1111
use rustc_middle::mir::{
12-
AggregateKind, Constant, FakeReadCause, Field, Local, LocalInfo, LocalKind, Location, Operand,
13-
Place, PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind,
12+
AggregateKind, Constant, FakeReadCause, Local, LocalInfo, LocalKind, Location, Operand, Place,
13+
PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind,
1414
};
1515
use rustc_middle::ty::print::Print;
1616
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
1717
use rustc_mir_dataflow::move_paths::{InitLocation, LookupResult};
1818
use rustc_span::def_id::LocalDefId;
1919
use rustc_span::{symbol::sym, Span, Symbol, DUMMY_SP};
20-
use rustc_target::abi::VariantIdx;
20+
use rustc_target::abi::{FieldIdx, VariantIdx};
2121
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
2222
use rustc_trait_selection::traits::{
2323
type_known_to_meet_bound_modulo_regions, Obligation, ObligationCause,
@@ -302,7 +302,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
302302
fn describe_field(
303303
&self,
304304
place: PlaceRef<'tcx>,
305-
field: Field,
305+
field: FieldIdx,
306306
including_tuple_field: IncludingTupleField,
307307
) -> Option<String> {
308308
let place_ty = match place {
@@ -331,7 +331,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
331331
fn describe_field_from_ty(
332332
&self,
333333
ty: Ty<'_>,
334-
field: Field,
334+
field: FieldIdx,
335335
variant_index: Option<VariantIdx>,
336336
including_tuple_field: IncludingTupleField,
337337
) -> Option<String> {

0 commit comments

Comments
 (0)