diff options
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/raw.rs | 15 | ||||
-rw-r--r-- | crates/ra_hir_def/src/path.rs | 7 | ||||
-rw-r--r-- | crates/ra_hir_def/src/path/lower/lower_use.rs | 14 |
4 files changed, 30 insertions, 11 deletions
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 7499dff31..193067f73 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -438,7 +438,10 @@ where | |||
438 | } else { | 438 | } else { |
439 | match import.path.segments.last() { | 439 | match import.path.segments.last() { |
440 | Some(last_segment) => { | 440 | Some(last_segment) => { |
441 | let name = import.alias.clone().unwrap_or_else(|| last_segment.clone()); | 441 | let name = match &import.alias { |
442 | raw::ImportAlias::Alias(name) => name.clone(), | ||
443 | _ => last_segment.clone(), // "use as ;" and "use as _;" are treated the same way | ||
444 | }; | ||
442 | log::debug!("resolved import {:?} ({:?}) to {:?}", name, import, def); | 445 | log::debug!("resolved import {:?} ({:?}) to {:?}", name, import, def); |
443 | 446 | ||
444 | // extern crates in the crate root are special-cased to insert entries into the extern prelude: rust-lang/rust#54658 | 447 | // extern crates in the crate root are special-cased to insert entries into the extern prelude: rust-lang/rust#54658 |
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index fac1169ef..f068b4d4e 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs | |||
@@ -145,7 +145,7 @@ impl_arena_id!(Import); | |||
145 | #[derive(Debug, Clone, PartialEq, Eq)] | 145 | #[derive(Debug, Clone, PartialEq, Eq)] |
146 | pub struct ImportData { | 146 | pub struct ImportData { |
147 | pub(super) path: ModPath, | 147 | pub(super) path: ModPath, |
148 | pub(super) alias: Option<Name>, | 148 | pub(super) alias: ImportAlias, |
149 | pub(super) is_glob: bool, | 149 | pub(super) is_glob: bool, |
150 | pub(super) is_prelude: bool, | 150 | pub(super) is_prelude: bool, |
151 | pub(super) is_extern_crate: bool, | 151 | pub(super) is_extern_crate: bool, |
@@ -153,6 +153,13 @@ pub struct ImportData { | |||
153 | pub(super) visibility: RawVisibility, | 153 | pub(super) visibility: RawVisibility, |
154 | } | 154 | } |
155 | 155 | ||
156 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
157 | pub enum ImportAlias { | ||
158 | NoAlias, | ||
159 | Unnamed, // use Foo as _; | ||
160 | Alias(Name), | ||
161 | } | ||
162 | |||
156 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 163 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
157 | pub(super) struct Def(RawId); | 164 | pub(super) struct Def(RawId); |
158 | impl_arena_id!(Def); | 165 | impl_arena_id!(Def); |
@@ -353,7 +360,11 @@ impl RawItemsCollector { | |||
353 | let path = ModPath::from_name_ref(&name_ref); | 360 | let path = ModPath::from_name_ref(&name_ref); |
354 | let visibility = | 361 | let visibility = |
355 | RawVisibility::from_ast_with_hygiene(extern_crate.visibility(), &self.hygiene); | 362 | RawVisibility::from_ast_with_hygiene(extern_crate.visibility(), &self.hygiene); |
356 | let alias = extern_crate.alias().and_then(|a| a.name()).map(|it| it.as_name()); | 363 | let alias = extern_crate.alias().map_or(ImportAlias::NoAlias, |a| { |
364 | a.name() | ||
365 | .map(|it| it.as_name()) | ||
366 | .map_or(ImportAlias::Unnamed, |a| ImportAlias::Alias(a)) | ||
367 | }); | ||
357 | let attrs = self.parse_attrs(&extern_crate); | 368 | let attrs = self.parse_attrs(&extern_crate); |
358 | // FIXME: cfg_attr | 369 | // FIXME: cfg_attr |
359 | let is_macro_use = extern_crate.has_atom_attr("macro_use"); | 370 | let is_macro_use = extern_crate.has_atom_attr("macro_use"); |
diff --git a/crates/ra_hir_def/src/path.rs b/crates/ra_hir_def/src/path.rs index ab290e2c9..27ccf6643 100644 --- a/crates/ra_hir_def/src/path.rs +++ b/crates/ra_hir_def/src/path.rs | |||
@@ -57,7 +57,12 @@ impl ModPath { | |||
57 | pub(crate) fn expand_use_item( | 57 | pub(crate) fn expand_use_item( |
58 | item_src: InFile<ast::UseItem>, | 58 | item_src: InFile<ast::UseItem>, |
59 | hygiene: &Hygiene, | 59 | hygiene: &Hygiene, |
60 | mut cb: impl FnMut(ModPath, &ast::UseTree, /* is_glob */ bool, Option<Name>), | 60 | mut cb: impl FnMut( |
61 | ModPath, | ||
62 | &ast::UseTree, | ||
63 | /* is_glob */ bool, | ||
64 | crate::nameres::raw::ImportAlias, | ||
65 | ), | ||
61 | ) { | 66 | ) { |
62 | if let Some(tree) = item_src.value.use_tree() { | 67 | if let Some(tree) = item_src.value.use_tree() { |
63 | lower::lower_use_tree(None, tree, hygiene, &mut cb); | 68 | lower::lower_use_tree(None, tree, hygiene, &mut cb); |
diff --git a/crates/ra_hir_def/src/path/lower/lower_use.rs b/crates/ra_hir_def/src/path/lower/lower_use.rs index 531878174..f693cefbc 100644 --- a/crates/ra_hir_def/src/path/lower/lower_use.rs +++ b/crates/ra_hir_def/src/path/lower/lower_use.rs | |||
@@ -4,20 +4,18 @@ | |||
4 | use std::iter; | 4 | use std::iter; |
5 | 5 | ||
6 | use either::Either; | 6 | use either::Either; |
7 | use hir_expand::{ | 7 | use hir_expand::{hygiene::Hygiene, name::AsName}; |
8 | hygiene::Hygiene, | ||
9 | name::{AsName, Name}, | ||
10 | }; | ||
11 | use ra_syntax::ast::{self, NameOwner}; | 8 | use ra_syntax::ast::{self, NameOwner}; |
12 | use test_utils::tested_by; | 9 | use test_utils::tested_by; |
13 | 10 | ||
11 | use crate::nameres::raw::ImportAlias; | ||
14 | use crate::path::{ModPath, PathKind}; | 12 | use crate::path::{ModPath, PathKind}; |
15 | 13 | ||
16 | pub(crate) fn lower_use_tree( | 14 | pub(crate) fn lower_use_tree( |
17 | prefix: Option<ModPath>, | 15 | prefix: Option<ModPath>, |
18 | tree: ast::UseTree, | 16 | tree: ast::UseTree, |
19 | hygiene: &Hygiene, | 17 | hygiene: &Hygiene, |
20 | cb: &mut dyn FnMut(ModPath, &ast::UseTree, bool, Option<Name>), | 18 | cb: &mut dyn FnMut(ModPath, &ast::UseTree, bool, ImportAlias), |
21 | ) { | 19 | ) { |
22 | if let Some(use_tree_list) = tree.use_tree_list() { | 20 | if let Some(use_tree_list) = tree.use_tree_list() { |
23 | let prefix = match tree.path() { | 21 | let prefix = match tree.path() { |
@@ -34,7 +32,9 @@ pub(crate) fn lower_use_tree( | |||
34 | lower_use_tree(prefix.clone(), child_tree, hygiene, cb); | 32 | lower_use_tree(prefix.clone(), child_tree, hygiene, cb); |
35 | } | 33 | } |
36 | } else { | 34 | } else { |
37 | let alias = tree.alias().and_then(|a| a.name()).map(|a| a.as_name()); | 35 | let alias = tree.alias().map_or(ImportAlias::NoAlias, |a| { |
36 | a.name().map(|it| it.as_name()).map_or(ImportAlias::Unnamed, |a| ImportAlias::Alias(a)) | ||
37 | }); | ||
38 | let is_glob = tree.has_star(); | 38 | let is_glob = tree.has_star(); |
39 | if let Some(ast_path) = tree.path() { | 39 | if let Some(ast_path) = tree.path() { |
40 | // Handle self in a path. | 40 | // Handle self in a path. |
@@ -57,7 +57,7 @@ pub(crate) fn lower_use_tree( | |||
57 | } else if is_glob { | 57 | } else if is_glob { |
58 | tested_by!(glob_enum_group); | 58 | tested_by!(glob_enum_group); |
59 | if let Some(prefix) = prefix { | 59 | if let Some(prefix) = prefix { |
60 | cb(prefix, &tree, is_glob, None) | 60 | cb(prefix, &tree, is_glob, ImportAlias::NoAlias) |
61 | } | 61 | } |
62 | } | 62 | } |
63 | } | 63 | } |