Skip to content

Commit fd6fed3

Browse files
committed
address review
1 parent 2ef8308 commit fd6fed3

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

compiler/rustc_mir_build/src/build/expr/as_place.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,13 @@ impl<'tcx> PlaceBuilder<'tcx> {
325325
}
326326
}
327327

328+
/// Similar to `Place::ty` but needed during mir building.
329+
///
330+
/// Applies the projections in the `PlaceBuilder` to the base
331+
/// type.
332+
///
333+
/// Fallible as the root of this place may be an upvar for
334+
/// which no base type can be determined.
328335
pub fn try_compute_ty<D>(
329336
&self,
330337
local_decls: &D,

compiler/rustc_mir_build/src/build/matches/util.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
5454
let variant_idx = opt_variant_idx.unwrap();
5555
adt_def.variant(variant_idx).fields[field_idx].ty(self.tcx, substs)
5656
}
57-
ty::Adt(adt_def, substs) => {
58-
adt_def.all_fields().collect::<Vec<_>>()[field_idx].ty(self.tcx, substs)
59-
}
60-
ty::Tuple(elems) => elems.to_vec()[field_idx],
57+
ty::Adt(adt_def, substs) => adt_def
58+
.all_fields()
59+
.nth(field_idx)
60+
.unwrap_or_else(|| {
61+
bug!(
62+
"expected to take field idx {:?} of fields of {:?}",
63+
field_idx,
64+
adt_def
65+
)
66+
})
67+
.ty(self.tcx, substs),
68+
ty::Tuple(elems) => elems.iter().nth(field_idx).unwrap_or_else(|| {
69+
bug!("expected to take field idx {:?} of {:?}", field_idx, elems)
70+
}),
6171
_ => bug!(
6272
"no field available, place_ty: {:#?}, kind: {:?}",
6373
place_ty,

0 commit comments

Comments
 (0)