diff options
| author | b-naber <bn263@gmx.de> | 2022-11-02 22:20:17 +0100 |
|---|---|---|
| committer | b-naber <bn263@gmx.de> | 2022-11-23 20:01:53 +0100 |
| commit | fd6fed3027be425c27a5a8c825575bdd7a1e63dd (patch) | |
| tree | 1f94ec8c44a692f713c328e23c81f98ab52e3334 | |
| parent | 2ef8308687f57335e117fdfa7d92002cf6f53eda (diff) | |
| download | rust-fd6fed3027be425c27a5a8c825575bdd7a1e63dd.tar.gz rust-fd6fed3027be425c27a5a8c825575bdd7a1e63dd.zip | |
address review
| -rw-r--r-- | compiler/rustc_mir_build/src/build/expr/as_place.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_mir_build/src/build/matches/util.rs | 18 |
2 files changed, 21 insertions, 4 deletions
diff --git a/compiler/rustc_mir_build/src/build/expr/as_place.rs b/compiler/rustc_mir_build/src/build/expr/as_place.rs index b682b0c3bd4..36f08a7a48f 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_place.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_place.rs @@ -325,6 +325,13 @@ impl<'tcx> PlaceBuilder<'tcx> { } } + /// Similar to `Place::ty` but needed during mir building. + /// + /// Applies the projections in the `PlaceBuilder` to the base + /// type. + /// + /// Fallible as the root of this place may be an upvar for + /// which no base type can be determined. pub fn try_compute_ty<D>( &self, local_decls: &D, diff --git a/compiler/rustc_mir_build/src/build/matches/util.rs b/compiler/rustc_mir_build/src/build/matches/util.rs index 7423b5e1ae3..fb2a5be28a2 100644 --- a/compiler/rustc_mir_build/src/build/matches/util.rs +++ b/compiler/rustc_mir_build/src/build/matches/util.rs @@ -54,10 +54,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let variant_idx = opt_variant_idx.unwrap(); adt_def.variant(variant_idx).fields[field_idx].ty(self.tcx, substs) } - ty::Adt(adt_def, substs) => { - adt_def.all_fields().collect::<Vec<_>>()[field_idx].ty(self.tcx, substs) - } - ty::Tuple(elems) => elems.to_vec()[field_idx], + ty::Adt(adt_def, substs) => adt_def + .all_fields() + .nth(field_idx) + .unwrap_or_else(|| { + bug!( + "expected to take field idx {:?} of fields of {:?}", + field_idx, + adt_def + ) + }) + .ty(self.tcx, substs), + ty::Tuple(elems) => elems.iter().nth(field_idx).unwrap_or_else(|| { + bug!("expected to take field idx {:?} of {:?}", field_idx, elems) + }), _ => bug!( "no field available, place_ty: {:#?}, kind: {:?}", place_ty, |
