simplify some code that depend on Deref

This commit is contained in:
ouz-a 2022-05-12 00:27:06 +03:00
parent 41419e7036
commit c0e4230bf5
3 changed files with 32 additions and 28 deletions

View file

@ -1461,6 +1461,16 @@ impl<'tcx> Place<'tcx> {
self.projection.iter().any(|elem| elem.is_indirect())
}
/// If MirPhase >= Derefered and if projection contains Deref,
/// It's guaranteed to be in the first place
pub fn ret_deref(&self) -> Option<PlaceElem<'tcx>> {
if !self.projection.is_empty() && self.projection[0] == PlaceElem::Deref {
return Some(self.projection[0]);
} else {
None
}
}
/// Finds the innermost `Local` from this `Place`, *if* it is either a local itself or
/// a single deref of a local.
#[inline(always)]
@ -1533,6 +1543,16 @@ impl<'tcx> PlaceRef<'tcx> {
}
}
/// If MirPhase >= Derefered and if projection contains Deref,
/// It's guaranteed to be in the first place
pub fn ret_deref(&self) -> Option<PlaceElem<'tcx>> {
if !self.projection.is_empty() && self.projection[0] == PlaceElem::Deref {
return Some(self.projection[0]);
} else {
None
}
}
/// If this place represents a local variable like `_X` with no
/// projections, return `Some(_X)`.
#[inline]