Skip to content

Commit bdb9775

Browse files
committed
Simplify find_mod_path with use of node.ancestors
1 parent 544322e commit bdb9775

File tree

1 file changed

+1
-20
lines changed

1 file changed

+1
-20
lines changed

crates/ra_assists/src/handlers/expand_glob_import.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,7 @@ pub(crate) fn expand_glob_import(acc: &mut Assists, ctx: &AssistContext) -> Opti
5959
}
6060

6161
fn find_mod_path(star: &SyntaxToken) -> Option<ast::Path> {
62-
let mut node = star.parent();
63-
64-
loop {
65-
match_ast! {
66-
match node {
67-
ast::UseTree(use_tree) => {
68-
if let Some(path) = use_tree.path() {
69-
return Some(path);
70-
}
71-
},
72-
ast::UseTreeList(_use_tree_list) => {},
73-
_ => return None,
74-
}
75-
}
76-
77-
node = match node.parent() {
78-
Some(node) => node,
79-
None => return None,
80-
}
81-
}
62+
star.ancestors().find_map(|n| ast::UseTree::cast(n).and_then(|u| u.path()))
8263
}
8364

8465
#[derive(PartialEq)]

0 commit comments

Comments
 (0)