From 44a2f681a988eb5587bd98a0cb37730fbd33f576 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Tue, 16 Oct 2018 15:39:07 +0200 Subject: [PATCH] Add `Place::base_local` method and improve doc for `Place::local` to clarify why we need the former. --- src/librustc/mir/mod.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 2587e19b1cb62..883a9d6497b0b 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -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 { match self { Place::Local(local) | @@ -1978,6 +1981,15 @@ impl<'tcx> Place<'tcx> { _ => None, } } + + /// Find the innermost `Local` from this `Place`. + pub fn base_local(&self) -> Option { + 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> {