From 0bc7d285189caaffc13e4d6856baf895f72ed80c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 30 Oct 2019 18:41:50 +0300 Subject: refactor $crate handling Introduce proper hygiene module, which should grow quite a bit eventually. --- crates/ra_hir/src/expr/lower.rs | 4 +++- crates/ra_hir/src/impl_block.rs | 12 ++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/expr/lower.rs b/crates/ra_hir/src/expr/lower.rs index ad029b868..575d78198 100644 --- a/crates/ra_hir/src/expr/lower.rs +++ b/crates/ra_hir/src/expr/lower.rs @@ -1,6 +1,7 @@ //! FIXME: write short doc here use hir_def::{ + hygiene::Hygiene, name::{self, AsName, Name}, path::GenericArgs, type_ref::TypeRef, @@ -597,7 +598,8 @@ where } fn parse_path(&mut self, path: ast::Path) -> Option { - Path::from_src(Source { ast: path, file_id: self.current_file_id }, self.db) + let hygiene = Hygiene::new(self.db, self.current_file_id); + Path::from_src(path, &hygiene) } } diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index 518330713..9e4a40017 100644 --- a/crates/ra_hir/src/impl_block.rs +++ b/crates/ra_hir/src/impl_block.rs @@ -3,7 +3,7 @@ use rustc_hash::FxHashMap; use std::sync::Arc; -use hir_def::{attr::Attr, type_ref::TypeRef}; +use hir_def::{attr::Attr, hygiene::Hygiene, type_ref::TypeRef}; use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; use ra_cfg::CfgOptions; use ra_syntax::{ @@ -227,10 +227,11 @@ impl ModuleImplBlocks { owner: &dyn ast::ModuleItemOwner, file_id: HirFileId, ) { + let hygiene = Hygiene::new(db, file_id); for item in owner.items_with_macros() { match item { ast::ItemOrMacro::Item(ast::ModuleItem::ImplBlock(impl_block_ast)) => { - let attrs = Attr::from_attrs_owner(file_id, &impl_block_ast, db); + let attrs = Attr::from_attrs_owner(&impl_block_ast, &hygiene); if attrs.map_or(false, |attrs| { attrs.iter().any(|attr| attr.is_cfg_enabled(cfg_options) == Some(false)) }) { @@ -247,7 +248,7 @@ impl ModuleImplBlocks { } ast::ItemOrMacro::Item(_) => (), ast::ItemOrMacro::Macro(macro_call) => { - let attrs = Attr::from_attrs_owner(file_id, ¯o_call, db); + let attrs = Attr::from_attrs_owner(¯o_call, &hygiene); if attrs.map_or(false, |attrs| { attrs.iter().any(|attr| attr.is_cfg_enabled(cfg_options) == Some(false)) }) { @@ -256,9 +257,8 @@ impl ModuleImplBlocks { //FIXME: we should really cut down on the boilerplate required to process a macro let ast_id = AstId::new(file_id, db.ast_id_map(file_id).ast_id(¯o_call)); - if let Some(path) = macro_call - .path() - .and_then(|path| Path::from_src(Source { ast: path, file_id }, db)) + if let Some(path) = + macro_call.path().and_then(|path| Path::from_src(path, &hygiene)) { if let Some(def) = self.module.resolver(db).resolve_path_as_macro(db, &path) { -- cgit v1.2.3