From 16e620c052016010b2f17070a98bdc1e7e849ab3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 30 Oct 2019 16:12:55 +0300 Subject: move raw_items to hir_def --- crates/ra_hir/src/attr.rs | 91 +---- crates/ra_hir/src/code_model.rs | 30 +- crates/ra_hir/src/db.rs | 17 +- crates/ra_hir/src/either.rs | 55 +-- crates/ra_hir/src/from_source.rs | 42 +-- crates/ra_hir/src/lib.rs | 5 +- crates/ra_hir/src/marks.rs | 1 + crates/ra_hir/src/mock.rs | 1 + crates/ra_hir/src/name.rs | 143 +------- crates/ra_hir/src/nameres.rs | 11 +- crates/ra_hir/src/nameres/collector.rs | 3 +- crates/ra_hir/src/nameres/raw.rs | 403 --------------------- crates/ra_hir/src/nameres/tests/mod_resolution.rs | 2 +- crates/ra_hir/src/path.rs | 423 +--------------------- crates/ra_hir/src/type_ref.rs | 163 +-------- 15 files changed, 23 insertions(+), 1367 deletions(-) delete mode 100644 crates/ra_hir/src/nameres/raw.rs (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/attr.rs b/crates/ra_hir/src/attr.rs index bd159a566..988a671b8 100644 --- a/crates/ra_hir/src/attr.rs +++ b/crates/ra_hir/src/attr.rs @@ -1,90 +1 @@ -//! A higher level attributes based on TokenTree, with also some shortcuts. - -use std::sync::Arc; - -use mbe::ast_to_token_tree; -use ra_cfg::CfgOptions; -use ra_syntax::{ - ast::{self, AstNode, AttrsOwner}, - SmolStr, -}; -use tt::Subtree; - -use crate::{db::AstDatabase, path::Path, HirFileId, Source}; - -#[derive(Debug, Clone, PartialEq, Eq)] -pub(crate) struct Attr { - pub(crate) path: Path, - pub(crate) input: Option, -} - -#[derive(Debug, Clone, PartialEq, Eq)] -pub enum AttrInput { - Literal(SmolStr), - TokenTree(Subtree), -} - -impl Attr { - pub(crate) fn from_src( - Source { file_id, ast }: Source, - db: &impl AstDatabase, - ) -> Option { - let path = Path::from_src(Source { file_id, ast: ast.path()? }, db)?; - let input = match ast.input() { - None => None, - Some(ast::AttrInput::Literal(lit)) => { - // FIXME: escape? raw string? - let value = lit.syntax().first_token()?.text().trim_matches('"').into(); - Some(AttrInput::Literal(value)) - } - Some(ast::AttrInput::TokenTree(tt)) => { - Some(AttrInput::TokenTree(ast_to_token_tree(&tt)?.0)) - } - }; - - Some(Attr { path, input }) - } - - pub(crate) fn from_attrs_owner( - file_id: HirFileId, - owner: &dyn AttrsOwner, - db: &impl AstDatabase, - ) -> Option> { - let mut attrs = owner.attrs().peekable(); - if attrs.peek().is_none() { - // Avoid heap allocation - return None; - } - Some(attrs.flat_map(|ast| Attr::from_src(Source { file_id, ast }, db)).collect()) - } - - pub(crate) fn is_simple_atom(&self, name: &str) -> bool { - // FIXME: Avoid cloning - self.path.as_ident().map_or(false, |s| s.to_string() == name) - } - - // FIXME: handle cfg_attr :-) - pub(crate) fn as_cfg(&self) -> Option<&Subtree> { - if !self.is_simple_atom("cfg") { - return None; - } - match &self.input { - Some(AttrInput::TokenTree(subtree)) => Some(subtree), - _ => None, - } - } - - pub(crate) fn as_path(&self) -> Option<&SmolStr> { - if !self.is_simple_atom("path") { - return None; - } - match &self.input { - Some(AttrInput::Literal(it)) => Some(it), - _ => None, - } - } - - pub(crate) fn is_cfg_enabled(&self, cfg_options: &CfgOptions) -> Option { - cfg_options.is_cfg_enabled(self.as_cfg()?) - } -} +pub use hir_def::attr::*; diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 1a790b2f3..de1377aa4 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -6,7 +6,7 @@ pub(crate) mod docs; use std::sync::Arc; use hir_def::{CrateModuleId, ModuleId}; -use ra_db::{CrateId, Edition, FileId}; +use ra_db::{CrateId, Edition}; use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; use crate::{ @@ -33,7 +33,7 @@ use crate::{ }, type_ref::Mutability, type_ref::TypeRef, - AsName, AstId, Either, HasSource, Name, Ty, + AsName, Either, HasSource, Name, Ty, }; /// hir::Crate describes a single crate. It's the main interface with which @@ -147,31 +147,7 @@ impl_froms!( BuiltinType ); -pub enum ModuleSource { - SourceFile(ast::SourceFile), - Module(ast::Module), -} - -impl ModuleSource { - pub(crate) fn new( - db: &(impl DefDatabase + AstDatabase), - file_id: Option, - decl_id: Option>, - ) -> ModuleSource { - match (file_id, decl_id) { - (Some(file_id), _) => { - let source_file = db.parse(file_id).tree(); - ModuleSource::SourceFile(source_file) - } - (None, Some(item_id)) => { - let module = item_id.to_node(db); - assert!(module.item_list().is_some(), "expected inline module"); - ModuleSource::Module(module) - } - (None, None) => panic!(), - } - } -} +pub use hir_def::ModuleSource; impl Module { pub(crate) fn new(krate: Crate, crate_module_id: CrateModuleId) -> Module { diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index 8f6cb2da7..142d7338d 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -12,15 +12,15 @@ use crate::{ ids, impl_block::{ImplBlock, ImplSourceMap, ModuleImplBlocks}, lang_item::{LangItemTarget, LangItems}, - nameres::{CrateDefMap, ImportSourceMap, Namespace, RawItems}, + nameres::{CrateDefMap, Namespace}, traits::TraitData, ty::{ method_resolution::CrateImplBlocks, traits::Impl, CallableDef, FnSig, GenericPredicate, InferenceResult, Substs, Ty, TypableDef, TypeCtor, }, type_alias::TypeAliasData, - Const, ConstData, Crate, DefWithBody, Enum, ExprScopes, FnData, Function, HirFileId, Module, - Static, Struct, StructField, Trait, TypeAlias, + Const, ConstData, Crate, DefWithBody, Enum, ExprScopes, FnData, Function, Module, Static, + Struct, StructField, Trait, TypeAlias, }; pub use hir_def::db::{InternDatabase, InternDatabaseStorage}; @@ -32,7 +32,7 @@ pub use hir_expand::db::{ // This database uses `AstDatabase` internally, #[salsa::query_group(DefDatabaseStorage)] #[salsa::requires(AstDatabase)] -pub trait DefDatabase: InternDatabase + HirDebugDatabase + AstDatabase { +pub trait DefDatabase: HirDebugDatabase + hir_def::db::DefDatabase2 { #[salsa::invoke(crate::adt::StructData::struct_data_query)] fn struct_data(&self, s: Struct) -> Arc; @@ -45,15 +45,6 @@ pub trait DefDatabase: InternDatabase + HirDebugDatabase + AstDatabase { #[salsa::invoke(crate::traits::TraitItemsIndex::trait_items_index)] fn trait_items_index(&self, module: Module) -> crate::traits::TraitItemsIndex; - #[salsa::invoke(RawItems::raw_items_with_source_map_query)] - fn raw_items_with_source_map( - &self, - file_id: HirFileId, - ) -> (Arc, Arc); - - #[salsa::invoke(RawItems::raw_items_query)] - fn raw_items(&self, file_id: HirFileId) -> Arc; - #[salsa::invoke(CrateDefMap::crate_def_map_query)] fn crate_def_map(&self, krate: Crate) -> Arc; diff --git a/crates/ra_hir/src/either.rs b/crates/ra_hir/src/either.rs index 83583ef8b..44498dd38 100644 --- a/crates/ra_hir/src/either.rs +++ b/crates/ra_hir/src/either.rs @@ -1,54 +1 @@ -//! FIXME: write short doc here - -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub enum Either { - A(A), - B(B), -} - -impl Either { - pub fn either(self, f1: F1, f2: F2) -> R - where - F1: FnOnce(A) -> R, - F2: FnOnce(B) -> R, - { - match self { - Either::A(a) => f1(a), - Either::B(b) => f2(b), - } - } - pub fn map(self, f1: F1, f2: F2) -> Either - where - F1: FnOnce(A) -> U, - F2: FnOnce(B) -> V, - { - match self { - Either::A(a) => Either::A(f1(a)), - Either::B(b) => Either::B(f2(b)), - } - } - pub fn map_a(self, f: F) -> Either - where - F: FnOnce(A) -> U, - { - self.map(f, |it| it) - } - pub fn a(self) -> Option { - match self { - Either::A(it) => Some(it), - Either::B(_) => None, - } - } - pub fn b(self) -> Option { - match self { - Either::A(_) => None, - Either::B(it) => Some(it), - } - } - pub fn as_ref(&self) -> Either<&A, &B> { - match self { - Either::A(it) => Either::A(it), - Either::B(it) => Either::B(it), - } - } -} +pub use hir_def::either::*; diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs index 93713bb14..697c8dc84 100644 --- a/crates/ra_hir/src/from_source.rs +++ b/crates/ra_hir/src/from_source.rs @@ -1,11 +1,6 @@ //! FIXME: write short doc here -use ra_db::{FileId, FilePosition}; -use ra_syntax::{ - algo::find_node_at_offset, - ast::{self, AstNode, NameOwner}, - SyntaxNode, -}; +use ra_syntax::ast::{self, AstNode, NameOwner}; use crate::{ db::{AstDatabase, DefDatabase, HirDatabase}, @@ -129,41 +124,6 @@ impl FromSource for StructField { } } -// FIXME: simplify it -impl ModuleSource { - pub fn from_position( - db: &(impl DefDatabase + AstDatabase), - position: FilePosition, - ) -> ModuleSource { - let parse = db.parse(position.file_id); - match &find_node_at_offset::(parse.tree().syntax(), position.offset) { - Some(m) if !m.has_semi() => ModuleSource::Module(m.clone()), - _ => { - let source_file = parse.tree(); - ModuleSource::SourceFile(source_file) - } - } - } - - pub fn from_child_node( - db: &(impl DefDatabase + AstDatabase), - file_id: FileId, - child: &SyntaxNode, - ) -> ModuleSource { - if let Some(m) = child.ancestors().filter_map(ast::Module::cast).find(|it| !it.has_semi()) { - ModuleSource::Module(m) - } else { - let source_file = db.parse(file_id).tree(); - ModuleSource::SourceFile(source_file) - } - } - - pub fn from_file_id(db: &(impl DefDatabase + AstDatabase), file_id: FileId) -> ModuleSource { - let source_file = db.parse(file_id).tree(); - ModuleSource::SourceFile(source_file) - } -} - impl Module { pub fn from_declaration(db: &impl HirDatabase, src: Source) -> Option { let src_parent = Source { diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 0f2d233bb..b49f615bf 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -59,10 +59,7 @@ pub mod from_source; #[cfg(test)] mod marks; -use hir_expand::{ - ast_id_map::{AstIdMap, FileAstId}, - AstId, -}; +use hir_expand::AstId; use crate::{ids::MacroFileKind, name::AsName, resolve::Resolver}; diff --git a/crates/ra_hir/src/marks.rs b/crates/ra_hir/src/marks.rs index 79af24b20..b423489a1 100644 --- a/crates/ra_hir/src/marks.rs +++ b/crates/ra_hir/src/marks.rs @@ -2,6 +2,7 @@ test_utils::marks!( bogus_paths + // FIXME: restore this mark once hir is split name_res_works_for_broken_modules can_import_enum_variant type_var_cycles_resolve_completely diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs index 0b278deb3..bb2d78abe 100644 --- a/crates/ra_hir/src/mock.rs +++ b/crates/ra_hir/src/mock.rs @@ -17,6 +17,7 @@ use crate::{db, debug::HirDebugHelper, diagnostics::DiagnosticSink}; pub const WORKSPACE: SourceRootId = SourceRootId(0); #[salsa::database( + hir_def::db::DefDatabase2Storage, ra_db::SourceDatabaseExtStorage, ra_db::SourceDatabaseStorage, db::InternDatabaseStorage, diff --git a/crates/ra_hir/src/name.rs b/crates/ra_hir/src/name.rs index 1e0b8c350..cf66f88ad 100644 --- a/crates/ra_hir/src/name.rs +++ b/crates/ra_hir/src/name.rs @@ -1,142 +1 @@ -//! FIXME: write short doc here - -use std::fmt; - -use ra_syntax::{ast, SmolStr}; - -/// `Name` is a wrapper around string, which is used in hir for both references -/// and declarations. In theory, names should also carry hygiene info, but we are -/// not there yet! -#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] -pub struct Name(Repr); - -#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] -enum Repr { - Text(SmolStr), - TupleField(usize), -} - -impl fmt::Display for Name { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match &self.0 { - Repr::Text(text) => fmt::Display::fmt(&text, f), - Repr::TupleField(idx) => fmt::Display::fmt(&idx, f), - } - } -} - -impl Name { - /// Note: this is private to make creating name from random string hard. - /// Hopefully, this should allow us to integrate hygiene cleaner in the - /// future, and to switch to interned representation of names. - const fn new_text(text: SmolStr) -> Name { - Name(Repr::Text(text)) - } - - pub(crate) fn new_tuple_field(idx: usize) -> Name { - Name(Repr::TupleField(idx)) - } - - /// Shortcut to create inline plain text name - const fn new_inline_ascii(len: usize, text: &[u8]) -> Name { - Name::new_text(SmolStr::new_inline_from_ascii(len, text)) - } - - /// Resolve a name from the text of token. - fn resolve(raw_text: &SmolStr) -> Name { - let raw_start = "r#"; - if raw_text.as_str().starts_with(raw_start) { - Name::new_text(SmolStr::new(&raw_text[raw_start.len()..])) - } else { - Name::new_text(raw_text.clone()) - } - } - - pub(crate) fn missing() -> Name { - Name::new_text("[missing name]".into()) - } - - pub(crate) fn as_tuple_index(&self) -> Option { - match self.0 { - Repr::TupleField(idx) => Some(idx), - _ => None, - } - } -} - -pub(crate) trait AsName { - fn as_name(&self) -> Name; -} - -impl AsName for ast::NameRef { - fn as_name(&self) -> Name { - match self.as_tuple_field() { - Some(idx) => Name::new_tuple_field(idx), - None => Name::resolve(self.text()), - } - } -} - -impl AsName for ast::Name { - fn as_name(&self) -> Name { - Name::resolve(self.text()) - } -} - -impl AsName for ast::FieldKind { - fn as_name(&self) -> Name { - match self { - ast::FieldKind::Name(nr) => nr.as_name(), - ast::FieldKind::Index(idx) => Name::new_tuple_field(idx.text().parse().unwrap()), - } - } -} - -impl AsName for ra_db::Dependency { - fn as_name(&self) -> Name { - Name::new_text(self.name.clone()) - } -} - -// Primitives -pub(crate) const ISIZE: Name = Name::new_inline_ascii(5, b"isize"); -pub(crate) const I8: Name = Name::new_inline_ascii(2, b"i8"); -pub(crate) const I16: Name = Name::new_inline_ascii(3, b"i16"); -pub(crate) const I32: Name = Name::new_inline_ascii(3, b"i32"); -pub(crate) const I64: Name = Name::new_inline_ascii(3, b"i64"); -pub(crate) const I128: Name = Name::new_inline_ascii(4, b"i128"); -pub(crate) const USIZE: Name = Name::new_inline_ascii(5, b"usize"); -pub(crate) const U8: Name = Name::new_inline_ascii(2, b"u8"); -pub(crate) const U16: Name = Name::new_inline_ascii(3, b"u16"); -pub(crate) const U32: Name = Name::new_inline_ascii(3, b"u32"); -pub(crate) const U64: Name = Name::new_inline_ascii(3, b"u64"); -pub(crate) const U128: Name = Name::new_inline_ascii(4, b"u128"); -pub(crate) const F32: Name = Name::new_inline_ascii(3, b"f32"); -pub(crate) const F64: Name = Name::new_inline_ascii(3, b"f64"); -pub(crate) const BOOL: Name = Name::new_inline_ascii(4, b"bool"); -pub(crate) const CHAR: Name = Name::new_inline_ascii(4, b"char"); -pub(crate) const STR: Name = Name::new_inline_ascii(3, b"str"); - -// Special names -pub(crate) const SELF_PARAM: Name = Name::new_inline_ascii(4, b"self"); -pub(crate) const SELF_TYPE: Name = Name::new_inline_ascii(4, b"Self"); -pub(crate) const MACRO_RULES: Name = Name::new_inline_ascii(11, b"macro_rules"); - -// Components of known path (value or mod name) -pub(crate) const STD: Name = Name::new_inline_ascii(3, b"std"); -pub(crate) const ITER: Name = Name::new_inline_ascii(4, b"iter"); -pub(crate) const OPS: Name = Name::new_inline_ascii(3, b"ops"); -pub(crate) const FUTURE: Name = Name::new_inline_ascii(6, b"future"); -pub(crate) const RESULT: Name = Name::new_inline_ascii(6, b"result"); -pub(crate) const BOXED: Name = Name::new_inline_ascii(5, b"boxed"); - -// Components of known path (type name) -pub(crate) const INTO_ITERATOR_TYPE: Name = Name::new_inline_ascii(12, b"IntoIterator"); -pub(crate) const ITEM_TYPE: Name = Name::new_inline_ascii(4, b"Item"); -pub(crate) const TRY_TYPE: Name = Name::new_inline_ascii(3, b"Try"); -pub(crate) const OK_TYPE: Name = Name::new_inline_ascii(2, b"Ok"); -pub(crate) const FUTURE_TYPE: Name = Name::new_inline_ascii(6, b"Future"); -pub(crate) const RESULT_TYPE: Name = Name::new_inline_ascii(6, b"Result"); -pub(crate) const OUTPUT_TYPE: Name = Name::new_inline_ascii(6, b"Output"); -pub(crate) const TARGET_TYPE: Name = Name::new_inline_ascii(6, b"Target"); -pub(crate) const BOX_TYPE: Name = Name::new_inline_ascii(3, b"Box"); +pub use hir_def::name::*; diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index b325979f5..39f585b44 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs @@ -48,7 +48,6 @@ //! on the result mod per_ns; -mod raw; mod collector; mod mod_resolution; #[cfg(test)] @@ -74,12 +73,9 @@ use crate::{ Trait, }; -pub(crate) use self::raw::{ImportSourceMap, RawItems}; +pub use self::per_ns::{Namespace, PerNs}; -pub use self::{ - per_ns::{Namespace, PerNs}, - raw::ImportId, -}; +pub use hir_def::nameres::raw::ImportId; /// Contains all top-level defs from a macro-expanded crate #[derive(Debug, PartialEq, Eq)] @@ -328,7 +324,8 @@ impl CrateDefMap { ) -> ResolvePathResult { let mut segments = path.segments.iter().enumerate(); let mut curr_per_ns: PerNs = match path.kind { - PathKind::DollarCrate(krate) => { + PathKind::DollarCrate(crate_id) => { + let krate = Crate { crate_id }; if krate == self.krate { tested_by!(macro_dollar_crate_self); PerNs::types(Module::new(self.krate, self.root).into()) diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index a94a0554c..2dd0a5877 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs @@ -1,5 +1,6 @@ //! FIXME: write short doc here +use hir_def::nameres::raw; use ra_cfg::CfgOptions; use ra_db::FileId; use ra_syntax::{ast, SmolStr}; @@ -12,7 +13,7 @@ use crate::{ ids::{AstItemDef, LocationCtx, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind}, name::MACRO_RULES, nameres::{ - diagnostics::DefDiagnostic, mod_resolution::ModDir, raw, Crate, CrateDefMap, CrateModuleId, + diagnostics::DefDiagnostic, mod_resolution::ModDir, Crate, CrateDefMap, CrateModuleId, ModuleData, ModuleDef, PerNs, ReachedFixedPoint, Resolution, ResolveMode, }, Adt, AstId, Const, Enum, Function, HirFileId, MacroDef, Module, Name, Path, PathKind, Static, diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir/src/nameres/raw.rs deleted file mode 100644 index 57f2929c3..000000000 --- a/crates/ra_hir/src/nameres/raw.rs +++ /dev/null @@ -1,403 +0,0 @@ -//! FIXME: write short doc here - -use std::{ops::Index, sync::Arc}; - -use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; -use ra_syntax::{ - ast::{self, AttrsOwner, NameOwner}, - AstNode, AstPtr, SourceFile, -}; -use test_utils::tested_by; - -use crate::{ - attr::Attr, - db::{AstDatabase, DefDatabase}, - AsName, AstIdMap, Either, FileAstId, HirFileId, ModuleSource, Name, Path, Source, -}; - -/// `RawItems` is a set of top-level items in a file (except for impls). -/// -/// It is the input to name resolution algorithm. `RawItems` are not invalidated -/// on most edits. -#[derive(Debug, Default, PartialEq, Eq)] -pub struct RawItems { - modules: Arena, - imports: Arena, - defs: Arena, - macros: Arena, - /// items for top-level module - items: Vec, -} - -#[derive(Debug, Default, PartialEq, Eq)] -pub struct ImportSourceMap { - map: ArenaMap, -} - -type ImportSourcePtr = Either, AstPtr>; -type ImportSource = Either; - -impl ImportSourcePtr { - fn to_node(self, file: &SourceFile) -> ImportSource { - self.map(|ptr| ptr.to_node(file.syntax()), |ptr| ptr.to_node(file.syntax())) - } -} - -impl ImportSourceMap { - fn insert(&mut self, import: ImportId, ptr: ImportSourcePtr) { - self.map.insert(import, ptr) - } - - pub(crate) fn get(&self, source: &ModuleSource, import: ImportId) -> ImportSource { - let file = match source { - ModuleSource::SourceFile(file) => file.clone(), - ModuleSource::Module(m) => m.syntax().ancestors().find_map(SourceFile::cast).unwrap(), - }; - - self.map[import].to_node(&file) - } -} - -impl RawItems { - pub(crate) fn raw_items_query( - db: &(impl DefDatabase + AstDatabase), - file_id: HirFileId, - ) -> Arc { - db.raw_items_with_source_map(file_id).0 - } - - pub(crate) fn raw_items_with_source_map_query( - db: &(impl DefDatabase + AstDatabase), - file_id: HirFileId, - ) -> (Arc, Arc) { - let mut collector = RawItemsCollector { - raw_items: RawItems::default(), - source_ast_id_map: db.ast_id_map(file_id), - source_map: ImportSourceMap::default(), - file_id, - db, - }; - if let Some(node) = db.parse_or_expand(file_id) { - if let Some(source_file) = ast::SourceFile::cast(node.clone()) { - collector.process_module(None, source_file); - } else if let Some(item_list) = ast::MacroItems::cast(node) { - collector.process_module(None, item_list); - } - } - (Arc::new(collector.raw_items), Arc::new(collector.source_map)) - } - - pub(super) fn items(&self) -> &[RawItem] { - &self.items - } -} - -impl Index for RawItems { - type Output = ModuleData; - fn index(&self, idx: Module) -> &ModuleData { - &self.modules[idx] - } -} - -impl Index for RawItems { - type Output = ImportData; - fn index(&self, idx: ImportId) -> &ImportData { - &self.imports[idx] - } -} - -impl Index for RawItems { - type Output = DefData; - fn index(&self, idx: Def) -> &DefData { - &self.defs[idx] - } -} - -impl Index for RawItems { - type Output = MacroData; - fn index(&self, idx: Macro) -> &MacroData { - &self.macros[idx] - } -} - -// Avoid heap allocation on items without attributes. -type Attrs = Option>; - -#[derive(Debug, PartialEq, Eq, Clone)] -pub(super) struct RawItem { - attrs: Attrs, - pub(super) kind: RawItemKind, -} - -impl RawItem { - pub(super) fn attrs(&self) -> &[Attr] { - self.attrs.as_ref().map_or(&[], |it| &*it) - } -} - -#[derive(Debug, PartialEq, Eq, Clone, Copy)] -pub(super) enum RawItemKind { - Module(Module), - Import(ImportId), - Def(Def), - Macro(Macro), -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub(super) struct Module(RawId); -impl_arena_id!(Module); - -#[derive(Debug, PartialEq, Eq)] -pub(super) enum ModuleData { - Declaration { name: Name, ast_id: FileAstId }, - Definition { name: Name, ast_id: FileAstId, items: Vec }, -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct ImportId(RawId); -impl_arena_id!(ImportId); - -#[derive(Debug, Clone, PartialEq, Eq)] -pub 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, - pub(super) is_macro_use: bool, -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub(super) struct Def(RawId); -impl_arena_id!(Def); - -#[derive(Debug, PartialEq, Eq)] -pub(super) struct DefData { - pub(super) name: Name, - pub(super) kind: DefKind, -} - -#[derive(Debug, PartialEq, Eq, Clone, Copy)] -pub(super) enum DefKind { - Function(FileAstId), - Struct(FileAstId), - Union(FileAstId), - Enum(FileAstId), - Const(FileAstId), - Static(FileAstId), - Trait(FileAstId), - TypeAlias(FileAstId), -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub(super) struct Macro(RawId); -impl_arena_id!(Macro); - -#[derive(Debug, PartialEq, Eq)] -pub(super) struct MacroData { - pub(super) ast_id: FileAstId, - pub(super) path: Path, - pub(super) name: Option, - pub(super) export: bool, -} - -struct RawItemsCollector { - raw_items: RawItems, - source_ast_id_map: Arc, - source_map: ImportSourceMap, - file_id: HirFileId, - db: DB, -} - -impl RawItemsCollector<&DB> { - fn process_module(&mut self, current_module: Option, body: impl ast::ModuleItemOwner) { - for item_or_macro in body.items_with_macros() { - match item_or_macro { - ast::ItemOrMacro::Macro(m) => self.add_macro(current_module, m), - ast::ItemOrMacro::Item(item) => self.add_item(current_module, item), - } - } - } - - fn add_item(&mut self, current_module: Option, item: ast::ModuleItem) { - let attrs = self.parse_attrs(&item); - let (kind, name) = match item { - ast::ModuleItem::Module(module) => { - self.add_module(current_module, module); - return; - } - ast::ModuleItem::UseItem(use_item) => { - self.add_use_item(current_module, use_item); - return; - } - ast::ModuleItem::ExternCrateItem(extern_crate) => { - self.add_extern_crate_item(current_module, extern_crate); - return; - } - ast::ModuleItem::ImplBlock(_) => { - // impls don't participate in name resolution - return; - } - ast::ModuleItem::StructDef(it) => { - let id = self.source_ast_id_map.ast_id(&it); - let name = it.name(); - if it.is_union() { - (DefKind::Union(id), name) - } else { - (DefKind::Struct(id), name) - } - } - ast::ModuleItem::EnumDef(it) => { - (DefKind::Enum(self.source_ast_id_map.ast_id(&it)), it.name()) - } - ast::ModuleItem::FnDef(it) => { - (DefKind::Function(self.source_ast_id_map.ast_id(&it)), it.name()) - } - ast::ModuleItem::TraitDef(it) => { - (DefKind::Trait(self.source_ast_id_map.ast_id(&it)), it.name()) - } - ast::ModuleItem::TypeAliasDef(it) => { - (DefKind::TypeAlias(self.source_ast_id_map.ast_id(&it)), it.name()) - } - ast::ModuleItem::ConstDef(it) => { - (DefKind::Const(self.source_ast_id_map.ast_id(&it)), it.name()) - } - ast::ModuleItem::StaticDef(it) => { - (DefKind::Static(self.source_ast_id_map.ast_id(&it)), it.name()) - } - }; - if let Some(name) = name { - let name = name.as_name(); - let def = self.raw_items.defs.alloc(DefData { name, kind }); - self.push_item(current_module, attrs, RawItemKind::Def(def)); - } - } - - fn add_module(&mut self, current_module: Option, module: ast::Module) { - let name = match module.name() { - Some(it) => it.as_name(), - None => return, - }; - let attrs = self.parse_attrs(&module); - - let ast_id = self.source_ast_id_map.ast_id(&module); - if module.has_semi() { - let item = self.raw_items.modules.alloc(ModuleData::Declaration { name, ast_id }); - self.push_item(current_module, attrs, RawItemKind::Module(item)); - return; - } - - if let Some(item_list) = module.item_list() { - let item = self.raw_items.modules.alloc(ModuleData::Definition { - name, - ast_id, - items: Vec::new(), - }); - self.process_module(Some(item), item_list); - self.push_item(current_module, attrs, RawItemKind::Module(item)); - return; - } - tested_by!(name_res_works_for_broken_modules); - } - - fn add_use_item(&mut self, current_module: Option, use_item: ast::UseItem) { - // FIXME: cfg_attr - let is_prelude = use_item.has_atom_attr("prelude_import"); - let attrs = self.parse_attrs(&use_item); - - Path::expand_use_item( - Source { ast: use_item, file_id: self.file_id }, - self.db, - |path, use_tree, is_glob, alias| { - let import_data = ImportData { - path, - alias, - is_glob, - is_prelude, - is_extern_crate: false, - is_macro_use: false, - }; - self.push_import( - current_module, - attrs.clone(), - import_data, - Either::A(AstPtr::new(use_tree)), - ); - }, - ) - } - - fn add_extern_crate_item( - &mut self, - current_module: Option, - extern_crate: ast::ExternCrateItem, - ) { - if let Some(name_ref) = extern_crate.name_ref() { - let path = Path::from_name_ref(&name_ref); - let alias = extern_crate.alias().and_then(|a| a.name()).map(|it| it.as_name()); - let attrs = self.parse_attrs(&extern_crate); - // FIXME: cfg_attr - let is_macro_use = extern_crate.has_atom_attr("macro_use"); - let import_data = ImportData { - path, - alias, - is_glob: false, - is_prelude: false, - is_extern_crate: true, - is_macro_use, - }; - self.push_import( - current_module, - attrs, - import_data, - Either::B(AstPtr::new(&extern_crate)), - ); - } - } - - fn add_macro(&mut self, current_module: Option, m: ast::MacroCall) { - let attrs = self.parse_attrs(&m); - let path = match m - .path() - .and_then(|path| Path::from_src(Source { ast: path, file_id: self.file_id }, self.db)) - { - Some(it) => it, - _ => return, - }; - - let name = m.name().map(|it| it.as_name()); - let ast_id = self.source_ast_id_map.ast_id(&m); - // FIXME: cfg_attr - let export = m.attrs().filter_map(|x| x.simple_name()).any(|name| name == "macro_export"); - - let m = self.raw_items.macros.alloc(MacroData { ast_id, path, name, export }); - self.push_item(current_module, attrs, RawItemKind::Macro(m)); - } - - fn push_import( - &mut self, - current_module: Option, - attrs: Attrs, - data: ImportData, - source: ImportSourcePtr, - ) { - let import = self.raw_items.imports.alloc(data); - self.source_map.insert(import, source); - self.push_item(current_module, attrs, RawItemKind::Import(import)) - } - - fn push_item(&mut self, current_module: Option, attrs: Attrs, kind: RawItemKind) { - match current_module { - Some(module) => match &mut self.raw_items.modules[module] { - ModuleData::Definition { items, .. } => items, - ModuleData::Declaration { .. } => unreachable!(), - }, - None => &mut self.raw_items.items, - } - .push(RawItem { attrs, kind }) - } - - fn parse_attrs(&self, item: &impl ast::AttrsOwner) -> Attrs { - Attr::from_attrs_owner(self.file_id, item, self.db) - } -} diff --git a/crates/ra_hir/src/nameres/tests/mod_resolution.rs b/crates/ra_hir/src/nameres/tests/mod_resolution.rs index f569aacdc..abfe8b1c3 100644 --- a/crates/ra_hir/src/nameres/tests/mod_resolution.rs +++ b/crates/ra_hir/src/nameres/tests/mod_resolution.rs @@ -2,7 +2,7 @@ use super::*; #[test] fn name_res_works_for_broken_modules() { - covers!(name_res_works_for_broken_modules); + // covers!(name_res_works_for_broken_modules); let map = def_map( " //- /lib.rs diff --git a/crates/ra_hir/src/path.rs b/crates/ra_hir/src/path.rs index bbe536bcb..7f0ff4bfc 100644 --- a/crates/ra_hir/src/path.rs +++ b/crates/ra_hir/src/path.rs @@ -1,422 +1 @@ -//! FIXME: write short doc here - -use std::{iter, sync::Arc}; - -use ra_syntax::{ - ast::{self, NameOwner, TypeAscriptionOwner}, - AstNode, -}; - -use crate::{db::AstDatabase, name, type_ref::TypeRef, AsName, Crate, Name, Source}; - -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Path { - pub kind: PathKind, - pub segments: Vec, -} - -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct PathSegment { - pub name: Name, - pub args_and_bindings: Option>, -} - -/// Generic arguments to a path segment (e.g. the `i32` in `Option`). This -/// can (in the future) also include bindings of associated types, like in -/// `Iterator`. -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct GenericArgs { - pub args: Vec, - /// This specifies whether the args contain a Self type as the first - /// element. This is the case for path segments like ``, where - /// `T` is actually a type parameter for the path `Trait` specifying the - /// Self type. Otherwise, when we have a path `Trait`, the Self type - /// is left out. - pub has_self_type: bool, - /// Associated type bindings like in `Iterator`. - pub bindings: Vec<(Name, TypeRef)>, -} - -/// A single generic argument. -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum GenericArg { - Type(TypeRef), - // or lifetime... -} - -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum PathKind { - Plain, - Self_, - Super, - Crate, - // Absolute path - Abs, - // Type based path like `::foo` - Type(Box), - // `$crate` from macro expansion - DollarCrate(Crate), -} - -impl Path { - /// Calls `cb` with all paths, represented by this use item. - pub fn expand_use_item( - item_src: Source, - db: &impl AstDatabase, - mut cb: impl FnMut(Path, &ast::UseTree, bool, Option), - ) { - if let Some(tree) = item_src.ast.use_tree() { - expand_use_tree( - None, - tree, - &|| item_src.file_id.macro_crate(db).map(|crate_id| Crate { crate_id }), - &mut cb, - ); - } - } - - pub fn from_simple_segments(kind: PathKind, segments: impl IntoIterator) -> Path { - Path { - kind, - segments: segments - .into_iter() - .map(|name| PathSegment { name, args_and_bindings: None }) - .collect(), - } - } - - /// Converts an `ast::Path` to `Path`. Works with use trees. - /// DEPRECATED: It does not handle `$crate` from macro call. - pub fn from_ast(path: ast::Path) -> Option { - Path::parse(path, &|| None) - } - - /// Converts an `ast::Path` to `Path`. Works with use trees. - /// It correctly handles `$crate` based path from macro call. - pub fn from_src(source: Source, db: &impl AstDatabase) -> Option { - let file_id = source.file_id; - Path::parse(source.ast, &|| file_id.macro_crate(db).map(|crate_id| Crate { crate_id })) - } - - fn parse(mut path: ast::Path, macro_crate: &impl Fn() -> Option) -> Option { - let mut kind = PathKind::Plain; - let mut segments = Vec::new(); - loop { - let segment = path.segment()?; - - if segment.has_colon_colon() { - kind = PathKind::Abs; - } - - match segment.kind()? { - ast::PathSegmentKind::Name(name) => { - if name.text() == "$crate" { - if let Some(macro_crate) = macro_crate() { - kind = PathKind::DollarCrate(macro_crate); - break; - } - } - - let args = segment - .type_arg_list() - .and_then(GenericArgs::from_ast) - .or_else(|| { - GenericArgs::from_fn_like_path_ast( - segment.param_list(), - segment.ret_type(), - ) - }) - .map(Arc::new); - let segment = PathSegment { name: name.as_name(), args_and_bindings: args }; - segments.push(segment); - } - ast::PathSegmentKind::Type { type_ref, trait_ref } => { - assert!(path.qualifier().is_none()); // this can only occur at the first segment - - let self_type = TypeRef::from_ast(type_ref?); - - match trait_ref { - // ::foo - None => { - kind = PathKind::Type(Box::new(self_type)); - } - // >::Foo desugars to Trait::Foo - Some(trait_ref) => { - let path = Path::parse(trait_ref.path()?, macro_crate)?; - kind = path.kind; - let mut prefix_segments = path.segments; - prefix_segments.reverse(); - segments.extend(prefix_segments); - // Insert the type reference (T in the above example) as Self parameter for the trait - let mut last_segment = segments.last_mut()?; - if last_segment.args_and_bindings.is_none() { - last_segment.args_and_bindings = - Some(Arc::new(GenericArgs::empty())); - }; - let args = last_segment.args_and_bindings.as_mut().unwrap(); - let mut args_inner = Arc::make_mut(args); - args_inner.has_self_type = true; - args_inner.args.insert(0, GenericArg::Type(self_type)); - } - } - } - ast::PathSegmentKind::CrateKw => { - kind = PathKind::Crate; - break; - } - ast::PathSegmentKind::SelfKw => { - kind = PathKind::Self_; - break; - } - ast::PathSegmentKind::SuperKw => { - kind = PathKind::Super; - break; - } - } - path = match qualifier(&path) { - Some(it) => it, - None => break, - }; - } - segments.reverse(); - return Some(Path { kind, segments }); - - fn qualifier(path: &ast::Path) -> Option { - if let Some(q) = path.qualifier() { - return Some(q); - } - // FIXME: this bottom up traversal is not too precise. - // Should we handle do a top-down analysis, recording results? - let use_tree_list = path.syntax().ancestors().find_map(ast::UseTreeList::cast)?; - let use_tree = use_tree_list.parent_use_tree(); - use_tree.path() - } - } - - /// Converts an `ast::NameRef` into a single-identifier `Path`. - pub fn from_name_ref(name_ref: &ast::NameRef) -> Path { - name_ref.as_name().into() - } - - /// `true` is this path is a single identifier, like `foo` - pub fn is_ident(&self) -> bool { - self.kind == PathKind::Plain && self.segments.len() == 1 - } - - /// `true` if this path is just a standalone `self` - pub fn is_self(&self) -> bool { - self.kind == PathKind::Self_ && self.segments.is_empty() - } - - /// If this path is a single identifier, like `foo`, return its name. - pub fn as_ident(&self) -> Option<&Name> { - if self.kind != PathKind::Plain || self.segments.len() > 1 { - return None; - } - self.segments.first().map(|s| &s.name) - } - - pub fn expand_macro_expr(&self) -> Option { - self.as_ident().and_then(|name| Some(name.clone())) - } - - pub fn is_type_relative(&self) -> bool { - match self.kind { - PathKind::Type(_) => true, - _ => false, - } - } -} - -impl GenericArgs { - pub(crate) fn from_ast(node: ast::TypeArgList) -> Option { - let mut args = Vec::new(); - for type_arg in node.type_args() { - let type_ref = TypeRef::from_ast_opt(type_arg.type_ref()); - args.push(GenericArg::Type(type_ref)); - } - // lifetimes ignored for now - let mut bindings = Vec::new(); - for assoc_type_arg in node.assoc_type_args() { - if let Some(name_ref) = assoc_type_arg.name_ref() { - let name = name_ref.as_name(); - let type_ref = TypeRef::from_ast_opt(assoc_type_arg.type_ref()); - bindings.push((name, type_ref)); - } - } - if args.is_empty() && bindings.is_empty() { - None - } else { - Some(GenericArgs { args, has_self_type: false, bindings }) - } - } - - /// Collect `GenericArgs` from the parts of a fn-like path, i.e. `Fn(X, Y) - /// -> Z` (which desugars to `Fn<(X, Y), Output=Z>`). - pub(crate) fn from_fn_like_path_ast( - params: Option, - ret_type: Option, - ) -> Option { - let mut args = Vec::new(); - let mut bindings = Vec::new(); - if let Some(params) = params { - let mut param_types = Vec::new(); - for param in params.params() { - let type_ref = TypeRef::from_ast_opt(param.ascribed_type()); - param_types.push(type_ref); - } - let arg = GenericArg::Type(TypeRef::Tuple(param_types)); - args.push(arg); - } - if let Some(ret_type) = ret_type { - let type_ref = TypeRef::from_ast_opt(ret_type.type_ref()); - bindings.push((name::OUTPUT_TYPE, type_ref)) - } - if args.is_empty() && bindings.is_empty() { - None - } else { - Some(GenericArgs { args, has_self_type: false, bindings }) - } - } - - pub(crate) fn empty() -> GenericArgs { - GenericArgs { args: Vec::new(), has_self_type: false, bindings: Vec::new() } - } -} - -impl From for Path { - fn from(name: Name) -> Path { - Path::from_simple_segments(PathKind::Plain, iter::once(name)) - } -} - -fn expand_use_tree( - prefix: Option, - tree: ast::UseTree, - macro_crate: &impl Fn() -> Option, - cb: &mut impl FnMut(Path, &ast::UseTree, bool, Option), -) { - if let Some(use_tree_list) = tree.use_tree_list() { - let prefix = match tree.path() { - // E.g. use something::{{{inner}}}; - None => prefix, - // E.g. `use something::{inner}` (prefix is `None`, path is `something`) - // or `use something::{path::{inner::{innerer}}}` (prefix is `something::path`, path is `inner`) - Some(path) => match convert_path(prefix, path, macro_crate) { - Some(it) => Some(it), - None => return, // FIXME: report errors somewhere - }, - }; - for child_tree in use_tree_list.use_trees() { - expand_use_tree(prefix.clone(), child_tree, macro_crate, cb); - } - } else { - let alias = tree.alias().and_then(|a| a.name()).map(|a| a.as_name()); - if let Some(ast_path) = tree.path() { - // Handle self in a path. - // E.g. `use something::{self, <...>}` - if ast_path.qualifier().is_none() { - if let Some(segment) = ast_path.segment() { - if segment.kind() == Some(ast::PathSegmentKind::SelfKw) { - if let Some(prefix) = prefix { - cb(prefix, &tree, false, alias); - return; - } - } - } - } - if let Some(path) = convert_path(prefix, ast_path, macro_crate) { - let is_glob = tree.has_star(); - cb(path, &tree, is_glob, alias) - } - // FIXME: report errors somewhere - // We get here if we do - } - } -} - -fn convert_path( - prefix: Option, - path: ast::Path, - macro_crate: &impl Fn() -> Option, -) -> Option { - let prefix = if let Some(qual) = path.qualifier() { - Some(convert_path(prefix, qual, macro_crate)?) - } else { - prefix - }; - - let segment = path.segment()?; - let res = match segment.kind()? { - ast::PathSegmentKind::Name(name) => { - if name.text() == "$crate" { - if let Some(krate) = macro_crate() { - return Some(Path::from_simple_segments( - PathKind::DollarCrate(krate), - iter::empty(), - )); - } - } - - // no type args in use - let mut res = prefix - .unwrap_or_else(|| Path { kind: PathKind::Plain, segments: Vec::with_capacity(1) }); - res.segments.push(PathSegment { - name: name.as_name(), - args_and_bindings: None, // no type args in use - }); - res - } - ast::PathSegmentKind::CrateKw => { - if prefix.is_some() { - return None; - } - Path::from_simple_segments(PathKind::Crate, iter::empty()) - } - ast::PathSegmentKind::SelfKw => { - if prefix.is_some() { - return None; - } - Path::from_simple_segments(PathKind::Self_, iter::empty()) - } - ast::PathSegmentKind::SuperKw => { - if prefix.is_some() { - return None; - } - Path::from_simple_segments(PathKind::Super, iter::empty()) - } - ast::PathSegmentKind::Type { .. } => { - // not allowed in imports - return None; - } - }; - Some(res) -} - -pub mod known { - use super::{Path, PathKind}; - use crate::name; - - pub fn std_iter_into_iterator() -> Path { - Path::from_simple_segments( - PathKind::Abs, - vec![name::STD, name::ITER, name::INTO_ITERATOR_TYPE], - ) - } - - pub fn std_ops_try() -> Path { - Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::OPS, name::TRY_TYPE]) - } - - pub fn std_result_result() -> Path { - Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::RESULT, name::RESULT_TYPE]) - } - - pub fn std_future_future() -> Path { - Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::FUTURE, name::FUTURE_TYPE]) - } - - pub fn std_boxed_box() -> Path { - Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::BOXED, name::BOX_TYPE]) - } -} +pub use hir_def::path::*; diff --git a/crates/ra_hir/src/type_ref.rs b/crates/ra_hir/src/type_ref.rs index 2cf06b250..bd56ddbe6 100644 --- a/crates/ra_hir/src/type_ref.rs +++ b/crates/ra_hir/src/type_ref.rs @@ -1,162 +1 @@ -//! HIR for references to types. Paths in these are not yet resolved. They can -//! be directly created from an ast::TypeRef, without further queries. - -use ra_syntax::ast::{self, TypeAscriptionOwner, TypeBoundsOwner}; - -use crate::Path; - -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] -pub enum Mutability { - Shared, - Mut, -} - -impl Mutability { - pub fn from_mutable(mutable: bool) -> Mutability { - if mutable { - Mutability::Mut - } else { - Mutability::Shared - } - } - - pub fn as_keyword_for_ref(self) -> &'static str { - match self { - Mutability::Shared => "", - Mutability::Mut => "mut ", - } - } - - pub fn as_keyword_for_ptr(self) -> &'static str { - match self { - Mutability::Shared => "const ", - Mutability::Mut => "mut ", - } - } -} - -/// Compare ty::Ty -#[derive(Clone, PartialEq, Eq, Hash, Debug)] -pub enum TypeRef { - Never, - Placeholder, - Tuple(Vec), - Path(Path), - RawPtr(Box, Mutability), - Reference(Box, Mutability), - Array(Box /*, Expr*/), - Slice(Box), - /// A fn pointer. Last element of the vector is the return type. - Fn(Vec), - // For - ImplTrait(Vec), - DynTrait(Vec), - Error, -} - -#[derive(Clone, PartialEq, Eq, Hash, Debug)] -pub enum TypeBound { - Path(Path), - // also for<> bounds - // also Lifetimes - Error, -} - -impl TypeRef { - /// Converts an `ast::TypeRef` to a `hir::TypeRef`. - pub(crate) fn from_ast(node: ast::TypeRef) -> Self { - match node { - ast::TypeRef::ParenType(inner) => TypeRef::from_ast_opt(inner.type_ref()), - ast::TypeRef::TupleType(inner) => { - TypeRef::Tuple(inner.fields().map(TypeRef::from_ast).collect()) - } - ast::TypeRef::NeverType(..) => TypeRef::Never, - ast::TypeRef::PathType(inner) => { - // FIXME: Use `Path::from_src` - inner.path().and_then(Path::from_ast).map(TypeRef::Path).unwrap_or(TypeRef::Error) - } - ast::TypeRef::PointerType(inner) => { - let inner_ty = TypeRef::from_ast_opt(inner.type_ref()); - let mutability = Mutability::from_mutable(inner.is_mut()); - TypeRef::RawPtr(Box::new(inner_ty), mutability) - } - ast::TypeRef::ArrayType(inner) => { - TypeRef::Array(Box::new(TypeRef::from_ast_opt(inner.type_ref()))) - } - ast::TypeRef::SliceType(inner) => { - TypeRef::Slice(Box::new(TypeRef::from_ast_opt(inner.type_ref()))) - } - ast::TypeRef::ReferenceType(inner) => { - let inner_ty = TypeRef::from_ast_opt(inner.type_ref()); - let mutability = Mutability::from_mutable(inner.is_mut()); - TypeRef::Reference(Box::new(inner_ty), mutability) - } - ast::TypeRef::PlaceholderType(_inner) => TypeRef::Placeholder, - ast::TypeRef::FnPointerType(inner) => { - let ret_ty = TypeRef::from_ast_opt(inner.ret_type().and_then(|rt| rt.type_ref())); - let mut params = if let Some(pl) = inner.param_list() { - pl.params().map(|p| p.ascribed_type()).map(TypeRef::from_ast_opt).collect() - } else { - Vec::new() - }; - params.push(ret_ty); - TypeRef::Fn(params) - } - // for types are close enough for our purposes to the inner type for now... - ast::TypeRef::ForType(inner) => TypeRef::from_ast_opt(inner.type_ref()), - ast::TypeRef::ImplTraitType(inner) => { - TypeRef::ImplTrait(type_bounds_from_ast(inner.type_bound_list())) - } - ast::TypeRef::DynTraitType(inner) => { - TypeRef::DynTrait(type_bounds_from_ast(inner.type_bound_list())) - } - } - } - - pub(crate) fn from_ast_opt(node: Option) -> Self { - if let Some(node) = node { - TypeRef::from_ast(node) - } else { - TypeRef::Error - } - } - - pub fn unit() -> TypeRef { - TypeRef::Tuple(Vec::new()) - } -} - -pub(crate) fn type_bounds_from_ast(type_bounds_opt: Option) -> Vec { - if let Some(type_bounds) = type_bounds_opt { - type_bounds.bounds().map(TypeBound::from_ast).collect() - } else { - vec![] - } -} - -impl TypeBound { - pub(crate) fn from_ast(node: ast::TypeBound) -> Self { - match node.kind() { - ast::TypeBoundKind::PathType(path_type) => { - let path = match path_type.path() { - Some(p) => p, - None => return TypeBound::Error, - }; - // FIXME: Use `Path::from_src` - let path = match Path::from_ast(path) { - Some(p) => p, - None => return TypeBound::Error, - }; - TypeBound::Path(path) - } - ast::TypeBoundKind::ForType(_) | ast::TypeBoundKind::Lifetime(_) => TypeBound::Error, - } - } - - pub fn as_path(&self) -> Option<&Path> { - match self { - TypeBound::Path(p) => Some(p), - _ => None, - } - } -} +pub use hir_def::type_ref::*; -- cgit v1.2.3 From f8ddef875af08f6c67fe69f7803f3926bc6f66bb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 30 Oct 2019 17:19:30 +0300 Subject: remove forward pointer for name --- crates/ra_hir/src/adt.rs | 3 ++- crates/ra_hir/src/code_model.rs | 18 +++++++++--------- crates/ra_hir/src/expr/lower.rs | 4 ++-- crates/ra_hir/src/from_source.rs | 2 +- crates/ra_hir/src/generics.rs | 14 +++++++++----- crates/ra_hir/src/lib.rs | 6 +++--- crates/ra_hir/src/name.rs | 1 - crates/ra_hir/src/nameres/collector.rs | 5 ++--- crates/ra_hir/src/resolve.rs | 20 +++++++++++--------- crates/ra_hir/src/source_binder.rs | 5 +++-- crates/ra_hir/src/traits.rs | 4 ++-- crates/ra_hir/src/ty/autoderef.rs | 3 ++- crates/ra_hir/src/ty/infer.rs | 2 +- crates/ra_hir/src/ty/infer/expr.rs | 3 ++- crates/ra_hir/src/ty/traits/chalk.rs | 3 ++- crates/ra_hir/src/type_alias.rs | 2 +- 16 files changed, 52 insertions(+), 43 deletions(-) delete mode 100644 crates/ra_hir/src/name.rs (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs index 3e9cd3c63..ce64980bb 100644 --- a/crates/ra_hir/src/adt.rs +++ b/crates/ra_hir/src/adt.rs @@ -3,13 +3,14 @@ use std::sync::Arc; +use hir_def::name::AsName; use ra_arena::{impl_arena_id, Arena, RawId}; use ra_syntax::ast::{self, NameOwner, StructKind, TypeAscriptionOwner}; use crate::{ db::{AstDatabase, DefDatabase, HirDatabase}, type_ref::TypeRef, - AsName, Enum, EnumVariant, FieldSource, HasSource, Module, Name, Source, Struct, StructField, + Enum, EnumVariant, FieldSource, HasSource, Module, Name, Source, Struct, StructField, }; impl Struct { diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index de1377aa4..7848d0a3f 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -5,7 +5,13 @@ pub(crate) mod docs; use std::sync::Arc; -use hir_def::{CrateModuleId, ModuleId}; +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, + }, + CrateModuleId, ModuleId, +}; use ra_db::{CrateId, Edition}; use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; @@ -20,10 +26,6 @@ use crate::{ TypeAliasId, }, impl_block::ImplBlock, - name::{ - BOOL, CHAR, F32, F64, I128, I16, I32, I64, I8, ISIZE, SELF_TYPE, STR, U128, U16, U32, U64, - U8, USIZE, - }, nameres::{ImportId, ModuleScope, Namespace}, resolve::{Resolver, Scope, TypeNs}, traits::TraitData, @@ -33,7 +35,7 @@ use crate::{ }, type_ref::Mutability, type_ref::TypeRef, - AsName, Either, HasSource, Name, Ty, + Either, HasSource, Name, Ty, }; /// hir::Crate describes a single crate. It's the main interface with which @@ -898,9 +900,7 @@ impl Trait { .where_predicates .iter() .filter_map(|pred| match &pred.type_ref { - TypeRef::Path(p) if p.as_ident() == Some(&crate::name::SELF_TYPE) => { - pred.bound.as_path() - } + TypeRef::Path(p) if p.as_ident() == Some(&name::SELF_TYPE) => pred.bound.as_path(), _ => None, }) .filter_map(|path| match resolver.resolve_path_in_type_ns_fully(db, path) { diff --git a/crates/ra_hir/src/expr/lower.rs b/crates/ra_hir/src/expr/lower.rs index b3a9a2e6b..cf8a41b1e 100644 --- a/crates/ra_hir/src/expr/lower.rs +++ b/crates/ra_hir/src/expr/lower.rs @@ -1,5 +1,6 @@ //! FIXME: write short doc here +use hir_def::name::{self, AsName, Name}; use ra_arena::Arena; use ra_syntax::{ ast::{ @@ -12,7 +13,6 @@ use test_utils::tested_by; use crate::{ db::HirDatabase, - name::{AsName, Name, SELF_PARAM}, path::GenericArgs, ty::primitive::{FloatTy, IntTy, UncertainFloatTy, UncertainIntTy}, type_ref::TypeRef, @@ -78,7 +78,7 @@ where let ptr = AstPtr::new(&self_param); let param_pat = self.alloc_pat( Pat::Bind { - name: SELF_PARAM, + name: name::SELF_PARAM, mode: BindingAnnotation::Unannotated, subpat: None, }, diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs index 697c8dc84..b9fbaa367 100644 --- a/crates/ra_hir/src/from_source.rs +++ b/crates/ra_hir/src/from_source.rs @@ -1,11 +1,11 @@ //! FIXME: write short doc here +use hir_def::name::AsName; use ra_syntax::ast::{self, AstNode, NameOwner}; use crate::{ db::{AstDatabase, DefDatabase, HirDatabase}, ids::{AstItemDef, LocationCtx}, - name::AsName, AstId, Const, Crate, Enum, EnumVariant, FieldSource, Function, HasSource, ImplBlock, Module, ModuleSource, Source, Static, Struct, StructField, Trait, TypeAlias, Union, VariantDef, }; diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs index 4ce7551c3..61786a614 100644 --- a/crates/ra_hir/src/generics.rs +++ b/crates/ra_hir/src/generics.rs @@ -5,15 +5,15 @@ use std::sync::Arc; +use hir_def::name::{self, AsName}; use ra_syntax::ast::{self, DefaultTypeParamOwner, NameOwner, TypeBoundsOwner, TypeParamsOwner}; use crate::{ db::{AstDatabase, DefDatabase, HirDatabase}, - name::SELF_TYPE, path::Path, type_ref::{TypeBound, TypeRef}, - Adt, AsName, Const, Container, Enum, EnumVariant, Function, HasSource, ImplBlock, Name, Struct, - Trait, TypeAlias, Union, + Adt, Const, Container, Enum, EnumVariant, Function, HasSource, ImplBlock, Name, Struct, Trait, + TypeAlias, Union, }; /// Data about a generic parameter (to a function, struct, impl, ...). @@ -94,11 +94,15 @@ impl GenericParams { GenericDef::Adt(Adt::Enum(it)) => generics.fill(&it.source(db).ast, start), GenericDef::Trait(it) => { // traits get the Self type as an implicit first type parameter - generics.params.push(GenericParam { idx: start, name: SELF_TYPE, default: None }); + generics.params.push(GenericParam { + idx: start, + name: name::SELF_TYPE, + default: None, + }); generics.fill(&it.source(db).ast, start + 1); // add super traits as bounds on Self // i.e., trait Foo: Bar is equivalent to trait Foo where Self: Bar - let self_param = TypeRef::Path(SELF_TYPE.into()); + let self_param = TypeRef::Path(name::SELF_TYPE.into()); generics.fill_bounds(&it.source(db).ast, self_param); } GenericDef::TypeAlias(it) => generics.fill(&it.source(db).ast, start), diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index b49f615bf..620911459 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -36,7 +36,6 @@ mod path; pub mod source_binder; mod ids; -mod name; mod nameres; mod adt; mod traits; @@ -61,7 +60,7 @@ mod marks; use hir_expand::AstId; -use crate::{ids::MacroFileKind, name::AsName, resolve::Resolver}; +use crate::{ids::MacroFileKind, resolve::Resolver}; pub use crate::{ adt::VariantDef, @@ -71,7 +70,6 @@ pub use crate::{ generics::{GenericDef, GenericParam, GenericParams, HasGenericParams}, ids::{HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile}, impl_block::ImplBlock, - name::Name, nameres::{ImportId, Namespace, PerNs}, path::{Path, PathKind}, resolve::ScopeDef, @@ -89,3 +87,5 @@ pub use self::code_model::{ Enum, EnumVariant, FieldSource, FnData, Function, HasBody, MacroDef, Module, ModuleDef, ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, }; + +pub use hir_def::name::Name; diff --git a/crates/ra_hir/src/name.rs b/crates/ra_hir/src/name.rs deleted file mode 100644 index cf66f88ad..000000000 --- a/crates/ra_hir/src/name.rs +++ /dev/null @@ -1 +0,0 @@ -pub use hir_def::name::*; diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index 2dd0a5877..1f3849dc7 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs @@ -1,6 +1,6 @@ //! FIXME: write short doc here -use hir_def::nameres::raw; +use hir_def::{name, nameres::raw}; use ra_cfg::CfgOptions; use ra_db::FileId; use ra_syntax::{ast, SmolStr}; @@ -11,7 +11,6 @@ use crate::{ attr::Attr, db::DefDatabase, ids::{AstItemDef, LocationCtx, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind}, - name::MACRO_RULES, nameres::{ diagnostics::DefDiagnostic, mod_resolution::ModDir, Crate, CrateDefMap, CrateModuleId, ModuleData, ModuleDef, PerNs, ReachedFixedPoint, Resolution, ResolveMode, @@ -726,7 +725,7 @@ where } fn is_macro_rules(path: &Path) -> bool { - path.as_ident() == Some(&MACRO_RULES) + path.as_ident() == Some(&name::MACRO_RULES) } #[cfg(test)] diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index 8b6269407..b9459552b 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs @@ -1,7 +1,10 @@ //! Name resolution. use std::sync::Arc; -use hir_def::CrateModuleId; +use hir_def::{ + name::{self, Name}, + CrateModuleId, +}; use rustc_hash::FxHashSet; use crate::{ @@ -13,7 +16,6 @@ use crate::{ }, generics::GenericParams, impl_block::ImplBlock, - name::{Name, SELF_PARAM, SELF_TYPE}, nameres::{CrateDefMap, PerNs}, path::{Path, PathKind}, Adt, BuiltinType, Const, Enum, EnumVariant, Function, MacroDef, ModuleDef, Static, Struct, @@ -150,13 +152,13 @@ impl Resolver { } } Scope::ImplBlockScope(impl_) => { - if first_name == &SELF_TYPE { + if first_name == &name::SELF_TYPE { let idx = if path.segments.len() == 1 { None } else { Some(1) }; return Some((TypeNs::SelfType(*impl_), idx)); } } Scope::AdtScope(adt) => { - if first_name == &SELF_TYPE { + if first_name == &name::SELF_TYPE { let idx = if path.segments.len() == 1 { None } else { Some(1) }; return Some((TypeNs::AdtSelfType(*adt), idx)); } @@ -205,7 +207,7 @@ impl Resolver { return None; } let n_segments = path.segments.len(); - let tmp = SELF_PARAM; + let tmp = name::SELF_PARAM; let first_name = if path.is_self() { &tmp } else { &path.segments.first()?.name }; let skip_to_mod = path.kind != PathKind::Plain && !path.is_self(); for scope in self.scopes.iter().rev() { @@ -241,13 +243,13 @@ impl Resolver { Scope::GenericParams(_) => continue, Scope::ImplBlockScope(impl_) if n_segments > 1 => { - if first_name == &SELF_TYPE { + if first_name == &name::SELF_TYPE { let ty = TypeNs::SelfType(*impl_); return Some(ResolveValueResult::Partial(ty, 1)); } } Scope::AdtScope(adt) if n_segments > 1 => { - if first_name == &SELF_TYPE { + if first_name == &name::SELF_TYPE { let ty = TypeNs::AdtSelfType(*adt); return Some(ResolveValueResult::Partial(ty, 1)); } @@ -459,10 +461,10 @@ impl Scope { } } Scope::ImplBlockScope(i) => { - f(SELF_TYPE, ScopeDef::ImplSelfType(*i)); + f(name::SELF_TYPE, ScopeDef::ImplSelfType(*i)); } Scope::AdtScope(i) => { - f(SELF_TYPE, ScopeDef::AdtSelfType(*i)); + f(name::SELF_TYPE, ScopeDef::AdtSelfType(*i)); } Scope::ExprScope(e) => { e.expr_scopes.entries(e.scope_id).iter().for_each(|e| { diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 730c33226..8a1fa29a4 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -7,6 +7,7 @@ //! purely for "IDE needs". use std::sync::Arc; +use hir_def::name::AsName; use ra_db::FileId; use ra_syntax::{ ast::{self, AstNode}, @@ -27,8 +28,8 @@ use crate::{ path::known, resolve::{ScopeDef, TypeNs, ValueNs}, ty::method_resolution::implements_trait, - AsName, Const, DefWithBody, Either, Enum, FromSource, Function, HasBody, HirFileId, MacroDef, - Module, Name, Path, Resolver, Static, Struct, Ty, + Const, DefWithBody, Either, Enum, FromSource, Function, HasBody, HirFileId, MacroDef, Module, + Name, Path, Resolver, Static, Struct, Ty, }; fn try_get_resolver_for_node( diff --git a/crates/ra_hir/src/traits.rs b/crates/ra_hir/src/traits.rs index 22f188049..514c813ab 100644 --- a/crates/ra_hir/src/traits.rs +++ b/crates/ra_hir/src/traits.rs @@ -1,14 +1,14 @@ //! HIR for trait definitions. -use rustc_hash::FxHashMap; use std::sync::Arc; +use hir_def::name::AsName; use ra_syntax::ast::{self, NameOwner}; +use rustc_hash::FxHashMap; use crate::{ db::{AstDatabase, DefDatabase}, ids::LocationCtx, - name::AsName, AssocItem, Const, Function, HasSource, Module, Name, Trait, TypeAlias, }; diff --git a/crates/ra_hir/src/ty/autoderef.rs b/crates/ra_hir/src/ty/autoderef.rs index 02492ca14..03c45546d 100644 --- a/crates/ra_hir/src/ty/autoderef.rs +++ b/crates/ra_hir/src/ty/autoderef.rs @@ -5,10 +5,11 @@ use std::iter::successors; +use hir_def::name; use log::{info, warn}; use super::{traits::Solution, Canonical, Substs, Ty, TypeWalk}; -use crate::{db::HirDatabase, name, HasGenericParams, Resolver}; +use crate::{db::HirDatabase, HasGenericParams, Resolver}; const AUTODEREF_RECURSION_LIMIT: usize = 10; diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index ebaff998e..92b8e718e 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -21,6 +21,7 @@ use std::sync::Arc; use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue}; use rustc_hash::FxHashMap; +use hir_def::name; use ra_arena::map::ArenaMap; use ra_prof::profile; use test_utils::tested_by; @@ -37,7 +38,6 @@ use crate::{ db::HirDatabase, diagnostics::DiagnosticSink, expr::{BindingAnnotation, Body, ExprId, PatId}, - name, path::known, resolve::{Resolver, TypeNs}, ty::infer::diagnostics::InferenceDiagnostic, diff --git a/crates/ra_hir/src/ty/infer/expr.rs b/crates/ra_hir/src/ty/infer/expr.rs index f8807c742..7ef87bfe2 100644 --- a/crates/ra_hir/src/ty/infer/expr.rs +++ b/crates/ra_hir/src/ty/infer/expr.rs @@ -3,12 +3,13 @@ use std::iter::{repeat, repeat_with}; use std::sync::Arc; +use hir_def::name; + use super::{BindingMode, Expectation, InferenceContext, InferenceDiagnostic, TypeMismatch}; use crate::{ db::HirDatabase, expr::{self, Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, generics::{GenericParams, HasGenericParams}, - name, nameres::Namespace, path::{GenericArg, GenericArgs}, ty::{ diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs index ab66515be..2dd4c2fae 100644 --- a/crates/ra_hir/src/ty/traits/chalk.rs +++ b/crates/ra_hir/src/ty/traits/chalk.rs @@ -9,6 +9,7 @@ use chalk_ir::{ }; use chalk_rust_ir::{AssociatedTyDatum, ImplDatum, StructDatum, TraitDatum}; +use hir_def::name; use ra_db::salsa::{InternId, InternKey}; use super::{Canonical, ChalkContext, Impl, Obligation}; @@ -734,7 +735,7 @@ fn closure_fn_trait_impl_datum( substs: Substs::build_for_def(db, trait_).push(self_ty).push(arg_ty).build(), }; - let output_ty_id = fn_once_trait.associated_type_by_name(db, &crate::name::OUTPUT_TYPE)?; + let output_ty_id = fn_once_trait.associated_type_by_name(db, &name::OUTPUT_TYPE)?; let output_ty_value = chalk_rust_ir::AssociatedTyValue { associated_ty_id: output_ty_id.to_chalk(db), diff --git a/crates/ra_hir/src/type_alias.rs b/crates/ra_hir/src/type_alias.rs index 674a46102..18c01e1b9 100644 --- a/crates/ra_hir/src/type_alias.rs +++ b/crates/ra_hir/src/type_alias.rs @@ -2,11 +2,11 @@ use std::sync::Arc; +use hir_def::name::{AsName, Name}; use ra_syntax::ast::NameOwner; use crate::{ db::{AstDatabase, DefDatabase}, - name::{AsName, Name}, type_ref::TypeRef, HasSource, TypeAlias, }; -- cgit v1.2.3 From e56433432057712086ca623c4a1ef40089004839 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 30 Oct 2019 17:24:36 +0300 Subject: remove forward pointer to Path --- crates/ra_hir/src/expr.rs | 2 +- crates/ra_hir/src/expr/lower.rs | 6 ++++-- crates/ra_hir/src/expr/validation.rs | 2 +- crates/ra_hir/src/generics.rs | 6 ++++-- crates/ra_hir/src/lib.rs | 7 ++++--- crates/ra_hir/src/path.rs | 1 - crates/ra_hir/src/resolve.rs | 2 +- crates/ra_hir/src/source_binder.rs | 3 +-- crates/ra_hir/src/ty/infer.rs | 3 +-- crates/ra_hir/src/ty/infer/expr.rs | 6 ++++-- crates/ra_hir/src/ty/infer/path.rs | 6 ++++-- crates/ra_hir/src/ty/lower.rs | 3 ++- 12 files changed, 27 insertions(+), 20 deletions(-) delete mode 100644 crates/ra_hir/src/path.rs (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index d238741ba..31857ad56 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs @@ -6,13 +6,13 @@ pub(crate) mod validation; use std::{ops::Index, sync::Arc}; +use hir_def::path::GenericArgs; use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; use ra_syntax::{ast, AstPtr}; use rustc_hash::FxHashMap; use crate::{ db::HirDatabase, - path::GenericArgs, ty::primitive::{UncertainFloatTy, UncertainIntTy}, type_ref::{Mutability, TypeRef}, DefWithBody, Either, HasSource, Name, Path, Resolver, Source, diff --git a/crates/ra_hir/src/expr/lower.rs b/crates/ra_hir/src/expr/lower.rs index cf8a41b1e..6436c3a24 100644 --- a/crates/ra_hir/src/expr/lower.rs +++ b/crates/ra_hir/src/expr/lower.rs @@ -1,6 +1,9 @@ //! FIXME: write short doc here -use hir_def::name::{self, AsName, Name}; +use hir_def::{ + name::{self, AsName, Name}, + path::GenericArgs, +}; use ra_arena::Arena; use ra_syntax::{ ast::{ @@ -13,7 +16,6 @@ use test_utils::tested_by; use crate::{ db::HirDatabase, - path::GenericArgs, ty::primitive::{FloatTy, IntTy, UncertainFloatTy, UncertainIntTy}, type_ref::TypeRef, AstId, DefWithBody, Either, HirFileId, MacroCallLoc, MacroFileKind, Mutability, Path, Resolver, diff --git a/crates/ra_hir/src/expr/validation.rs b/crates/ra_hir/src/expr/validation.rs index 1aa853c3e..c685edda1 100644 --- a/crates/ra_hir/src/expr/validation.rs +++ b/crates/ra_hir/src/expr/validation.rs @@ -2,6 +2,7 @@ use std::sync::Arc; +use hir_def::path::known; use ra_syntax::ast; use rustc_hash::FxHashSet; @@ -9,7 +10,6 @@ use crate::{ db::HirDatabase, diagnostics::{DiagnosticSink, MissingFields, MissingOkInTailExpr}, expr::AstPtr, - path::known, ty::{ApplicationTy, InferenceResult, Ty, TypeCtor}, Adt, Function, Name, Path, }; diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs index 61786a614..45f9713a0 100644 --- a/crates/ra_hir/src/generics.rs +++ b/crates/ra_hir/src/generics.rs @@ -5,12 +5,14 @@ use std::sync::Arc; -use hir_def::name::{self, AsName}; +use hir_def::{ + name::{self, AsName}, + path::Path, +}; use ra_syntax::ast::{self, DefaultTypeParamOwner, NameOwner, TypeBoundsOwner, TypeParamsOwner}; use crate::{ db::{AstDatabase, DefDatabase, HirDatabase}, - path::Path, type_ref::{TypeBound, TypeRef}, Adt, Const, Container, Enum, EnumVariant, Function, HasSource, ImplBlock, Name, Struct, Trait, TypeAlias, Union, diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 620911459..e723a1f40 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -32,7 +32,6 @@ pub mod debug; pub mod db; #[macro_use] pub mod mock; -mod path; pub mod source_binder; mod ids; @@ -71,7 +70,6 @@ pub use crate::{ ids::{HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile}, impl_block::ImplBlock, nameres::{ImportId, Namespace, PerNs}, - path::{Path, PathKind}, resolve::ScopeDef, source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer}, ty::{ @@ -88,4 +86,7 @@ pub use self::code_model::{ ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, }; -pub use hir_def::name::Name; +pub use hir_def::{ + name::Name, + path::{Path, PathKind}, +}; diff --git a/crates/ra_hir/src/path.rs b/crates/ra_hir/src/path.rs deleted file mode 100644 index 7f0ff4bfc..000000000 --- a/crates/ra_hir/src/path.rs +++ /dev/null @@ -1 +0,0 @@ -pub use hir_def::path::*; diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index b9459552b..2a783b61e 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs @@ -3,6 +3,7 @@ use std::sync::Arc; use hir_def::{ name::{self, Name}, + path::{Path, PathKind}, CrateModuleId, }; use rustc_hash::FxHashSet; @@ -17,7 +18,6 @@ use crate::{ generics::GenericParams, impl_block::ImplBlock, nameres::{CrateDefMap, PerNs}, - path::{Path, PathKind}, Adt, BuiltinType, Const, Enum, EnumVariant, Function, MacroDef, ModuleDef, Static, Struct, Trait, TypeAlias, }; diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 8a1fa29a4..544433a0a 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -7,7 +7,7 @@ //! purely for "IDE needs". use std::sync::Arc; -use hir_def::name::AsName; +use hir_def::{name::AsName, path::known}; use ra_db::FileId; use ra_syntax::{ ast::{self, AstNode}, @@ -25,7 +25,6 @@ use crate::{ BodySourceMap, }, ids::LocationCtx, - path::known, resolve::{ScopeDef, TypeNs, ValueNs}, ty::method_resolution::implements_trait, Const, DefWithBody, Either, Enum, FromSource, Function, HasBody, HirFileId, MacroDef, Module, diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 92b8e718e..05c6b5aad 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -21,7 +21,7 @@ use std::sync::Arc; use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue}; use rustc_hash::FxHashMap; -use hir_def::name; +use hir_def::{name, path::known}; use ra_arena::map::ArenaMap; use ra_prof::profile; use test_utils::tested_by; @@ -38,7 +38,6 @@ use crate::{ db::HirDatabase, diagnostics::DiagnosticSink, expr::{BindingAnnotation, Body, ExprId, PatId}, - path::known, resolve::{Resolver, TypeNs}, ty::infer::diagnostics::InferenceDiagnostic, type_ref::{Mutability, TypeRef}, diff --git a/crates/ra_hir/src/ty/infer/expr.rs b/crates/ra_hir/src/ty/infer/expr.rs index 7ef87bfe2..bc6437b44 100644 --- a/crates/ra_hir/src/ty/infer/expr.rs +++ b/crates/ra_hir/src/ty/infer/expr.rs @@ -3,7 +3,10 @@ use std::iter::{repeat, repeat_with}; use std::sync::Arc; -use hir_def::name; +use hir_def::{ + name, + path::{GenericArg, GenericArgs}, +}; use super::{BindingMode, Expectation, InferenceContext, InferenceDiagnostic, TypeMismatch}; use crate::{ @@ -11,7 +14,6 @@ use crate::{ expr::{self, Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, generics::{GenericParams, HasGenericParams}, nameres::Namespace, - path::{GenericArg, GenericArgs}, ty::{ autoderef, method_resolution, op, primitive, CallableDef, InferTy, Mutability, Obligation, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk, diff --git a/crates/ra_hir/src/ty/infer/path.rs b/crates/ra_hir/src/ty/infer/path.rs index db979353a..77aa35ce1 100644 --- a/crates/ra_hir/src/ty/infer/path.rs +++ b/crates/ra_hir/src/ty/infer/path.rs @@ -1,5 +1,7 @@ //! Path expression resolution. +use hir_def::path::PathSegment; + use super::{ExprOrPatId, InferenceContext, TraitRef}; use crate::{ db::HirDatabase, @@ -131,7 +133,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { fn resolve_trait_assoc_item( &mut self, trait_ref: TraitRef, - segment: &crate::path::PathSegment, + segment: &PathSegment, id: ExprOrPatId, ) -> Option<(ValueNs, Option)> { let trait_ = trait_ref.trait_; @@ -170,7 +172,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { fn resolve_ty_assoc_item( &mut self, ty: Ty, - segment: &crate::path::PathSegment, + segment: &PathSegment, id: ExprOrPatId, ) -> Option<(ValueNs, Option)> { if let Ty::Unknown = ty { diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index 366556134..b131b306c 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs @@ -8,6 +8,8 @@ use std::iter; use std::sync::Arc; +use hir_def::path::{GenericArg, PathSegment}; + use super::{ FnSig, GenericPredicate, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk, @@ -18,7 +20,6 @@ use crate::{ generics::HasGenericParams, generics::{GenericDef, WherePredicate}, nameres::Namespace, - path::{GenericArg, PathSegment}, resolve::{Resolver, TypeNs}, ty::Adt, type_ref::{TypeBound, TypeRef}, -- cgit v1.2.3 From e5300ad3baf80c9903235a98a12b6cfd409e9f10 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 30 Oct 2019 17:28:30 +0300 Subject: remove forward pointer for type_ref --- crates/ra_hir/src/adt.rs | 3 +-- crates/ra_hir/src/code_model.rs | 3 +-- crates/ra_hir/src/expr.rs | 6 ++++-- crates/ra_hir/src/expr/lower.rs | 2 +- crates/ra_hir/src/generics.rs | 2 +- crates/ra_hir/src/impl_block.rs | 2 +- crates/ra_hir/src/lib.rs | 3 +-- crates/ra_hir/src/ty.rs | 4 ++-- crates/ra_hir/src/ty/infer.rs | 7 +++++-- crates/ra_hir/src/ty/infer/coerce.rs | 3 +-- crates/ra_hir/src/ty/lower.rs | 6 ++++-- crates/ra_hir/src/ty/method_resolution.rs | 3 +-- crates/ra_hir/src/type_alias.rs | 6 ++++-- crates/ra_hir/src/type_ref.rs | 1 - 14 files changed, 27 insertions(+), 24 deletions(-) delete mode 100644 crates/ra_hir/src/type_ref.rs (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs index ce64980bb..d16b3a1cc 100644 --- a/crates/ra_hir/src/adt.rs +++ b/crates/ra_hir/src/adt.rs @@ -3,13 +3,12 @@ use std::sync::Arc; -use hir_def::name::AsName; +use hir_def::{name::AsName, type_ref::TypeRef}; use ra_arena::{impl_arena_id, Arena, RawId}; use ra_syntax::ast::{self, NameOwner, StructKind, TypeAscriptionOwner}; use crate::{ db::{AstDatabase, DefDatabase, HirDatabase}, - type_ref::TypeRef, Enum, EnumVariant, FieldSource, HasSource, Module, Name, Source, Struct, StructField, }; diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 7848d0a3f..d865c972e 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -10,6 +10,7 @@ use hir_def::{ 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 ra_db::{CrateId, Edition}; @@ -33,8 +34,6 @@ use crate::{ primitive::{FloatBitness, FloatTy, IntBitness, IntTy, Signedness}, InferenceResult, TraitRef, }, - type_ref::Mutability, - type_ref::TypeRef, Either, HasSource, Name, Ty, }; diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index 31857ad56..6e23197a4 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs @@ -6,7 +6,10 @@ pub(crate) mod validation; use std::{ops::Index, sync::Arc}; -use hir_def::path::GenericArgs; +use hir_def::{ + path::GenericArgs, + type_ref::{Mutability, TypeRef}, +}; use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; use ra_syntax::{ast, AstPtr}; use rustc_hash::FxHashMap; @@ -14,7 +17,6 @@ use rustc_hash::FxHashMap; use crate::{ db::HirDatabase, ty::primitive::{UncertainFloatTy, UncertainIntTy}, - type_ref::{Mutability, TypeRef}, DefWithBody, Either, HasSource, Name, Path, Resolver, Source, }; diff --git a/crates/ra_hir/src/expr/lower.rs b/crates/ra_hir/src/expr/lower.rs index 6436c3a24..ad029b868 100644 --- a/crates/ra_hir/src/expr/lower.rs +++ b/crates/ra_hir/src/expr/lower.rs @@ -3,6 +3,7 @@ use hir_def::{ name::{self, AsName, Name}, path::GenericArgs, + type_ref::TypeRef, }; use ra_arena::Arena; use ra_syntax::{ @@ -17,7 +18,6 @@ use test_utils::tested_by; use crate::{ db::HirDatabase, ty::primitive::{FloatTy, IntTy, UncertainFloatTy, UncertainIntTy}, - type_ref::TypeRef, AstId, DefWithBody, Either, HirFileId, MacroCallLoc, MacroFileKind, Mutability, Path, Resolver, Source, }; diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs index 45f9713a0..9d5d18564 100644 --- a/crates/ra_hir/src/generics.rs +++ b/crates/ra_hir/src/generics.rs @@ -8,12 +8,12 @@ use std::sync::Arc; use hir_def::{ name::{self, AsName}, path::Path, + type_ref::{TypeBound, TypeRef}, }; use ra_syntax::ast::{self, DefaultTypeParamOwner, NameOwner, TypeBoundsOwner, TypeParamsOwner}; use crate::{ db::{AstDatabase, DefDatabase, HirDatabase}, - type_ref::{TypeBound, TypeRef}, Adt, Const, Container, Enum, EnumVariant, Function, HasSource, ImplBlock, Name, Struct, Trait, TypeAlias, Union, }; diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index 06f21fc33..8584686fd 100644 --- a/crates/ra_hir/src/impl_block.rs +++ b/crates/ra_hir/src/impl_block.rs @@ -3,6 +3,7 @@ use rustc_hash::FxHashMap; use std::sync::Arc; +use hir_def::type_ref::TypeRef; use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; use ra_cfg::CfgOptions; use ra_syntax::{ @@ -19,7 +20,6 @@ use crate::{ ids::MacroCallLoc, resolve::Resolver, ty::Ty, - type_ref::TypeRef, AssocItem, AstId, Const, Function, HasSource, HirFileId, MacroFileKind, Path, Source, TraitRef, TypeAlias, }; diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index e723a1f40..4dd99c74f 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -39,7 +39,6 @@ mod nameres; mod adt; mod traits; mod type_alias; -mod type_ref; mod ty; mod attr; mod impl_block; @@ -75,7 +74,6 @@ pub use crate::{ ty::{ display::HirDisplay, ApplicationTy, CallableDef, Substs, TraitRef, Ty, TypeCtor, TypeWalk, }, - type_ref::Mutability, }; pub use self::code_model::{ @@ -89,4 +87,5 @@ pub use self::code_model::{ pub use hir_def::{ name::Name, path::{Path, PathKind}, + type_ref::Mutability, }; diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index cc9746f6d..d2bfcdc7d 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs @@ -17,8 +17,8 @@ use std::sync::Arc; use std::{fmt, iter, mem}; use crate::{ - db::HirDatabase, expr::ExprId, type_ref::Mutability, util::make_mut_slice, Adt, Crate, - DefWithBody, GenericParams, HasGenericParams, Name, Trait, TypeAlias, + db::HirDatabase, expr::ExprId, util::make_mut_slice, Adt, Crate, DefWithBody, GenericParams, + HasGenericParams, Mutability, Name, Trait, TypeAlias, }; use display::{HirDisplay, HirFormatter}; diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 05c6b5aad..7466ee341 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -21,7 +21,11 @@ use std::sync::Arc; use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue}; use rustc_hash::FxHashMap; -use hir_def::{name, path::known}; +use hir_def::{ + name, + path::known, + type_ref::{Mutability, TypeRef}, +}; use ra_arena::map::ArenaMap; use ra_prof::profile; use test_utils::tested_by; @@ -40,7 +44,6 @@ use crate::{ expr::{BindingAnnotation, Body, ExprId, PatId}, resolve::{Resolver, TypeNs}, ty::infer::diagnostics::InferenceDiagnostic, - type_ref::{Mutability, TypeRef}, Adt, AssocItem, ConstData, DefWithBody, FnData, Function, HasBody, Path, StructField, }; diff --git a/crates/ra_hir/src/ty/infer/coerce.rs b/crates/ra_hir/src/ty/infer/coerce.rs index 0429a9866..6ea135126 100644 --- a/crates/ra_hir/src/ty/infer/coerce.rs +++ b/crates/ra_hir/src/ty/infer/coerce.rs @@ -14,8 +14,7 @@ use crate::{ lang_item::LangItemTarget, resolve::Resolver, ty::{autoderef, Substs, Ty, TypeCtor, TypeWalk}, - type_ref::Mutability, - Adt, + Adt, Mutability, }; impl<'a, D: HirDatabase> InferenceContext<'a, D> { diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index b131b306c..0f49a0e54 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs @@ -8,7 +8,10 @@ use std::iter; use std::sync::Arc; -use hir_def::path::{GenericArg, PathSegment}; +use hir_def::{ + path::{GenericArg, PathSegment}, + type_ref::{TypeBound, TypeRef}, +}; use super::{ FnSig, GenericPredicate, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, @@ -22,7 +25,6 @@ use crate::{ nameres::Namespace, resolve::{Resolver, TypeNs}, ty::Adt, - type_ref::{TypeBound, TypeRef}, util::make_mut_slice, BuiltinType, Const, Enum, EnumVariant, Function, ModuleDef, Path, Static, Struct, StructField, Trait, TypeAlias, Union, diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs index 50583a142..eb69344f6 100644 --- a/crates/ra_hir/src/ty/method_resolution.rs +++ b/crates/ra_hir/src/ty/method_resolution.rs @@ -15,8 +15,7 @@ use crate::{ resolve::Resolver, ty::primitive::{FloatBitness, UncertainFloatTy, UncertainIntTy}, ty::{Ty, TypeCtor}, - type_ref::Mutability, - AssocItem, Crate, Function, Module, Name, Trait, + AssocItem, Crate, Function, Module, Mutability, Name, Trait, }; /// This is used as a key for indexing impls. diff --git a/crates/ra_hir/src/type_alias.rs b/crates/ra_hir/src/type_alias.rs index 18c01e1b9..87126ee7f 100644 --- a/crates/ra_hir/src/type_alias.rs +++ b/crates/ra_hir/src/type_alias.rs @@ -2,12 +2,14 @@ use std::sync::Arc; -use hir_def::name::{AsName, Name}; +use hir_def::{ + name::{AsName, Name}, + type_ref::TypeRef, +}; use ra_syntax::ast::NameOwner; use crate::{ db::{AstDatabase, DefDatabase}, - type_ref::TypeRef, HasSource, TypeAlias, }; diff --git a/crates/ra_hir/src/type_ref.rs b/crates/ra_hir/src/type_ref.rs deleted file mode 100644 index bd56ddbe6..000000000 --- a/crates/ra_hir/src/type_ref.rs +++ /dev/null @@ -1 +0,0 @@ -pub use hir_def::type_ref::*; -- cgit v1.2.3 From c1ed9ccc4ed7dfff3abb6eb01d7c311c8e31108c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 30 Oct 2019 17:40:13 +0300 Subject: fix compilation --- crates/ra_hir/src/db.rs | 7 +++++-- crates/ra_hir/src/either.rs | 1 - crates/ra_hir/src/lib.rs | 3 +-- crates/ra_hir/src/mock.rs | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) delete mode 100644 crates/ra_hir/src/either.rs (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index 142d7338d..ebfd970eb 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -23,7 +23,10 @@ use crate::{ Struct, StructField, Trait, TypeAlias, }; -pub use hir_def::db::{InternDatabase, InternDatabaseStorage}; +pub use hir_def::db::{ + DefDatabase2, DefDatabase2Storage, InternDatabase, InternDatabaseStorage, RawItemsQuery, + RawItemsWithSourceMapQuery, +}; pub use hir_expand::db::{ AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery, ParseMacroQuery, @@ -32,7 +35,7 @@ pub use hir_expand::db::{ // This database uses `AstDatabase` internally, #[salsa::query_group(DefDatabaseStorage)] #[salsa::requires(AstDatabase)] -pub trait DefDatabase: HirDebugDatabase + hir_def::db::DefDatabase2 { +pub trait DefDatabase: HirDebugDatabase + DefDatabase2 { #[salsa::invoke(crate::adt::StructData::struct_data_query)] fn struct_data(&self, s: Struct) -> Arc; diff --git a/crates/ra_hir/src/either.rs b/crates/ra_hir/src/either.rs deleted file mode 100644 index 44498dd38..000000000 --- a/crates/ra_hir/src/either.rs +++ /dev/null @@ -1 +0,0 @@ -pub use hir_def::either::*; diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 4dd99c74f..fabe6eff6 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -26,7 +26,6 @@ macro_rules! impl_froms { } } -mod either; pub mod debug; pub mod db; @@ -62,7 +61,6 @@ use crate::{ids::MacroFileKind, resolve::Resolver}; pub use crate::{ adt::VariantDef, - either::Either, expr::ExprScopes, from_source::FromSource, generics::{GenericDef, GenericParam, GenericParams, HasGenericParams}, @@ -85,6 +83,7 @@ pub use self::code_model::{ }; pub use hir_def::{ + either::Either, name::Name, path::{Path, PathKind}, type_ref::Mutability, diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs index bb2d78abe..35dfaf3ba 100644 --- a/crates/ra_hir/src/mock.rs +++ b/crates/ra_hir/src/mock.rs @@ -17,12 +17,12 @@ use crate::{db, debug::HirDebugHelper, diagnostics::DiagnosticSink}; pub const WORKSPACE: SourceRootId = SourceRootId(0); #[salsa::database( - hir_def::db::DefDatabase2Storage, ra_db::SourceDatabaseExtStorage, ra_db::SourceDatabaseStorage, db::InternDatabaseStorage, db::AstDatabaseStorage, db::DefDatabaseStorage, + db::DefDatabase2Storage, db::HirDatabaseStorage )] #[derive(Debug)] -- cgit v1.2.3 From e34e71c62d9b4cf0ab237969e03ecde893ab347b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 30 Oct 2019 18:06:08 +0300 Subject: remove forward pointer for attrs --- crates/ra_hir/src/attr.rs | 1 - crates/ra_hir/src/impl_block.rs | 3 +-- crates/ra_hir/src/lib.rs | 1 - crates/ra_hir/src/nameres/collector.rs | 3 +-- 4 files changed, 2 insertions(+), 6 deletions(-) delete mode 100644 crates/ra_hir/src/attr.rs (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/attr.rs b/crates/ra_hir/src/attr.rs deleted file mode 100644 index 988a671b8..000000000 --- a/crates/ra_hir/src/attr.rs +++ /dev/null @@ -1 +0,0 @@ -pub use hir_def::attr::*; diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index 8584686fd..518330713 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::type_ref::TypeRef; +use hir_def::{attr::Attr, type_ref::TypeRef}; use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; use ra_cfg::CfgOptions; use ra_syntax::{ @@ -12,7 +12,6 @@ use ra_syntax::{ }; use crate::{ - attr::Attr, code_model::{Module, ModuleSource}, db::{AstDatabase, DefDatabase, HirDatabase}, generics::HasGenericParams, diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index fabe6eff6..f765490b0 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -39,7 +39,6 @@ mod adt; mod traits; mod type_alias; mod ty; -mod attr; mod impl_block; mod expr; mod lang_item; diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index 1f3849dc7..2f342870b 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs @@ -1,6 +1,6 @@ //! FIXME: write short doc here -use hir_def::{name, nameres::raw}; +use hir_def::{attr::Attr, name, nameres::raw}; use ra_cfg::CfgOptions; use ra_db::FileId; use ra_syntax::{ast, SmolStr}; @@ -8,7 +8,6 @@ use rustc_hash::FxHashMap; use test_utils::tested_by; use crate::{ - attr::Attr, db::DefDatabase, ids::{AstItemDef, LocationCtx, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind}, nameres::{ -- cgit v1.2.3