From bdb97756ca4c2710061fc49a5e2c2c10f5cc1eb6 Mon Sep 17 00:00:00 2001 From: unexge Date: Mon, 3 Aug 2020 13:04:20 +0300 Subject: Simplify `find_mod_path` with use of `node.ancestors` --- .../ra_assists/src/handlers/expand_glob_import.rs | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/crates/ra_assists/src/handlers/expand_glob_import.rs b/crates/ra_assists/src/handlers/expand_glob_import.rs index 963c1353f..1eb8070ad 100644 --- a/crates/ra_assists/src/handlers/expand_glob_import.rs +++ b/crates/ra_assists/src/handlers/expand_glob_import.rs @@ -59,26 +59,7 @@ pub(crate) fn expand_glob_import(acc: &mut Assists, ctx: &AssistContext) -> Opti } fn find_mod_path(star: &SyntaxToken) -> Option { - let mut node = star.parent(); - - loop { - match_ast! { - match node { - ast::UseTree(use_tree) => { - if let Some(path) = use_tree.path() { - return Some(path); - } - }, - ast::UseTreeList(_use_tree_list) => {}, - _ => return None, - } - } - - node = match node.parent() { - Some(node) => node, - None => return None, - } - } + star.ancestors().find_map(|n| ast::UseTree::cast(n).and_then(|u| u.path())) } #[derive(PartialEq)] -- cgit v1.2.3