aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/nameres
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-02-01 23:49:20 +0000
committerFlorian Diebold <[email protected]>2019-02-04 20:49:34 +0000
commitd69023fc72b26e64ebf1f96fc322a2f7377a5f4d (patch)
tree1e448053268f830a77076069bf26b39694d518d9 /crates/ra_hir/src/nameres
parent397d84ee292295ce1d19033e586467ef9148e5bc (diff)
Lower extern crates to imports
This is probably not completely correct, but it kind of works.
Diffstat (limited to 'crates/ra_hir/src/nameres')
-rw-r--r--crates/ra_hir/src/nameres/lower.rs19
1 files changed, 16 insertions, 3 deletions
diff --git a/crates/ra_hir/src/nameres/lower.rs b/crates/ra_hir/src/nameres/lower.rs
index df87f520f..db898a782 100644
--- a/crates/ra_hir/src/nameres/lower.rs
+++ b/crates/ra_hir/src/nameres/lower.rs
@@ -8,7 +8,7 @@ use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap};
8use rustc_hash::FxHashMap; 8use rustc_hash::FxHashMap;
9 9
10use crate::{ 10use crate::{
11 SourceItemId, Path, ModuleSource, Name, 11 SourceItemId, Path, PathKind, ModuleSource, Name,
12 HirFileId, MacroCallLoc, AsName, PerNs, Function, 12 HirFileId, MacroCallLoc, AsName, PerNs, Function,
13 ModuleDef, Module, Struct, Enum, Const, Static, Trait, Type, 13 ModuleDef, Module, Struct, Enum, Const, Static, Trait, Type,
14 ids::LocationCtx, PersistentHirDatabase, 14 ids::LocationCtx, PersistentHirDatabase,
@@ -186,8 +186,21 @@ impl LoweredModule {
186 ast::ModuleItemKind::UseItem(it) => { 186 ast::ModuleItemKind::UseItem(it) => {
187 self.add_use_item(source_map, it); 187 self.add_use_item(source_map, it);
188 } 188 }
189 ast::ModuleItemKind::ExternCrateItem(_) => { 189 ast::ModuleItemKind::ExternCrateItem(it) => {
190 // TODO 190 // Lower `extern crate x` to `use ::x`. This is kind of cheating
191 // and only works if we always interpret absolute paths in the
192 // 2018 style; otherwise `::x` could also refer to a module in
193 // the crate root.
194 if let Some(name_ref) = it.name_ref() {
195 let mut path = Path::from_name_ref(name_ref);
196 path.kind = PathKind::Abs;
197 let alias = it.alias().and_then(|a| a.name()).map(AsName::as_name);
198 self.imports.alloc(ImportData {
199 path,
200 alias,
201 is_glob: false,
202 });
203 }
191 } 204 }
192 ast::ModuleItemKind::ConstDef(it) => { 205 ast::ModuleItemKind::ConstDef(it) => {
193 if let Some(name) = it.name() { 206 if let Some(name) = it.name() {