Refactor projection debug.

This commit is contained in:
Camille GILLOT 2023-08-31 18:56:34 +00:00
parent f222a2dd8f
commit 429a9258f1

View File

@ -1575,7 +1575,7 @@ pub fn can_use_in_debuginfo(&self) -> bool {
/// need neither the `V` parameter for `Index` nor the `T` for `Field`. /// need neither the `V` parameter for `Index` nor the `T` for `Field`.
pub type ProjectionKind = ProjectionElem<(), ()>; pub type ProjectionKind = ProjectionElem<(), ()>;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct PlaceRef<'tcx> { pub struct PlaceRef<'tcx> {
pub local: Local, pub local: Local,
pub projection: &'tcx [PlaceElem<'tcx>], pub projection: &'tcx [PlaceElem<'tcx>],
@ -1753,7 +1753,20 @@ pub fn project_deeper(
impl Debug for Place<'_> { impl Debug for Place<'_> {
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { 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 { match elem {
ProjectionElem::OpaqueCast(_) ProjectionElem::OpaqueCast(_)
| ProjectionElem::Downcast(_, _) | ProjectionElem::Downcast(_, _)
@ -1769,9 +1782,11 @@ fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
} }
} }
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 { match elem {
ProjectionElem::OpaqueCast(ty) => { ProjectionElem::OpaqueCast(ty) => {
write!(fmt, " as {ty})")?; write!(fmt, " as {ty})")?;
@ -1814,7 +1829,6 @@ fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
Ok(()) Ok(())
} }
}
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Scopes // Scopes