aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/path.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-02-02 08:20:50 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-02-02 08:20:50 +0000
commitda3802b2ce4796461a9fff22f4e9c6fd890879b2 (patch)
treeb3df38ae7b749178d854be9f2e6b16070a373216 /crates/ra_hir/src/path.rs
parent4447019f4b5f24728bb7b91b161755ddb373c74c (diff)
parentd8ef8acb47b1be92da97a2d5cd4334bceed5b919 (diff)
Merge #725
725: Implement `use as` r=matklad a=flodiebold Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/path.rs')
-rw-r--r--crates/ra_hir/src/path.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/crates/ra_hir/src/path.rs b/crates/ra_hir/src/path.rs
index e13d84c57..cb0a04500 100644
--- a/crates/ra_hir/src/path.rs
+++ b/crates/ra_hir/src/path.rs
@@ -1,6 +1,6 @@
1use std::sync::Arc; 1use std::sync::Arc;
2 2
3use ra_syntax::{ast, AstNode}; 3use ra_syntax::{ast::{self, NameOwner}, AstNode};
4 4
5use crate::{Name, AsName, type_ref::TypeRef}; 5use crate::{Name, AsName, type_ref::TypeRef};
6 6
@@ -46,7 +46,7 @@ impl Path {
46 /// Calls `cb` with all paths, represented by this use item. 46 /// Calls `cb` with all paths, represented by this use item.
47 pub fn expand_use_item<'a>( 47 pub fn expand_use_item<'a>(
48 item: &'a ast::UseItem, 48 item: &'a ast::UseItem,
49 mut cb: impl FnMut(Path, Option<&'a ast::PathSegment>), 49 mut cb: impl FnMut(Path, Option<&'a ast::PathSegment>, Option<Name>),
50 ) { 50 ) {
51 if let Some(tree) = item.use_tree() { 51 if let Some(tree) = item.use_tree() {
52 expand_use_tree(None, tree, &mut cb); 52 expand_use_tree(None, tree, &mut cb);
@@ -164,7 +164,7 @@ impl From<Name> for Path {
164fn expand_use_tree<'a>( 164fn expand_use_tree<'a>(
165 prefix: Option<Path>, 165 prefix: Option<Path>,
166 tree: &'a ast::UseTree, 166 tree: &'a ast::UseTree,
167 cb: &mut impl FnMut(Path, Option<&'a ast::PathSegment>), 167 cb: &mut impl FnMut(Path, Option<&'a ast::PathSegment>, Option<Name>),
168) { 168) {
169 if let Some(use_tree_list) = tree.use_tree_list() { 169 if let Some(use_tree_list) = tree.use_tree_list() {
170 let prefix = match tree.path() { 170 let prefix = match tree.path() {
@@ -181,6 +181,7 @@ fn expand_use_tree<'a>(
181 expand_use_tree(prefix.clone(), child_tree, cb); 181 expand_use_tree(prefix.clone(), child_tree, cb);
182 } 182 }
183 } else { 183 } else {
184 let alias = tree.alias().and_then(|a| a.name()).map(|a| a.as_name());
184 if let Some(ast_path) = tree.path() { 185 if let Some(ast_path) = tree.path() {
185 // Handle self in a path. 186 // Handle self in a path.
186 // E.g. `use something::{self, <...>}` 187 // E.g. `use something::{self, <...>}`
@@ -188,7 +189,7 @@ fn expand_use_tree<'a>(
188 if let Some(segment) = ast_path.segment() { 189 if let Some(segment) = ast_path.segment() {
189 if segment.kind() == Some(ast::PathSegmentKind::SelfKw) { 190 if segment.kind() == Some(ast::PathSegmentKind::SelfKw) {
190 if let Some(prefix) = prefix { 191 if let Some(prefix) = prefix {
191 cb(prefix, Some(segment)); 192 cb(prefix, Some(segment), alias);
192 return; 193 return;
193 } 194 }
194 } 195 }
@@ -196,9 +197,9 @@ fn expand_use_tree<'a>(
196 } 197 }
197 if let Some(path) = convert_path(prefix, ast_path) { 198 if let Some(path) = convert_path(prefix, ast_path) {
198 if tree.has_star() { 199 if tree.has_star() {
199 cb(path, None) 200 cb(path, None, alias)
200 } else if let Some(segment) = ast_path.segment() { 201 } else if let Some(segment) = ast_path.segment() {
201 cb(path, Some(segment)) 202 cb(path, Some(segment), alias)
202 }; 203 };
203 } 204 }
204 // TODO: report errors somewhere 205 // TODO: report errors somewhere