From 3eea41a68ca2de28dca35b6e713cbb36aa09f0c8 Mon Sep 17 00:00:00 2001 From: David Lattimore Date: Thu, 6 Aug 2020 07:36:03 +1000 Subject: Use SyntaxNode.ancestors instead of a loop --- crates/ra_ssr/src/resolving.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'crates') diff --git a/crates/ra_ssr/src/resolving.rs b/crates/ra_ssr/src/resolving.rs index 0ac929bd5..df60048eb 100644 --- a/crates/ra_ssr/src/resolving.rs +++ b/crates/ra_ssr/src/resolving.rs @@ -176,13 +176,7 @@ impl<'db> ResolutionScope<'db> { /// Returns the function in which SSR was invoked, if any. pub(crate) fn current_function(&self) -> Option { - let mut node = self.node.clone(); - loop { - if node.kind() == SyntaxKind::FN { - return Some(node); - } - node = node.parent()?; - } + self.node.ancestors().find(|node| node.kind() == SyntaxKind::FN).map(|node| node.clone()) } fn resolve_path(&self, path: &ast::Path) -> Option { -- cgit v1.2.3