Skip to content

Commit 44a2f68

Browse files
committed
Add Place::base_local method and improve doc for Place::local to clarify why we need the former.
1 parent 5ea8eb5 commit 44a2f68

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Diff for: src/librustc/mir/mod.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -1967,7 +1967,10 @@ impl<'tcx> Place<'tcx> {
19671967
Place::Projection(Box::new(PlaceProjection { base: self, elem }))
19681968
}
19691969

1970-
/// Find the innermost `Local` from this `Place`.
1970+
/// Find the innermost `Local` from this `Place`, *if* it is either a local itself or
1971+
/// a single deref of a local.
1972+
///
1973+
/// FIXME: can we safely swap the semantics of `fn base_local` below in here instead?
19711974
pub fn local(&self) -> Option<Local> {
19721975
match self {
19731976
Place::Local(local) |
@@ -1978,6 +1981,15 @@ impl<'tcx> Place<'tcx> {
19781981
_ => None,
19791982
}
19801983
}
1984+
1985+
/// Find the innermost `Local` from this `Place`.
1986+
pub fn base_local(&self) -> Option<Local> {
1987+
match self {
1988+
Place::Local(local) => Some(*local),
1989+
Place::Projection(box Projection { base, elem: _ }) => base.base_local(),
1990+
Place::Promoted(..) | Place::Static(..) => None,
1991+
}
1992+
}
19811993
}
19821994

19831995
impl<'tcx> Debug for Place<'tcx> {

0 commit comments

Comments
 (0)