From 1526eb25c98fd16a9c0d114d0ed44e8fec1cc19c Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 10 Feb 2019 20:44:34 +0100 Subject: Import the prelude --- crates/ra_hir/src/nameres/lower.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'crates/ra_hir/src/nameres/lower.rs') diff --git a/crates/ra_hir/src/nameres/lower.rs b/crates/ra_hir/src/nameres/lower.rs index 3cd496d7f..922dbe9c1 100644 --- a/crates/ra_hir/src/nameres/lower.rs +++ b/crates/ra_hir/src/nameres/lower.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use ra_syntax::{ AstNode, SourceFile, TreeArc, AstPtr, - ast::{self, ModuleItemOwner, NameOwner}, + ast::{self, ModuleItemOwner, NameOwner, AttrsOwner}, }; use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap}; use rustc_hash::FxHashMap; @@ -23,6 +23,7 @@ pub(super) struct ImportData { pub(super) path: Path, pub(super) alias: Option, pub(super) is_glob: bool, + pub(super) is_prelude: bool, pub(super) is_extern_crate: bool, } @@ -191,6 +192,7 @@ impl LoweredModule { path, alias, is_glob: false, + is_prelude: false, is_extern_crate: true, }); } @@ -214,11 +216,14 @@ impl LoweredModule { } fn add_use_item(&mut self, source_map: &mut ImportSourceMap, item: &ast::UseItem) { + let is_prelude = + item.attrs().any(|attr| attr.as_atom().map(|s| s == "prelude_import").unwrap_or(false)); Path::expand_use_item(item, |path, segment, alias| { let import = self.imports.alloc(ImportData { path, alias, is_glob: segment.is_none(), + is_prelude, is_extern_crate: false, }); if let Some(segment) = segment { -- cgit v1.2.3 From 92c595a6a6f7624092432d28ffd7e0ffd189cbda Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Wed, 13 Feb 2019 20:42:43 +0100 Subject: Handle extern crates better, so they work correctly in 2015 edition (see the removed comment.) --- crates/ra_hir/src/nameres/lower.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'crates/ra_hir/src/nameres/lower.rs') diff --git a/crates/ra_hir/src/nameres/lower.rs b/crates/ra_hir/src/nameres/lower.rs index 922dbe9c1..81d80654c 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}; use rustc_hash::FxHashMap; use crate::{ - SourceItemId, Path, PathKind, ModuleSource, Name, + SourceItemId, Path, ModuleSource, Name, HirFileId, MacroCallLoc, AsName, PerNs, Function, ModuleDef, Module, Struct, Enum, Const, Static, Trait, Type, ids::LocationCtx, PersistentHirDatabase, @@ -180,13 +180,8 @@ impl LoweredModule { self.add_use_item(source_map, it); } 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 path = Path::from_name_ref(name_ref); let alias = it.alias().and_then(|a| a.name()).map(AsName::as_name); self.imports.alloc(ImportData { path, -- cgit v1.2.3