address review

This commit is contained in:
b-naber 2022-11-02 22:20:17 +01:00
parent 2ef8308687
commit fd6fed3027
2 changed files with 21 additions and 4 deletions

View File

@ -325,6 +325,13 @@ pub(crate) fn clone_project(&self, elem: PlaceElem<'tcx>) -> Self {
} }
} }
/// 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>( pub fn try_compute_ty<D>(
&self, &self,
local_decls: &D, local_decls: &D,

View File

@ -54,10 +54,20 @@ pub(crate) fn field_match_pairs_tuple_struct<'pat>(
let variant_idx = opt_variant_idx.unwrap(); let variant_idx = opt_variant_idx.unwrap();
adt_def.variant(variant_idx).fields[field_idx].ty(self.tcx, substs) adt_def.variant(variant_idx).fields[field_idx].ty(self.tcx, substs)
} }
ty::Adt(adt_def, substs) => { ty::Adt(adt_def, substs) => adt_def
adt_def.all_fields().collect::<Vec<_>>()[field_idx].ty(self.tcx, substs) .all_fields()
} .nth(field_idx)
ty::Tuple(elems) => elems.to_vec()[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!( _ => bug!(
"no field available, place_ty: {:#?}, kind: {:?}", "no field available, place_ty: {:#?}, kind: {:?}",
place_ty, place_ty,