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') 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 From b05d6e53fb0e9a008dc2e1220b1201818e63ed2d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 30 Oct 2019 18:50:10 +0300 Subject: push either to hir_expand --- crates/ra_hir/src/lib.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index f765490b0..989818c0e 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -60,6 +60,13 @@ use crate::{ids::MacroFileKind, resolve::Resolver}; pub use crate::{ adt::VariantDef, + code_model::{ + docs::{DocDef, Docs, Documentation}, + src::{HasBodySource, HasSource, Source}, + Adt, AssocItem, BuiltinType, Const, ConstData, Container, Crate, CrateDependency, + DefWithBody, Enum, EnumVariant, FieldSource, FnData, Function, HasBody, MacroDef, Module, + ModuleDef, ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, + }, expr::ExprScopes, from_source::FromSource, generics::{GenericDef, GenericParam, GenericParams, HasGenericParams}, @@ -73,17 +80,9 @@ pub use crate::{ }, }; -pub use self::code_model::{ - docs::{DocDef, Docs, Documentation}, - src::{HasBodySource, HasSource, Source}, - Adt, AssocItem, BuiltinType, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, - Enum, EnumVariant, FieldSource, FnData, Function, HasBody, MacroDef, Module, ModuleDef, - ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, -}; - pub use hir_def::{ - either::Either, name::Name, path::{Path, PathKind}, type_ref::Mutability, }; +pub use hir_expand::either::Either; -- cgit v1.2.3 From 872ac566bfc6cf43ac55354cf5223b962dbc1d92 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 30 Oct 2019 18:56:20 +0300 Subject: push name down to hir_expand --- crates/ra_hir/src/adt.rs | 3 ++- crates/ra_hir/src/code_model.rs | 8 ++++---- crates/ra_hir/src/expr/lower.rs | 8 ++------ crates/ra_hir/src/from_source.rs | 2 +- crates/ra_hir/src/generics.rs | 2 +- crates/ra_hir/src/lib.rs | 3 +-- crates/ra_hir/src/nameres/collector.rs | 3 ++- crates/ra_hir/src/resolve.rs | 2 +- crates/ra_hir/src/source_binder.rs | 3 ++- crates/ra_hir/src/traits.rs | 3 ++- crates/ra_hir/src/ty/autoderef.rs | 2 +- crates/ra_hir/src/ty/infer.rs | 2 +- crates/ra_hir/src/ty/infer/expr.rs | 6 ++---- crates/ra_hir/src/ty/traits/chalk.rs | 3 ++- crates/ra_hir/src/type_alias.rs | 7 +++---- 15 files changed, 27 insertions(+), 30 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs index d16b3a1cc..97424b39e 100644 --- a/crates/ra_hir/src/adt.rs +++ b/crates/ra_hir/src/adt.rs @@ -3,7 +3,8 @@ use std::sync::Arc; -use hir_def::{name::AsName, type_ref::TypeRef}; +use hir_def::type_ref::TypeRef; +use hir_expand::name::AsName; use ra_arena::{impl_arena_id, Arena, RawId}; use ra_syntax::ast::{self, NameOwner, StructKind, TypeAscriptionOwner}; diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index d865c972e..a6ce23dd1 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -6,13 +6,13 @@ pub(crate) mod docs; use std::sync::Arc; use hir_def::{ - name::{ - self, AsName, BOOL, CHAR, F32, F64, I128, I16, I32, I64, I8, ISIZE, SELF_TYPE, STR, U128, - U16, U32, U64, U8, USIZE, - }, type_ref::{Mutability, TypeRef}, CrateModuleId, ModuleId, }; +use hir_expand::name::{ + self, AsName, BOOL, CHAR, F32, F64, I128, I16, I32, I64, I8, ISIZE, SELF_TYPE, STR, U128, U16, + U32, U64, U8, USIZE, +}; use ra_db::{CrateId, Edition}; use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; diff --git a/crates/ra_hir/src/expr/lower.rs b/crates/ra_hir/src/expr/lower.rs index 575d78198..241ad68fd 100644 --- a/crates/ra_hir/src/expr/lower.rs +++ b/crates/ra_hir/src/expr/lower.rs @@ -1,11 +1,7 @@ //! FIXME: write short doc here -use hir_def::{ - hygiene::Hygiene, - name::{self, AsName, Name}, - path::GenericArgs, - type_ref::TypeRef, -}; +use hir_def::{hygiene::Hygiene, path::GenericArgs, type_ref::TypeRef}; +use hir_expand::name::{self, AsName, Name}; use ra_arena::Arena; use ra_syntax::{ ast::{ diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs index b9fbaa367..a9de01455 100644 --- a/crates/ra_hir/src/from_source.rs +++ b/crates/ra_hir/src/from_source.rs @@ -1,6 +1,6 @@ //! FIXME: write short doc here -use hir_def::name::AsName; +use hir_expand::name::AsName; use ra_syntax::ast::{self, AstNode, NameOwner}; use crate::{ diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs index 9d5d18564..52e1fbf29 100644 --- a/crates/ra_hir/src/generics.rs +++ b/crates/ra_hir/src/generics.rs @@ -6,10 +6,10 @@ use std::sync::Arc; use hir_def::{ - name::{self, AsName}, path::Path, type_ref::{TypeBound, TypeRef}, }; +use hir_expand::name::{self, AsName}; use ra_syntax::ast::{self, DefaultTypeParamOwner, NameOwner, TypeBoundsOwner, TypeParamsOwner}; use crate::{ diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 989818c0e..603b0c3dc 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -81,8 +81,7 @@ pub use crate::{ }; pub use hir_def::{ - name::Name, path::{Path, PathKind}, type_ref::Mutability, }; -pub use hir_expand::either::Either; +pub use hir_expand::{either::Either, name::Name}; diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index 2f342870b..e2e13805a 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs @@ -1,6 +1,7 @@ //! FIXME: write short doc here -use hir_def::{attr::Attr, name, nameres::raw}; +use hir_def::{attr::Attr, nameres::raw}; +use hir_expand::name; use ra_cfg::CfgOptions; use ra_db::FileId; use ra_syntax::{ast, SmolStr}; diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index 2a783b61e..f77c9df9f 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs @@ -2,10 +2,10 @@ use std::sync::Arc; use hir_def::{ - name::{self, Name}, path::{Path, PathKind}, CrateModuleId, }; +use hir_expand::name::{self, Name}; use rustc_hash::FxHashSet; use crate::{ diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 544433a0a..01f51ba5d 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -7,7 +7,8 @@ //! purely for "IDE needs". use std::sync::Arc; -use hir_def::{name::AsName, path::known}; +use hir_def::path::known; +use hir_expand::name::AsName; use ra_db::FileId; use ra_syntax::{ ast::{self, AstNode}, diff --git a/crates/ra_hir/src/traits.rs b/crates/ra_hir/src/traits.rs index 514c813ab..1a45dacba 100644 --- a/crates/ra_hir/src/traits.rs +++ b/crates/ra_hir/src/traits.rs @@ -2,7 +2,8 @@ use std::sync::Arc; -use hir_def::name::AsName; +use hir_expand::name::AsName; + use ra_syntax::ast::{self, NameOwner}; use rustc_hash::FxHashMap; diff --git a/crates/ra_hir/src/ty/autoderef.rs b/crates/ra_hir/src/ty/autoderef.rs index 03c45546d..3645ee831 100644 --- a/crates/ra_hir/src/ty/autoderef.rs +++ b/crates/ra_hir/src/ty/autoderef.rs @@ -5,7 +5,7 @@ use std::iter::successors; -use hir_def::name; +use hir_expand::name; use log::{info, warn}; use super::{traits::Solution, Canonical, Substs, Ty, TypeWalk}; diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 7466ee341..6694467a3 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -22,10 +22,10 @@ use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue}; use rustc_hash::FxHashMap; use hir_def::{ - name, path::known, type_ref::{Mutability, TypeRef}, }; +use hir_expand::name; use ra_arena::map::ArenaMap; use ra_prof::profile; use test_utils::tested_by; diff --git a/crates/ra_hir/src/ty/infer/expr.rs b/crates/ra_hir/src/ty/infer/expr.rs index bc6437b44..fed52df39 100644 --- a/crates/ra_hir/src/ty/infer/expr.rs +++ b/crates/ra_hir/src/ty/infer/expr.rs @@ -3,10 +3,8 @@ use std::iter::{repeat, repeat_with}; use std::sync::Arc; -use hir_def::{ - name, - path::{GenericArg, GenericArgs}, -}; +use hir_def::path::{GenericArg, GenericArgs}; +use hir_expand::name; use super::{BindingMode, Expectation, InferenceContext, InferenceDiagnostic, TypeMismatch}; use crate::{ diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs index 2dd4c2fae..39ef92182 100644 --- a/crates/ra_hir/src/ty/traits/chalk.rs +++ b/crates/ra_hir/src/ty/traits/chalk.rs @@ -9,7 +9,8 @@ use chalk_ir::{ }; use chalk_rust_ir::{AssociatedTyDatum, ImplDatum, StructDatum, TraitDatum}; -use hir_def::name; +use hir_expand::name; + use ra_db::salsa::{InternId, InternKey}; use super::{Canonical, ChalkContext, Impl, Obligation}; diff --git a/crates/ra_hir/src/type_alias.rs b/crates/ra_hir/src/type_alias.rs index 87126ee7f..078e6295e 100644 --- a/crates/ra_hir/src/type_alias.rs +++ b/crates/ra_hir/src/type_alias.rs @@ -2,10 +2,9 @@ use std::sync::Arc; -use hir_def::{ - name::{AsName, Name}, - type_ref::TypeRef, -}; +use hir_def::type_ref::TypeRef; +use hir_expand::name::{AsName, Name}; + use ra_syntax::ast::NameOwner; use crate::{ -- cgit v1.2.3 From ab559f170ee02e3bdd9aeeb55933bb143b520c34 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 30 Oct 2019 19:10:53 +0300 Subject: move hygiene to hir_expand --- crates/ra_hir/src/expr/lower.rs | 7 +++++-- crates/ra_hir/src/impl_block.rs | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/expr/lower.rs b/crates/ra_hir/src/expr/lower.rs index 241ad68fd..6463dd65e 100644 --- a/crates/ra_hir/src/expr/lower.rs +++ b/crates/ra_hir/src/expr/lower.rs @@ -1,7 +1,10 @@ //! FIXME: write short doc here -use hir_def::{hygiene::Hygiene, path::GenericArgs, type_ref::TypeRef}; -use hir_expand::name::{self, AsName, Name}; +use hir_def::{path::GenericArgs, type_ref::TypeRef}; +use hir_expand::{ + hygiene::Hygiene, + name::{self, AsName, Name}, +}; use ra_arena::Arena; use ra_syntax::{ ast::{ diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index 9e4a40017..b1a014074 100644 --- a/crates/ra_hir/src/impl_block.rs +++ b/crates/ra_hir/src/impl_block.rs @@ -3,7 +3,8 @@ use rustc_hash::FxHashMap; use std::sync::Arc; -use hir_def::{attr::Attr, hygiene::Hygiene, type_ref::TypeRef}; +use hir_def::{attr::Attr, type_ref::TypeRef}; +use hir_expand::hygiene::Hygiene; use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; use ra_cfg::CfgOptions; use ra_syntax::{ -- cgit v1.2.3