From 536613554fbfc16c0da85615aff6717229d9df6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Fri, 25 Aug 2017 20:10:23 +0200 Subject: [PATCH] Clean up YieldFinder --- src/librustc/middle/region.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 6374eb3ff90..944d03737d3 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -1175,13 +1175,18 @@ struct YieldFinder<'a> { impl<'a> YieldFinder<'a> { fn lookup(&mut self, id: NodeId, f: F) { + // Don't traverse further if we found a yield expression + if self.result.is_some() { + return; + } + + // See if there's an entry in the cache if let Some(result) = self.cache.get(&id) { self.result = *result; return; } - if self.result.is_some() { - return; - } + + // Otherwise calculate the result and insert it into the cache f(self); self.cache.insert(id, self.result); }