diff options
Diffstat (limited to 'crates/ra_hir/src/path.rs')
-rw-r--r-- | crates/ra_hir/src/path.rs | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/crates/ra_hir/src/path.rs b/crates/ra_hir/src/path.rs index 370e10bb8..7b0ce3b61 100644 --- a/crates/ra_hir/src/path.rs +++ b/crates/ra_hir/src/path.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use ra_syntax::{ast, AstNode, TextRange}; | 1 | use ra_syntax::{ast, AstNode}; |
2 | 2 | ||
3 | use crate::{Name, AsName}; | 3 | use crate::{Name, AsName}; |
4 | 4 | ||
@@ -18,7 +18,10 @@ pub enum PathKind { | |||
18 | 18 | ||
19 | impl Path { | 19 | impl Path { |
20 | /// Calls `cb` with all paths, represented by this use item. | 20 | /// Calls `cb` with all paths, represented by this use item. |
21 | pub fn expand_use_item(item: &ast::UseItem, mut cb: impl FnMut(Path, Option<TextRange>)) { | 21 | pub fn expand_use_item<'a>( |
22 | item: &'a ast::UseItem, | ||
23 | mut cb: impl FnMut(Path, Option<&'a ast::PathSegment>), | ||
24 | ) { | ||
22 | if let Some(tree) = item.use_tree() { | 25 | if let Some(tree) = item.use_tree() { |
23 | expand_use_tree(None, tree, &mut cb); | 26 | expand_use_tree(None, tree, &mut cb); |
24 | } | 27 | } |
@@ -98,10 +101,10 @@ impl From<Name> for Path { | |||
98 | } | 101 | } |
99 | } | 102 | } |
100 | 103 | ||
101 | fn expand_use_tree( | 104 | fn expand_use_tree<'a>( |
102 | prefix: Option<Path>, | 105 | prefix: Option<Path>, |
103 | tree: &ast::UseTree, | 106 | tree: &'a ast::UseTree, |
104 | cb: &mut impl FnMut(Path, Option<TextRange>), | 107 | cb: &mut impl FnMut(Path, Option<&'a ast::PathSegment>), |
105 | ) { | 108 | ) { |
106 | if let Some(use_tree_list) = tree.use_tree_list() { | 109 | if let Some(use_tree_list) = tree.use_tree_list() { |
107 | let prefix = match tree.path() { | 110 | let prefix = match tree.path() { |
@@ -125,20 +128,18 @@ fn expand_use_tree( | |||
125 | if let Some(segment) = ast_path.segment() { | 128 | if let Some(segment) = ast_path.segment() { |
126 | if segment.kind() == Some(ast::PathSegmentKind::SelfKw) { | 129 | if segment.kind() == Some(ast::PathSegmentKind::SelfKw) { |
127 | if let Some(prefix) = prefix { | 130 | if let Some(prefix) = prefix { |
128 | cb(prefix, Some(segment.syntax().range())); | 131 | cb(prefix, Some(segment)); |
129 | return; | 132 | return; |
130 | } | 133 | } |
131 | } | 134 | } |
132 | } | 135 | } |
133 | } | 136 | } |
134 | if let Some(path) = convert_path(prefix, ast_path) { | 137 | if let Some(path) = convert_path(prefix, ast_path) { |
135 | let range = if tree.has_star() { | 138 | if tree.has_star() { |
136 | None | 139 | cb(path, None) |
137 | } else { | 140 | } else if let Some(segment) = ast_path.segment() { |
138 | let range = ast_path.segment().unwrap().syntax().range(); | 141 | cb(path, Some(segment)) |
139 | Some(range) | ||
140 | }; | 142 | }; |
141 | cb(path, range) | ||
142 | } | 143 | } |
143 | // TODO: report errors somewhere | 144 | // TODO: report errors somewhere |
144 | // We get here if we do | 145 | // We get here if we do |