diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-02 08:20:50 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-02 08:20:50 +0000 |
commit | da3802b2ce4796461a9fff22f4e9c6fd890879b2 (patch) | |
tree | b3df38ae7b749178d854be9f2e6b16070a373216 /crates/ra_hir/src/nameres | |
parent | 4447019f4b5f24728bb7b91b161755ddb373c74c (diff) | |
parent | d8ef8acb47b1be92da97a2d5cd4334bceed5b919 (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/nameres')
-rw-r--r-- | crates/ra_hir/src/nameres/lower.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/tests.rs | 24 |
2 files changed, 27 insertions, 1 deletions
diff --git a/crates/ra_hir/src/nameres/lower.rs b/crates/ra_hir/src/nameres/lower.rs index 9a45fa61c..df87f520f 100644 --- a/crates/ra_hir/src/nameres/lower.rs +++ b/crates/ra_hir/src/nameres/lower.rs | |||
@@ -21,6 +21,7 @@ impl_arena_id!(ImportId); | |||
21 | #[derive(Debug, PartialEq, Eq)] | 21 | #[derive(Debug, PartialEq, Eq)] |
22 | pub(super) struct ImportData { | 22 | pub(super) struct ImportData { |
23 | pub(super) path: Path, | 23 | pub(super) path: Path, |
24 | pub(super) alias: Option<Name>, | ||
24 | pub(super) is_glob: bool, | 25 | pub(super) is_glob: bool, |
25 | } | 26 | } |
26 | 27 | ||
@@ -209,9 +210,10 @@ impl LoweredModule { | |||
209 | } | 210 | } |
210 | 211 | ||
211 | fn add_use_item(&mut self, source_map: &mut ImportSourceMap, item: &ast::UseItem) { | 212 | fn add_use_item(&mut self, source_map: &mut ImportSourceMap, item: &ast::UseItem) { |
212 | Path::expand_use_item(item, |path, segment| { | 213 | Path::expand_use_item(item, |path, segment, alias| { |
213 | let import = self.imports.alloc(ImportData { | 214 | let import = self.imports.alloc(ImportData { |
214 | path, | 215 | path, |
216 | alias, | ||
215 | is_glob: segment.is_none(), | 217 | is_glob: segment.is_none(), |
216 | }); | 218 | }); |
217 | if let Some(segment) = segment { | 219 | if let Some(segment) = segment { |
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index 0e0683db7..81c8a4f12 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs | |||
@@ -91,6 +91,30 @@ fn item_map_smoke_test() { | |||
91 | } | 91 | } |
92 | 92 | ||
93 | #[test] | 93 | #[test] |
94 | fn use_as() { | ||
95 | let (item_map, module_id) = item_map( | ||
96 | " | ||
97 | //- /lib.rs | ||
98 | mod foo; | ||
99 | |||
100 | use crate::foo::Baz as Foo; | ||
101 | <|> | ||
102 | |||
103 | //- /foo/mod.rs | ||
104 | pub struct Baz; | ||
105 | ", | ||
106 | ); | ||
107 | check_module_item_map( | ||
108 | &item_map, | ||
109 | module_id, | ||
110 | " | ||
111 | Foo: t v | ||
112 | foo: t | ||
113 | ", | ||
114 | ); | ||
115 | } | ||
116 | |||
117 | #[test] | ||
94 | fn use_trees() { | 118 | fn use_trees() { |
95 | let (item_map, module_id) = item_map( | 119 | let (item_map, module_id) = item_map( |
96 | " | 120 | " |