Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify describe_field func in borrowck's diagnostics part #96386

Merged
merged 1 commit into from
Apr 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 10 additions & 19 deletions compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ crate use outlives_suggestion::OutlivesSuggestionBuilder;
crate use region_errors::{ErrorConstraintInfo, RegionErrorKind, RegionErrors};
crate use region_name::{RegionName, RegionNameSource};
crate use rustc_const_eval::util::CallKind;
use rustc_middle::mir::tcx::PlaceTy;

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

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

/// End-user visible description of the `field`nth field of `base`
fn describe_field(&self, place: PlaceRef<'tcx>, field: Field) -> String {
// FIXME Place2 Make this work iteratively
match place {
PlaceRef { local, projection: [] } => {
let local = &self.body.local_decls[local];
self.describe_field_from_ty(local.ty, field, None)
}
let place_ty = match place {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could instead just be ty: Ty<_> right? Then in the empty projection case, we don't need to wrap in a PlaceTy?

Copy link
Member Author

@SparrowLii SparrowLii Apr 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing you might be talking about PlaceRef? We need to know the value of variant_index, and the structure of PlaceTy fits well. Do you think it is better to separate Ty and variant_index for semantic clarity?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops I missed the variant index.

PlaceRef { local, projection: [] } => PlaceTy::from_ty(self.body.local_decls[local].ty),
PlaceRef { local, projection: [proj_base @ .., elem] } => match elem {
ProjectionElem::Deref => {
self.describe_field(PlaceRef { local, projection: proj_base }, field)
}
ProjectionElem::Downcast(_, variant_index) => {
let base_ty = place.ty(self.body, self.infcx.tcx).ty;
self.describe_field_from_ty(base_ty, field, Some(*variant_index))
}
ProjectionElem::Field(_, field_type) => {
self.describe_field_from_ty(*field_type, field, None)
}
ProjectionElem::Index(..)
ProjectionElem::Deref
| ProjectionElem::Index(..)
| ProjectionElem::ConstantIndex { .. }
| ProjectionElem::Subslice { .. } => {
self.describe_field(PlaceRef { local, projection: proj_base }, field)
PlaceRef { local, projection: proj_base }.ty(self.body, self.infcx.tcx)
}
ProjectionElem::Downcast(..) => place.ty(self.body, self.infcx.tcx),
ProjectionElem::Field(_, field_type) => PlaceTy::from_ty(*field_type),
},
}
};
self.describe_field_from_ty(place_ty.ty, field, place_ty.variant_index)
}

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