refactor $crate handling

Introduce proper hygiene module, which should grow quite a bit
eventually.
This commit is contained in:
Aleksey Kladov 2019-10-30 18:41:50 +03:00
parent e34e71c62d
commit 0bc7d28518
7 changed files with 118 additions and 89 deletions

View file

@ -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> {
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)
}
}

View file

@ -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, &macro_call, db);
let attrs = Attr::from_attrs_owner(&macro_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(&macro_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)
{