mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-04 12:44:40 +00:00
Lower extern crates to imports
This is probably not completely correct, but it kind of works.
This commit is contained in:
parent
397d84ee29
commit
d69023fc72
@ -8,7 +8,7 @@ use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap};
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
use crate::{
|
||||
SourceItemId, Path, ModuleSource, Name,
|
||||
SourceItemId, Path, PathKind, ModuleSource, Name,
|
||||
HirFileId, MacroCallLoc, AsName, PerNs, Function,
|
||||
ModuleDef, Module, Struct, Enum, Const, Static, Trait, Type,
|
||||
ids::LocationCtx, PersistentHirDatabase,
|
||||
@ -186,8 +186,21 @@ impl LoweredModule {
|
||||
ast::ModuleItemKind::UseItem(it) => {
|
||||
self.add_use_item(source_map, it);
|
||||
}
|
||||
ast::ModuleItemKind::ExternCrateItem(_) => {
|
||||
// TODO
|
||||
ast::ModuleItemKind::ExternCrateItem(it) => {
|
||||
// Lower `extern crate x` to `use ::x`. This is kind of cheating
|
||||
// and only works if we always interpret absolute paths in the
|
||||
// 2018 style; otherwise `::x` could also refer to a module in
|
||||
// the crate root.
|
||||
if let Some(name_ref) = it.name_ref() {
|
||||
let mut path = Path::from_name_ref(name_ref);
|
||||
path.kind = PathKind::Abs;
|
||||
let alias = it.alias().and_then(|a| a.name()).map(AsName::as_name);
|
||||
self.imports.alloc(ImportData {
|
||||
path,
|
||||
alias,
|
||||
is_glob: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
ast::ModuleItemKind::ConstDef(it) => {
|
||||
if let Some(name) = it.name() {
|
||||
|
Loading…
Reference in New Issue
Block a user