Refactor projection debug.
This commit is contained in:
parent
f222a2dd8f
commit
429a9258f1
1 changed files with 75 additions and 61 deletions
|
@ -1575,7 +1575,7 @@ impl<V, T> ProjectionElem<V, T> {
|
|||
/// need neither the `V` parameter for `Index` nor the `T` for `Field`.
|
||||
pub type ProjectionKind = ProjectionElem<(), ()>;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct PlaceRef<'tcx> {
|
||||
pub local: Local,
|
||||
pub projection: &'tcx [PlaceElem<'tcx>],
|
||||
|
@ -1753,7 +1753,20 @@ impl<'tcx> PlaceRef<'tcx> {
|
|||
|
||||
impl Debug for Place<'_> {
|
||||
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
|
||||
for elem in self.projection.iter().rev() {
|
||||
self.as_ref().fmt(fmt)
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for PlaceRef<'_> {
|
||||
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
|
||||
pre_fmt_projection(self.projection, fmt)?;
|
||||
write!(fmt, "{:?}", self.local)?;
|
||||
post_fmt_projection(self.projection, fmt)
|
||||
}
|
||||
}
|
||||
|
||||
fn pre_fmt_projection(projection: &[PlaceElem<'_>], fmt: &mut Formatter<'_>) -> fmt::Result {
|
||||
for &elem in projection.iter().rev() {
|
||||
match elem {
|
||||
ProjectionElem::OpaqueCast(_)
|
||||
| ProjectionElem::Downcast(_, _)
|
||||
|
@ -1769,9 +1782,11 @@ impl Debug for Place<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
write!(fmt, "{:?}", self.local)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
for elem in self.projection.iter() {
|
||||
fn post_fmt_projection(projection: &[PlaceElem<'_>], fmt: &mut Formatter<'_>) -> fmt::Result {
|
||||
for &elem in projection.iter() {
|
||||
match elem {
|
||||
ProjectionElem::OpaqueCast(ty) => {
|
||||
write!(fmt, " as {ty})")?;
|
||||
|
@ -1813,7 +1828,6 @@ impl Debug for Place<'_> {
|
|||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue