Skip to content

Commit a818173

Browse files
Rollup merge of #96386 - SparrowLii:des_field, r=jackh726
simplify `describe_field` func in borrowck's diagnostics part This PR simplify the `describe_field` func in borrowck's diagnostics part, besides fix the FIXME in it.
2 parents bb6265a + 74853ee commit a818173

File tree

1 file changed

+10
-19
lines changed
  • compiler/rustc_borrowck/src/diagnostics

1 file changed

+10
-19
lines changed

compiler/rustc_borrowck/src/diagnostics/mod.rs

+10-19
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ crate use outlives_suggestion::OutlivesSuggestionBuilder;
4040
crate use region_errors::{ErrorConstraintInfo, RegionErrorKind, RegionErrors};
4141
crate use region_name::{RegionName, RegionNameSource};
4242
crate use rustc_const_eval::util::CallKind;
43+
use rustc_middle::mir::tcx::PlaceTy;
4344

4445
pub(super) struct IncludingDowncast(pub(super) bool);
4546

@@ -329,30 +330,20 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
329330

330331
/// End-user visible description of the `field`nth field of `base`
331332
fn describe_field(&self, place: PlaceRef<'tcx>, field: Field) -> String {
332-
// FIXME Place2 Make this work iteratively
333-
match place {
334-
PlaceRef { local, projection: [] } => {
335-
let local = &self.body.local_decls[local];
336-
self.describe_field_from_ty(local.ty, field, None)
337-
}
333+
let place_ty = match place {
334+
PlaceRef { local, projection: [] } => PlaceTy::from_ty(self.body.local_decls[local].ty),
338335
PlaceRef { local, projection: [proj_base @ .., elem] } => match elem {
339-
ProjectionElem::Deref => {
340-
self.describe_field(PlaceRef { local, projection: proj_base }, field)
341-
}
342-
ProjectionElem::Downcast(_, variant_index) => {
343-
let base_ty = place.ty(self.body, self.infcx.tcx).ty;
344-
self.describe_field_from_ty(base_ty, field, Some(*variant_index))
345-
}
346-
ProjectionElem::Field(_, field_type) => {
347-
self.describe_field_from_ty(*field_type, field, None)
348-
}
349-
ProjectionElem::Index(..)
336+
ProjectionElem::Deref
337+
| ProjectionElem::Index(..)
350338
| ProjectionElem::ConstantIndex { .. }
351339
| ProjectionElem::Subslice { .. } => {
352-
self.describe_field(PlaceRef { local, projection: proj_base }, field)
340+
PlaceRef { local, projection: proj_base }.ty(self.body, self.infcx.tcx)
353341
}
342+
ProjectionElem::Downcast(..) => place.ty(self.body, self.infcx.tcx),
343+
ProjectionElem::Field(_, field_type) => PlaceTy::from_ty(*field_type),
354344
},
355-
}
345+
};
346+
self.describe_field_from_ty(place_ty.ty, field, place_ty.variant_index)
356347
}
357348

358349
/// End-user visible description of the `field_index`nth field of `ty`

0 commit comments

Comments
 (0)