| author | bors <bors@rust-lang.org> 2023-04-02 21:40:29 UTC |
| committer | bors <bors@rust-lang.org> 2023-04-02 21:40:29 UTC |
| log | a93bcdc30771340dfff914a1cf48556886ad33a6 |
| tree | af18945bacc5061e824a46c8dfa5dce862c9657b |
| parent | 3a8a131e9509c478ece1c58fe0ea2d49463d2300 |
| parent | b5b6def021d37c5f1cb7e06c1cf6915bcbcd53b1 |
Use `FieldIdx` in various things related to aggregates
Shrank `AggregateKind` by 8 bytes on x64, since the active field of a union is tracked as an `Option<FieldIdx>` instead of `Option<usize>`.
Part 3/? of https://github.com/rust-lang/compiler-team/issues/606
[`IndexSlice`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_index/vec/struct.IndexVec.html#deref-methods-IndexSlice%3CI,+T%3E) was added in https://github.com/rust-lang/rust/pull/10978713 files changed, 51 insertions(+), 46 deletions(-)
compiler/rustc_borrowck/src/diagnostics/mod.rs+3-2| ... | ... | @@ -6,6 +6,7 @@ use rustc_errors::{Applicability, Diagnostic}; |
| 6 | 6 | use rustc_hir as hir; |
| 7 | 7 | use rustc_hir::def::{CtorKind, Namespace}; |
| 8 | 8 | use rustc_hir::GeneratorKind; |
| 9 | use rustc_index::vec::IndexSlice; | |
| 9 | 10 | use rustc_infer::infer::{LateBoundRegionConversionTime, TyCtxtInferExt}; |
| 10 | 11 | use rustc_middle::mir::tcx::PlaceTy; |
| 11 | 12 | use rustc_middle::mir::{ |
| ... | ... | @@ -825,7 +826,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { |
| 825 | 826 | debug!("move_spans: def_id={:?} place={:?}", closure_def_id, place); |
| 826 | 827 | let places = &[Operand::Move(place)]; |
| 827 | 828 | if let Some((args_span, generator_kind, capture_kind_span, path_span)) = |
| 828 | self.closure_span(closure_def_id, moved_place, places) | |
| 829 | self.closure_span(closure_def_id, moved_place, IndexSlice::from_raw(places)) | |
| 829 | 830 | { |
| 830 | 831 | return ClosureUse { |
| 831 | 832 | generator_kind, |
| ... | ... | @@ -975,7 +976,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { |
| 975 | 976 | &self, |
| 976 | 977 | def_id: LocalDefId, |
| 977 | 978 | target_place: PlaceRef<'tcx>, |
| 978 | places: &[Operand<'tcx>], | |
| 979 | places: &IndexSlice<FieldIdx, Operand<'tcx>>, | |
| 979 | 980 | ) -> Option<(Span, Option<GeneratorKind>, Span, Span)> { |
| 980 | 981 | debug!( |
| 981 | 982 | "closure_span: def_id={:?} target_place={:?} places={:?}", |
compiler/rustc_borrowck/src/lib.rs+1-1| ... | ... | @@ -1343,7 +1343,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { |
| 1343 | 1343 | self.infcx.tcx.mir_borrowck(def_id); |
| 1344 | 1344 | debug!("{:?} used_mut_upvars={:?}", def_id, used_mut_upvars); |
| 1345 | 1345 | for field in used_mut_upvars { |
| 1346 | self.propagate_closure_used_mut_upvar(&operands[field.index()]); | |
| 1346 | self.propagate_closure_used_mut_upvar(&operands[*field]); | |
| 1347 | 1347 | } |
| 1348 | 1348 | } |
| 1349 | 1349 | AggregateKind::Adt(..) |
compiler/rustc_borrowck/src/type_check/mod.rs+9-10| ... | ... | @@ -14,7 +14,7 @@ use rustc_hir as hir; |
| 14 | 14 | use rustc_hir::def::DefKind; |
| 15 | 15 | use rustc_hir::def_id::LocalDefId; |
| 16 | 16 | use rustc_hir::lang_items::LangItem; |
| 17 | use rustc_index::vec::IndexVec; | |
| 17 | use rustc_index::vec::{IndexSlice, IndexVec}; | |
| 18 | 18 | use rustc_infer::infer::canonical::QueryRegionConstraints; |
| 19 | 19 | use rustc_infer::infer::outlives::env::RegionBoundPairs; |
| 20 | 20 | use rustc_infer::infer::region_constraints::RegionConstraintData; |
| ... | ... | @@ -1716,7 +1716,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { |
| 1716 | 1716 | fn aggregate_field_ty( |
| 1717 | 1717 | &mut self, |
| 1718 | 1718 | ak: &AggregateKind<'tcx>, |
| 1719 | field_index: usize, | |
| 1719 | field_index: FieldIdx, | |
| 1720 | 1720 | location: Location, |
| 1721 | 1721 | ) -> Result<Ty<'tcx>, FieldAccessError> { |
| 1722 | 1722 | let tcx = self.tcx(); |
| ... | ... | @@ -1725,8 +1725,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { |
| 1725 | 1725 | AggregateKind::Adt(adt_did, variant_index, substs, _, active_field_index) => { |
| 1726 | 1726 | let def = tcx.adt_def(adt_did); |
| 1727 | 1727 | let variant = &def.variant(variant_index); |
| 1728 | let adj_field_index = | |
| 1729 | FieldIdx::from_usize(active_field_index.unwrap_or(field_index)); | |
| 1728 | let adj_field_index = active_field_index.unwrap_or(field_index); | |
| 1730 | 1729 | if let Some(field) = variant.fields.get(adj_field_index) { |
| 1731 | 1730 | Ok(self.normalize(field.ty(tcx, substs), location)) |
| 1732 | 1731 | } else { |
| ... | ... | @@ -1734,7 +1733,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { |
| 1734 | 1733 | } |
| 1735 | 1734 | } |
| 1736 | 1735 | AggregateKind::Closure(_, substs) => { |
| 1737 | match substs.as_closure().upvar_tys().nth(field_index) { | |
| 1736 | match substs.as_closure().upvar_tys().nth(field_index.as_usize()) { | |
| 1738 | 1737 | Some(ty) => Ok(ty), |
| 1739 | 1738 | None => Err(FieldAccessError::OutOfRange { |
| 1740 | 1739 | field_count: substs.as_closure().upvar_tys().count(), |
| ... | ... | @@ -1745,7 +1744,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { |
| 1745 | 1744 | // It doesn't make sense to look at a field beyond the prefix; |
| 1746 | 1745 | // these require a variant index, and are not initialized in |
| 1747 | 1746 | // aggregate rvalues. |
| 1748 | match substs.as_generator().prefix_tys().nth(field_index) { | |
| 1747 | match substs.as_generator().prefix_tys().nth(field_index.as_usize()) { | |
| 1749 | 1748 | Some(ty) => Ok(ty), |
| 1750 | 1749 | None => Err(FieldAccessError::OutOfRange { |
| 1751 | 1750 | field_count: substs.as_generator().prefix_tys().count(), |
| ... | ... | @@ -2350,7 +2349,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { |
| 2350 | 2349 | body: &Body<'tcx>, |
| 2351 | 2350 | rvalue: &Rvalue<'tcx>, |
| 2352 | 2351 | aggregate_kind: &AggregateKind<'tcx>, |
| 2353 | operands: &[Operand<'tcx>], | |
| 2352 | operands: &IndexSlice<FieldIdx, Operand<'tcx>>, | |
| 2354 | 2353 | location: Location, |
| 2355 | 2354 | ) { |
| 2356 | 2355 | let tcx = self.tcx(); |
| ... | ... | @@ -2362,7 +2361,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { |
| 2362 | 2361 | return; |
| 2363 | 2362 | } |
| 2364 | 2363 | |
| 2365 | for (i, operand) in operands.iter().enumerate() { | |
| 2364 | for (i, operand) in operands.iter_enumerated() { | |
| 2366 | 2365 | let field_ty = match self.aggregate_field_ty(aggregate_kind, i, location) { |
| 2367 | 2366 | Ok(field_ty) => field_ty, |
| 2368 | 2367 | Err(FieldAccessError::OutOfRange { field_count }) => { |
| ... | ... | @@ -2370,8 +2369,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { |
| 2370 | 2369 | self, |
| 2371 | 2370 | rvalue, |
| 2372 | 2371 | "accessed field #{} but variant only has {}", |
| 2373 | i, | |
| 2374 | field_count | |
| 2372 | i.as_u32(), | |
| 2373 | field_count, | |
| 2375 | 2374 | ); |
| 2376 | 2375 | continue; |
| 2377 | 2376 | } |
compiler/rustc_codegen_cranelift/src/base.rs+4-3| ... | ... | @@ -802,14 +802,15 @@ fn codegen_stmt<'tcx>( |
| 802 | 802 | if active_field_index.is_some() { |
| 803 | 803 | assert_eq!(operands.len(), 1); |
| 804 | 804 | } |
| 805 | for (i, operand) in operands.iter().enumerate() { | |
| 805 | for (i, operand) in operands.iter_enumerated() { | |
| 806 | 806 | let operand = codegen_operand(fx, operand); |
| 807 | 807 | let field_index = active_field_index.unwrap_or(i); |
| 808 | 808 | let to = if let mir::AggregateKind::Array(_) = **kind { |
| 809 | let index = fx.bcx.ins().iconst(fx.pointer_type, field_index as i64); | |
| 809 | let array_index = i64::from(field_index.as_u32()); | |
| 810 | let index = fx.bcx.ins().iconst(fx.pointer_type, array_index); | |
| 810 | 811 | variant_dest.place_index(fx, index) |
| 811 | 812 | } else { |
| 812 | variant_dest.place_field(fx, FieldIdx::new(field_index)) | |
| 813 | variant_dest.place_field(fx, field_index) | |
| 813 | 814 | }; |
| 814 | 815 | to.write_cvalue(fx, operand); |
| 815 | 816 | } |
compiler/rustc_codegen_ssa/src/base.rs+3-3| ... | ... | @@ -306,9 +306,9 @@ pub fn coerce_unsized_into<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( |
| 306 | 306 | (&ty::Adt(def_a, _), &ty::Adt(def_b, _)) => { |
| 307 | 307 | assert_eq!(def_a, def_b); |
| 308 | 308 | |
| 309 | for i in 0..def_a.variant(FIRST_VARIANT).fields.len() { | |
| 310 | let src_f = src.project_field(bx, i); | |
| 311 | let dst_f = dst.project_field(bx, i); | |
| 309 | for i in def_a.variant(FIRST_VARIANT).fields.indices() { | |
| 310 | let src_f = src.project_field(bx, i.as_usize()); | |
| 311 | let dst_f = dst.project_field(bx, i.as_usize()); | |
| 312 | 312 | |
| 313 | 313 | if dst_f.layout.is_zst() { |
| 314 | 314 | continue; |
compiler/rustc_codegen_ssa/src/mir/rvalue.rs+3-3| ... | ... | @@ -123,16 +123,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { |
| 123 | 123 | if active_field_index.is_some() { |
| 124 | 124 | assert_eq!(operands.len(), 1); |
| 125 | 125 | } |
| 126 | for (i, operand) in operands.iter().enumerate() { | |
| 126 | for (i, operand) in operands.iter_enumerated() { | |
| 127 | 127 | let op = self.codegen_operand(bx, operand); |
| 128 | 128 | // Do not generate stores and GEPis for zero-sized fields. |
| 129 | 129 | if !op.layout.is_zst() { |
| 130 | 130 | let field_index = active_field_index.unwrap_or(i); |
| 131 | 131 | let field = if let mir::AggregateKind::Array(_) = **kind { |
| 132 | let llindex = bx.cx().const_usize(field_index as u64); | |
| 132 | let llindex = bx.cx().const_usize(field_index.as_u32().into()); | |
| 133 | 133 | variant_dest.project_index(bx, llindex) |
| 134 | 134 | } else { |
| 135 | variant_dest.project_field(bx, field_index) | |
| 135 | variant_dest.project_field(bx, field_index.as_usize()) | |
| 136 | 136 | }; |
| 137 | 137 | op.val.store(bx, field); |
| 138 | 138 | } |
compiler/rustc_const_eval/src/interpret/place.rs+5-4| ... | ... | @@ -5,10 +5,11 @@ |
| 5 | 5 | use either::{Either, Left, Right}; |
| 6 | 6 | |
| 7 | 7 | use rustc_ast::Mutability; |
| 8 | use rustc_index::vec::IndexSlice; | |
| 8 | 9 | use rustc_middle::mir; |
| 9 | 10 | use rustc_middle::ty; |
| 10 | 11 | use rustc_middle::ty::layout::{LayoutOf, TyAndLayout}; |
| 11 | use rustc_target::abi::{self, Abi, Align, HasDataLayout, Size, FIRST_VARIANT}; | |
| 12 | use rustc_target::abi::{self, Abi, Align, FieldIdx, HasDataLayout, Size, FIRST_VARIANT}; | |
| 12 | 13 | |
| 13 | 14 | use super::{ |
| 14 | 15 | alloc_range, mir_assign_valid_types, AllocId, AllocRef, AllocRefMut, CheckInAllocMsg, |
| ... | ... | @@ -787,7 +788,7 @@ where |
| 787 | 788 | pub fn write_aggregate( |
| 788 | 789 | &mut self, |
| 789 | 790 | kind: &mir::AggregateKind<'tcx>, |
| 790 | operands: &[mir::Operand<'tcx>], | |
| 791 | operands: &IndexSlice<FieldIdx, mir::Operand<'tcx>>, | |
| 791 | 792 | dest: &PlaceTy<'tcx, M::Provenance>, |
| 792 | 793 | ) -> InterpResult<'tcx> { |
| 793 | 794 | self.write_uninit(&dest)?; |
| ... | ... | @@ -801,9 +802,9 @@ where |
| 801 | 802 | if active_field_index.is_some() { |
| 802 | 803 | assert_eq!(operands.len(), 1); |
| 803 | 804 | } |
| 804 | for (field_index, operand) in operands.iter().enumerate() { | |
| 805 | for (field_index, operand) in operands.iter_enumerated() { | |
| 805 | 806 | let field_index = active_field_index.unwrap_or(field_index); |
| 806 | let field_dest = self.place_field(&variant_dest, field_index)?; | |
| 807 | let field_dest = self.place_field(&variant_dest, field_index.as_usize())?; | |
| 807 | 808 | let op = self.eval_operand(operand, Some(field_dest.layout))?; |
| 808 | 809 | self.copy_op(&op, &field_dest, /*allow_transmute*/ false)?; |
| 809 | 810 | } |
compiler/rustc_index/src/vec.rs+6| ... | ... | @@ -93,6 +93,12 @@ impl<I: Idx, T: fmt::Debug> fmt::Debug for IndexVec<I, T> { |
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | impl<I: Idx, T: fmt::Debug> fmt::Debug for IndexSlice<I, T> { | |
| 97 | fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { | |
| 98 | fmt::Debug::fmt(&self.raw, fmt) | |
| 99 | } | |
| 100 | } | |
| 101 | ||
| 96 | 102 | impl<I: Idx, T> IndexVec<I, T> { |
| 97 | 103 | #[inline] |
| 98 | 104 | pub fn new() -> Self { |
compiler/rustc_middle/src/mir/syntax.rs+4-3| ... | ... | @@ -16,6 +16,7 @@ use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece}; |
| 16 | 16 | use rustc_hir::def_id::DefId; |
| 17 | 17 | use rustc_hir::{self as hir}; |
| 18 | 18 | use rustc_hir::{self, GeneratorKind}; |
| 19 | use rustc_index::vec::IndexVec; | |
| 19 | 20 | use rustc_target::abi::{FieldIdx, VariantIdx}; |
| 20 | 21 | |
| 21 | 22 | use rustc_ast::Mutability; |
| ... | ... | @@ -1125,7 +1126,7 @@ pub enum Rvalue<'tcx> { |
| 1125 | 1126 | /// |
| 1126 | 1127 | /// Disallowed after deaggregation for all aggregate kinds except `Array` and `Generator`. After |
| 1127 | 1128 | /// generator lowering, `Generator` aggregate kinds are disallowed too. |
| 1128 | Aggregate(Box<AggregateKind<'tcx>>, Vec<Operand<'tcx>>), | |
| 1129 | Aggregate(Box<AggregateKind<'tcx>>, IndexVec<FieldIdx, Operand<'tcx>>), | |
| 1129 | 1130 | |
| 1130 | 1131 | /// Transmutes a `*mut u8` into shallow-initialized `Box<T>`. |
| 1131 | 1132 | /// |
| ... | ... | @@ -1186,7 +1187,7 @@ pub enum AggregateKind<'tcx> { |
| 1186 | 1187 | /// active field number and is present only for union expressions |
| 1187 | 1188 | /// -- e.g., for a union expression `SomeUnion { c: .. }`, the |
| 1188 | 1189 | /// active field index would identity the field `c` |
| 1189 | Adt(DefId, VariantIdx, SubstsRef<'tcx>, Option<UserTypeAnnotationIndex>, Option<usize>), | |
| 1190 | Adt(DefId, VariantIdx, SubstsRef<'tcx>, Option<UserTypeAnnotationIndex>, Option<FieldIdx>), | |
| 1190 | 1191 | |
| 1191 | 1192 | Closure(DefId, SubstsRef<'tcx>), |
| 1192 | 1193 | Generator(DefId, SubstsRef<'tcx>, hir::Movability), |
| ... | ... | @@ -1263,7 +1264,7 @@ pub enum BinOp { |
| 1263 | 1264 | mod size_asserts { |
| 1264 | 1265 | use super::*; |
| 1265 | 1266 | // tidy-alphabetical-start |
| 1266 | static_assert_size!(AggregateKind<'_>, 40); | |
| 1267 | static_assert_size!(AggregateKind<'_>, 32); | |
| 1267 | 1268 | static_assert_size!(Operand<'_>, 24); |
| 1268 | 1269 | static_assert_size!(Place<'_>, 16); |
| 1269 | 1270 | static_assert_size!(PlaceElem<'_>, 24); |
compiler/rustc_mir_build/src/build/custom/parse/instruction.rs+1-1| ... | ... | @@ -185,7 +185,7 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> { |
| 185 | 185 | }, |
| 186 | 186 | ExprKind::Adt(box AdtExpr{ adt_def, variant_index, substs, fields, .. }) => { |
| 187 | 187 | let is_union = adt_def.is_union(); |
| 188 | let active_field_index = is_union.then(|| fields[0].name.index()); | |
| 188 | let active_field_index = is_union.then(|| fields[0].name); | |
| 189 | 189 | |
| 190 | 190 | Ok(Rvalue::Aggregate( |
| 191 | 191 | Box::new(AggregateKind::Adt(adt_def.did(), *variant_index, substs, None, active_field_index)), |
compiler/rustc_mir_build/src/build/expr/as_rvalue.rs+6-7| ... | ... | @@ -1,8 +1,8 @@ |
| 1 | 1 | //! See docs in `build/expr/mod.rs`. |
| 2 | 2 | |
| 3 | use rustc_index::vec::Idx; | |
| 3 | use rustc_index::vec::{Idx, IndexVec}; | |
| 4 | 4 | use rustc_middle::ty::util::IntTypeExt; |
| 5 | use rustc_target::abi::{Abi, Primitive}; | |
| 5 | use rustc_target::abi::{Abi, FieldIdx, Primitive}; | |
| 6 | 6 | |
| 7 | 7 | use crate::build::expr::as_place::PlaceBase; |
| 8 | 8 | use crate::build::expr::category::{Category, RvalueFunc}; |
| ... | ... | @@ -17,7 +17,6 @@ use rustc_middle::thir::*; |
| 17 | 17 | use rustc_middle::ty::cast::{mir_cast_kind, CastTy}; |
| 18 | 18 | use rustc_middle::ty::{self, Ty, UpvarSubsts}; |
| 19 | 19 | use rustc_span::Span; |
| 20 | use rustc_target::abi::FieldIdx; | |
| 21 | 20 | |
| 22 | 21 | impl<'a, 'tcx> Builder<'a, 'tcx> { |
| 23 | 22 | /// Returns an rvalue suitable for use until the end of the current |
| ... | ... | @@ -327,7 +326,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { |
| 327 | 326 | |
| 328 | 327 | // first process the set of fields |
| 329 | 328 | let el_ty = expr.ty.sequence_element_type(this.tcx); |
| 330 | let fields: Vec<_> = fields | |
| 329 | let fields: IndexVec<FieldIdx, _> = fields | |
| 331 | 330 | .into_iter() |
| 332 | 331 | .copied() |
| 333 | 332 | .map(|f| { |
| ... | ... | @@ -348,7 +347,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { |
| 348 | 347 | ExprKind::Tuple { ref fields } => { |
| 349 | 348 | // see (*) above |
| 350 | 349 | // first process the set of fields |
| 351 | let fields: Vec<_> = fields | |
| 350 | let fields: IndexVec<FieldIdx, _> = fields | |
| 352 | 351 | .into_iter() |
| 353 | 352 | .copied() |
| 354 | 353 | .map(|f| { |
| ... | ... | @@ -402,7 +401,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { |
| 402 | 401 | } |
| 403 | 402 | |
| 404 | 403 | // see (*) above |
| 405 | let operands: Vec<_> = upvars | |
| 404 | let operands: IndexVec<FieldIdx, _> = upvars | |
| 406 | 405 | .into_iter() |
| 407 | 406 | .copied() |
| 408 | 407 | .map(|upvar| { |
| ... | ... | @@ -710,7 +709,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { |
| 710 | 709 | } |
| 711 | 710 | this.record_operands_moved(&[value_operand]); |
| 712 | 711 | } |
| 713 | block.and(Rvalue::Aggregate(Box::new(AggregateKind::Array(elem_ty)), Vec::new())) | |
| 712 | block.and(Rvalue::Aggregate(Box::new(AggregateKind::Array(elem_ty)), IndexVec::new())) | |
| 714 | 713 | } |
| 715 | 714 | |
| 716 | 715 | fn limit_capture_mutability( |
compiler/rustc_mir_build/src/build/expr/into.rs+4-7| ... | ... | @@ -6,11 +6,9 @@ use rustc_ast::InlineAsmOptions; |
| 6 | 6 | use rustc_data_structures::fx::FxHashMap; |
| 7 | 7 | use rustc_data_structures::stack::ensure_sufficient_stack; |
| 8 | 8 | use rustc_hir as hir; |
| 9 | use rustc_index::vec::Idx; | |
| 10 | 9 | use rustc_middle::mir::*; |
| 11 | 10 | use rustc_middle::thir::*; |
| 12 | 11 | use rustc_middle::ty::CanonicalUserTypeAnnotation; |
| 13 | use rustc_target::abi::FieldIdx; | |
| 14 | 12 | use std::iter; |
| 15 | 13 | |
| 16 | 14 | impl<'a, 'tcx> Builder<'a, 'tcx> { |
| ... | ... | @@ -320,7 +318,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { |
| 320 | 318 | // See the notes for `ExprKind::Array` in `as_rvalue` and for |
| 321 | 319 | // `ExprKind::Borrow` above. |
| 322 | 320 | let is_union = adt_def.is_union(); |
| 323 | let active_field_index = is_union.then(|| fields[0].name.index()); | |
| 321 | let active_field_index = is_union.then(|| fields[0].name); | |
| 324 | 322 | |
| 325 | 323 | let scope = this.local_scope(); |
| 326 | 324 | |
| ... | ... | @@ -344,10 +342,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { |
| 344 | 342 | }) |
| 345 | 343 | .collect(); |
| 346 | 344 | |
| 347 | let field_names: Vec<_> = | |
| 348 | (0..adt_def.variant(variant_index).fields.len()).map(FieldIdx::new).collect(); | |
| 345 | let field_names = adt_def.variant(variant_index).fields.indices(); | |
| 349 | 346 | |
| 350 | let fields: Vec<_> = if let Some(FruInfo { base, field_types }) = base { | |
| 347 | let fields = if let Some(FruInfo { base, field_types }) = base { | |
| 351 | 348 | let place_builder = |
| 352 | 349 | unpack!(block = this.as_place_builder(block, &this.thir[*base])); |
| 353 | 350 | |
| ... | ... | @@ -364,7 +361,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { |
| 364 | 361 | }) |
| 365 | 362 | .collect() |
| 366 | 363 | } else { |
| 367 | field_names.iter().filter_map(|n| fields_map.get(n).cloned()).collect() | |
| 364 | field_names.filter_map(|n| fields_map.get(&n).cloned()).collect() | |
| 368 | 365 | }; |
| 369 | 366 | |
| 370 | 367 | let inferred_ty = expr.ty; |
compiler/rustc_mir_transform/src/generator.rs+2-2| ... | ... | @@ -274,7 +274,7 @@ impl<'tcx> TransformVisitor<'tcx> { |
| 274 | 274 | statements.push(Statement { |
| 275 | 275 | kind: StatementKind::Assign(Box::new(( |
| 276 | 276 | Place::return_place(), |
| 277 | Rvalue::Aggregate(Box::new(kind), vec![]), | |
| 277 | Rvalue::Aggregate(Box::new(kind), IndexVec::new()), | |
| 278 | 278 | ))), |
| 279 | 279 | source_info, |
| 280 | 280 | }); |
| ... | ... | @@ -287,7 +287,7 @@ impl<'tcx> TransformVisitor<'tcx> { |
| 287 | 287 | statements.push(Statement { |
| 288 | 288 | kind: StatementKind::Assign(Box::new(( |
| 289 | 289 | Place::return_place(), |
| 290 | Rvalue::Aggregate(Box::new(kind), vec![val]), | |
| 290 | Rvalue::Aggregate(Box::new(kind), IndexVec::from_iter([val])), | |
| 291 | 291 | ))), |
| 292 | 292 | source_info, |
| 293 | 293 | }); |