Skip to content

Commit

Permalink
Add Place::base_local method and improve doc for Place::local to …
Browse files Browse the repository at this point in the history
…clarify why we need the former.
  • Loading branch information
pnkfelix committed Oct 16, 2018
1 parent 5ea8eb5 commit 44a2f68
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1967,7 +1967,10 @@ impl<'tcx> Place<'tcx> {
Place::Projection(Box::new(PlaceProjection { base: self, elem }))
}

/// Find the innermost `Local` from this `Place`.
/// Find the innermost `Local` from this `Place`, *if* it is either a local itself or
/// a single deref of a local.
///
/// FIXME: can we safely swap the semantics of `fn base_local` below in here instead?
pub fn local(&self) -> Option<Local> {
match self {
Place::Local(local) |
Expand All @@ -1978,6 +1981,15 @@ impl<'tcx> Place<'tcx> {
_ => None,
}
}

/// Find the innermost `Local` from this `Place`.
pub fn base_local(&self) -> Option<Local> {
match self {
Place::Local(local) => Some(*local),
Place::Projection(box Projection { base, elem: _ }) => base.base_local(),
Place::Promoted(..) | Place::Static(..) => None,
}
}
}

impl<'tcx> Debug for Place<'tcx> {
Expand Down

0 comments on commit 44a2f68

Please sign in to comment.