Move mir::Field
→ abi::FieldIdx
The first PR for https://github.com/rust-lang/compiler-team/issues/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.
This commit is contained in:
parent
acd27bb557
commit
5bbaeadc01
46 changed files with 192 additions and 157 deletions
|
@ -3,7 +3,7 @@ use rustc_middle::mir::tcx::PlaceTy;
|
|||
use rustc_middle::ty::cast::mir_cast_kind;
|
||||
use rustc_middle::{mir::*, thir::*, ty};
|
||||
use rustc_span::Span;
|
||||
use rustc_target::abi::VariantIdx;
|
||||
use rustc_target::abi::{FieldIdx, VariantIdx};
|
||||
|
||||
use crate::build::custom::ParseError;
|
||||
use crate::build::expr::as_constant::as_constant_inner;
|
||||
|
@ -223,7 +223,7 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
|
|||
let (parent, proj) = parse_by_kind!(self, expr_id, expr, "place",
|
||||
@call("mir_field", args) => {
|
||||
let (parent, ty) = self.parse_place_inner(args[0])?;
|
||||
let field = Field::from_u32(self.parse_integer_literal(args[1])? as u32);
|
||||
let field = FieldIdx::from_u32(self.parse_integer_literal(args[1])? as u32);
|
||||
let field_ty = ty.field_ty(self.tcx, field);
|
||||
let proj = PlaceElem::Field(field, field_ty);
|
||||
let place = parent.project_deeper(&[proj], self.tcx);
|
||||
|
|
|
@ -13,7 +13,7 @@ use rustc_middle::thir::*;
|
|||
use rustc_middle::ty::AdtDef;
|
||||
use rustc_middle::ty::{self, CanonicalUserTypeAnnotation, Ty, Variance};
|
||||
use rustc_span::Span;
|
||||
use rustc_target::abi::{VariantIdx, FIRST_VARIANT};
|
||||
use rustc_target::abi::{FieldIdx, VariantIdx, FIRST_VARIANT};
|
||||
|
||||
use std::assert_matches::assert_matches;
|
||||
use std::iter;
|
||||
|
@ -293,7 +293,7 @@ impl<'tcx> PlaceBuilder<'tcx> {
|
|||
&self.projection
|
||||
}
|
||||
|
||||
pub(crate) fn field(self, f: Field, ty: Ty<'tcx>) -> Self {
|
||||
pub(crate) fn field(self, f: FieldIdx, ty: Ty<'tcx>) -> Self {
|
||||
self.project(PlaceElem::Field(f, ty))
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ use rustc_middle::thir::*;
|
|||
use rustc_middle::ty::cast::{mir_cast_kind, CastTy};
|
||||
use rustc_middle::ty::{self, Ty, UpvarSubsts};
|
||||
use rustc_span::Span;
|
||||
use rustc_target::abi::FieldIdx;
|
||||
|
||||
impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
/// Returns an rvalue suitable for use until the end of the current
|
||||
|
@ -553,8 +554,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
result_value,
|
||||
Rvalue::CheckedBinaryOp(op, Box::new((lhs.to_copy(), rhs.to_copy()))),
|
||||
);
|
||||
let val_fld = Field::new(0);
|
||||
let of_fld = Field::new(1);
|
||||
let val_fld = FieldIdx::new(0);
|
||||
let of_fld = FieldIdx::new(1);
|
||||
|
||||
let tcx = self.tcx;
|
||||
let val = tcx.mk_place_field(result_value, val_fld, ty);
|
||||
|
|
|
@ -10,6 +10,7 @@ use rustc_index::vec::Idx;
|
|||
use rustc_middle::mir::*;
|
||||
use rustc_middle::thir::*;
|
||||
use rustc_middle::ty::CanonicalUserTypeAnnotation;
|
||||
use rustc_target::abi::FieldIdx;
|
||||
use std::iter;
|
||||
|
||||
impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
|
@ -344,7 +345,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
.collect();
|
||||
|
||||
let field_names: Vec<_> =
|
||||
(0..adt_def.variant(variant_index).fields.len()).map(Field::new).collect();
|
||||
(0..adt_def.variant(variant_index).fields.len()).map(FieldIdx::new).collect();
|
||||
|
||||
let fields: Vec<_> = if let Some(FruInfo { base, field_types }) = base {
|
||||
let place_builder =
|
||||
|
|
|
@ -25,6 +25,7 @@ use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
|
|||
use rustc_span::symbol::sym;
|
||||
use rustc_span::Span;
|
||||
use rustc_span::Symbol;
|
||||
use rustc_target::abi::FieldIdx;
|
||||
use rustc_target::spec::abi::Abi;
|
||||
|
||||
use super::lints;
|
||||
|
@ -793,7 +794,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
let mutability = captured_place.mutability;
|
||||
|
||||
let mut projs = closure_env_projs.clone();
|
||||
projs.push(ProjectionElem::Field(Field::new(i), ty));
|
||||
projs.push(ProjectionElem::Field(FieldIdx::new(i), ty));
|
||||
match capture {
|
||||
ty::UpvarCapture::ByValue => {}
|
||||
ty::UpvarCapture::ByRef(..) => {
|
||||
|
|
|
@ -10,7 +10,7 @@ use rustc_middle::hir::place::Place as HirPlace;
|
|||
use rustc_middle::hir::place::PlaceBase as HirPlaceBase;
|
||||
use rustc_middle::hir::place::ProjectionKind as HirProjectionKind;
|
||||
use rustc_middle::middle::region;
|
||||
use rustc_middle::mir::{self, BinOp, BorrowKind, Field, UnOp};
|
||||
use rustc_middle::mir::{self, BinOp, BorrowKind, UnOp};
|
||||
use rustc_middle::thir::*;
|
||||
use rustc_middle::ty::adjustment::{
|
||||
Adjust, Adjustment, AutoBorrow, AutoBorrowMutability, PointerCast,
|
||||
|
@ -20,7 +20,7 @@ use rustc_middle::ty::{
|
|||
self, AdtKind, InlineConstSubsts, InlineConstSubstsParts, ScalarInt, Ty, UpvarSubsts, UserType,
|
||||
};
|
||||
use rustc_span::{sym, Span};
|
||||
use rustc_target::abi::FIRST_VARIANT;
|
||||
use rustc_target::abi::{FieldIdx, FIRST_VARIANT};
|
||||
|
||||
impl<'tcx> Cx<'tcx> {
|
||||
pub(crate) fn mirror_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) -> ExprId {
|
||||
|
@ -379,7 +379,7 @@ impl<'tcx> Cx<'tcx> {
|
|||
.iter()
|
||||
.enumerate()
|
||||
.map(|(idx, e)| FieldExpr {
|
||||
name: Field::new(idx),
|
||||
name: FieldIdx::new(idx),
|
||||
expr: self.mirror_expr(e),
|
||||
})
|
||||
.collect();
|
||||
|
@ -733,7 +733,7 @@ impl<'tcx> Cx<'tcx> {
|
|||
hir::ExprKind::Field(ref source, ..) => ExprKind::Field {
|
||||
lhs: self.mirror_expr(source),
|
||||
variant_index: FIRST_VARIANT,
|
||||
name: Field::new(self.typeck_results.field_index(expr.hir_id)),
|
||||
name: FieldIdx::new(self.typeck_results.field_index(expr.hir_id)),
|
||||
},
|
||||
hir::ExprKind::Cast(ref source, ref cast_ty) => {
|
||||
// Check for a user-given type annotation on this `cast`
|
||||
|
@ -1053,7 +1053,7 @@ impl<'tcx> Cx<'tcx> {
|
|||
HirProjectionKind::Field(field, variant_index) => ExprKind::Field {
|
||||
lhs: self.thir.exprs.push(captured_place_expr),
|
||||
variant_index,
|
||||
name: Field::new(field as usize),
|
||||
name: FieldIdx::new(field as usize),
|
||||
},
|
||||
HirProjectionKind::Index | HirProjectionKind::Subslice => {
|
||||
// We don't capture these projections, so we can ignore them here
|
||||
|
@ -1107,7 +1107,7 @@ impl<'tcx> Cx<'tcx> {
|
|||
fields
|
||||
.iter()
|
||||
.map(|field| FieldExpr {
|
||||
name: Field::new(self.typeck_results.field_index(field.hir_id)),
|
||||
name: FieldIdx::new(self.typeck_results.field_index(field.hir_id)),
|
||||
expr: self.mirror_expr(field.expr),
|
||||
})
|
||||
.collect()
|
||||
|
|
|
@ -2,11 +2,12 @@ use rustc_hir as hir;
|
|||
use rustc_index::vec::Idx;
|
||||
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
|
||||
use rustc_infer::traits::Obligation;
|
||||
use rustc_middle::mir::{self, Field};
|
||||
use rustc_middle::mir;
|
||||
use rustc_middle::thir::{FieldPat, Pat, PatKind};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_session::lint;
|
||||
use rustc_span::Span;
|
||||
use rustc_target::abi::FieldIdx;
|
||||
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
|
||||
use rustc_trait_selection::traits::{self, ObligationCause};
|
||||
|
||||
|
@ -218,7 +219,7 @@ impl<'tcx> ConstToPat<'tcx> {
|
|||
) -> Result<Vec<FieldPat<'tcx>>, FallbackToConstRef> {
|
||||
vals.enumerate()
|
||||
.map(|(idx, val)| {
|
||||
let field = Field::new(idx);
|
||||
let field = FieldIdx::new(idx);
|
||||
Ok(FieldPat { field, pattern: self.recur(val, false)? })
|
||||
})
|
||||
.collect()
|
||||
|
|
|
@ -53,14 +53,14 @@ use smallvec::{smallvec, SmallVec};
|
|||
use rustc_data_structures::captures::Captures;
|
||||
use rustc_hir::{HirId, RangeEnd};
|
||||
use rustc_index::vec::Idx;
|
||||
use rustc_middle::mir::{self, Field};
|
||||
use rustc_middle::mir;
|
||||
use rustc_middle::thir::{FieldPat, Pat, PatKind, PatRange};
|
||||
use rustc_middle::ty::layout::IntegerExt;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, VariantDef};
|
||||
use rustc_middle::{middle::stability::EvalResult, mir::interpret::ConstValue};
|
||||
use rustc_session::lint;
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_target::abi::{Integer, Size, VariantIdx, FIRST_VARIANT};
|
||||
use rustc_target::abi::{FieldIdx, Integer, Size, VariantIdx, FIRST_VARIANT};
|
||||
|
||||
use self::Constructor::*;
|
||||
use self::SliceKind::*;
|
||||
|
@ -1126,7 +1126,7 @@ impl<'tcx> SplitWildcard<'tcx> {
|
|||
/// Note that the number of fields of a constructor may not match the fields declared in the
|
||||
/// original struct/variant. This happens if a private or `non_exhaustive` field is uninhabited,
|
||||
/// because the code mustn't observe that it is uninhabited. In that case that field is not
|
||||
/// included in `fields`. For that reason, when you have a `mir::Field` you must use
|
||||
/// included in `fields`. For that reason, when you have a `FieldIdx` you must use
|
||||
/// `index_with_declared_idx`.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub(super) struct Fields<'p, 'tcx> {
|
||||
|
@ -1165,7 +1165,7 @@ impl<'p, 'tcx> Fields<'p, 'tcx> {
|
|||
cx: &'a MatchCheckCtxt<'p, 'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
variant: &'a VariantDef,
|
||||
) -> impl Iterator<Item = (Field, Ty<'tcx>)> + Captures<'a> + Captures<'p> {
|
||||
) -> impl Iterator<Item = (FieldIdx, Ty<'tcx>)> + Captures<'a> + Captures<'p> {
|
||||
let ty::Adt(adt, substs) = ty.kind() else { bug!() };
|
||||
// Whether we must not match the fields of this variant exhaustively.
|
||||
let is_non_exhaustive = variant.is_field_list_non_exhaustive() && !adt.did().is_local();
|
||||
|
@ -1180,7 +1180,7 @@ impl<'p, 'tcx> Fields<'p, 'tcx> {
|
|||
if is_uninhabited && (!is_visible || is_non_exhaustive) {
|
||||
None
|
||||
} else {
|
||||
Some((Field::new(i), ty))
|
||||
Some((FieldIdx::new(i), ty))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -1438,7 +1438,7 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
|
|||
ty::Tuple(..) => PatKind::Leaf {
|
||||
subpatterns: subpatterns
|
||||
.enumerate()
|
||||
.map(|(i, pattern)| FieldPat { field: Field::new(i), pattern })
|
||||
.map(|(i, pattern)| FieldPat { field: FieldIdx::new(i), pattern })
|
||||
.collect(),
|
||||
},
|
||||
ty::Adt(adt_def, _) if adt_def.is_box() => {
|
||||
|
|
|
@ -21,12 +21,13 @@ use rustc_middle::mir::interpret::{
|
|||
ConstValue, ErrorHandled, LitToConstError, LitToConstInput, Scalar,
|
||||
};
|
||||
use rustc_middle::mir::{self, UserTypeProjection};
|
||||
use rustc_middle::mir::{BorrowKind, Field, Mutability};
|
||||
use rustc_middle::mir::{BorrowKind, Mutability};
|
||||
use rustc_middle::thir::{Ascription, BindingMode, FieldPat, LocalVarId, Pat, PatKind, PatRange};
|
||||
use rustc_middle::ty::subst::{GenericArg, SubstsRef};
|
||||
use rustc_middle::ty::CanonicalUserTypeAnnotation;
|
||||
use rustc_middle::ty::{self, AdtDef, ConstKind, Region, Ty, TyCtxt, UserType};
|
||||
use rustc_span::{Span, Symbol};
|
||||
use rustc_target::abi::FieldIdx;
|
||||
|
||||
use std::cmp::Ordering;
|
||||
|
||||
|
@ -356,7 +357,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
|||
let subpatterns = fields
|
||||
.iter()
|
||||
.map(|field| FieldPat {
|
||||
field: Field::new(self.typeck_results.field_index(field.hir_id)),
|
||||
field: FieldIdx::new(self.typeck_results.field_index(field.hir_id)),
|
||||
pattern: self.lower_pattern(&field.pat),
|
||||
})
|
||||
.collect();
|
||||
|
@ -379,7 +380,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
|||
pats.iter()
|
||||
.enumerate_and_adjust(expected_len, gap_pos)
|
||||
.map(|(i, subpattern)| FieldPat {
|
||||
field: Field::new(i),
|
||||
field: FieldIdx::new(i),
|
||||
pattern: self.lower_pattern(subpattern),
|
||||
})
|
||||
.collect()
|
||||
|
@ -723,7 +724,7 @@ macro_rules! ClonePatternFoldableImpls {
|
|||
}
|
||||
|
||||
ClonePatternFoldableImpls! { <'tcx>
|
||||
Span, Field, Mutability, Symbol, LocalVarId, usize,
|
||||
Span, FieldIdx, Mutability, Symbol, LocalVarId, usize,
|
||||
Region<'tcx>, Ty<'tcx>, BindingMode, AdtDef<'tcx>,
|
||||
SubstsRef<'tcx>, &'tcx GenericArg<'tcx>, UserType<'tcx>,
|
||||
UserTypeProjection, CanonicalUserTypeAnnotation<'tcx>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue