From 2e39b9c51f8a94662bf0c7d1f3411ebade7bfeb6 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 23 May 2019 22:17:45 +0200 Subject: [PATCH] Make find_local iterate instead of recurse --- .../dataflow/impls/borrowed_locals.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/librustc_mir/dataflow/impls/borrowed_locals.rs b/src/librustc_mir/dataflow/impls/borrowed_locals.rs index 42c2387b7052d..65cbc83fbcb84 100644 --- a/src/librustc_mir/dataflow/impls/borrowed_locals.rs +++ b/src/librustc_mir/dataflow/impls/borrowed_locals.rs @@ -91,16 +91,19 @@ struct BorrowedLocalsVisitor<'b, 'c: 'b> { } fn find_local<'tcx>(place: &Place<'tcx>) -> Option { - match *place { - Place::Base(PlaceBase::Local(l)) => Some(l), - Place::Base(PlaceBase::Static(..)) => None, - Place::Projection(ref proj) => { - match proj.elem { - ProjectionElem::Deref => None, - _ => find_local(&proj.base) + place.iterate(|place_base, place_projection| { + for proj in place_projection { + if proj.elem == ProjectionElem::Deref { + return None; } } - } + + if let PlaceBase::Local(local) = place_base { + Some(*local) + } else { + None + } + }) } impl<'tcx, 'b, 'c> Visitor<'tcx> for BorrowedLocalsVisitor<'b, 'c> {