From d87c16bea60f4972b0adf4dd69bbb9abcfca12d6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 24 Nov 2019 21:00:50 +0300 Subject: hir_def is fully doc'ed! --- crates/ra_hir_def/src/body/scope.rs | 2 +- crates/ra_hir_def/src/per_ns.rs | 5 ++++- crates/ra_hir_def/src/resolver.rs | 6 +++--- xtask/tests/tidy-tests/docs.rs | 1 - 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/ra_hir_def/src/body/scope.rs b/crates/ra_hir_def/src/body/scope.rs index 5240a59d5..625aa39dd 100644 --- a/crates/ra_hir_def/src/body/scope.rs +++ b/crates/ra_hir_def/src/body/scope.rs @@ -1,4 +1,4 @@ -//! FIXME: write short doc here +//! Name resolution for expressions. use std::sync::Arc; use hir_expand::name::Name; diff --git a/crates/ra_hir_def/src/per_ns.rs b/crates/ra_hir_def/src/per_ns.rs index 06ef6c9fc..00e866bf9 100644 --- a/crates/ra_hir_def/src/per_ns.rs +++ b/crates/ra_hir_def/src/per_ns.rs @@ -1,4 +1,7 @@ -//! FIXME: write short doc here +//! In rust, it is possible to have a value, a type and a macro with the same +//! name without conflicts. +//! +//! `PerNs` (per namespace) captures this. use hir_expand::MacroDefId; diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs index c24a9b165..1f8887c6b 100644 --- a/crates/ra_hir_def/src/resolver.rs +++ b/crates/ra_hir_def/src/resolver.rs @@ -29,20 +29,20 @@ pub struct Resolver { // FIXME how to store these best #[derive(Debug, Clone)] -pub(crate) struct ModuleItemMap { +struct ModuleItemMap { crate_def_map: Arc, module_id: LocalModuleId, } #[derive(Debug, Clone)] -pub(crate) struct ExprScope { +struct ExprScope { owner: DefWithBodyId, expr_scopes: Arc, scope_id: ScopeId, } #[derive(Debug, Clone)] -pub(crate) enum Scope { +enum Scope { /// All the items and imported names of a module ModuleScope(ModuleItemMap), /// Brings the generic parameters of an item into scope diff --git a/xtask/tests/tidy-tests/docs.rs b/xtask/tests/tidy-tests/docs.rs index 141219860..fae871285 100644 --- a/xtask/tests/tidy-tests/docs.rs +++ b/xtask/tests/tidy-tests/docs.rs @@ -74,7 +74,6 @@ fn no_docs_comments() { "ra_db", "ra_hir", "ra_hir_expand", - "ra_hir_def", "ra_ide_api", "ra_lsp_server", "ra_mbe", -- cgit v1.2.3 From 191b1d238fd1594ab74b1ab6a17dbe0430fc6b1a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 24 Nov 2019 21:03:24 +0300 Subject: Remove impl_block module --- crates/ra_hir/src/code_model.rs | 35 +++++++++++++++++++++++++ crates/ra_hir/src/code_model/src.rs | 10 +++++-- crates/ra_hir/src/impl_block.rs | 52 ------------------------------------- crates/ra_hir/src/lib.rs | 1 - 4 files changed, 43 insertions(+), 55 deletions(-) delete mode 100644 crates/ra_hir/src/impl_block.rs diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 263c557f3..96a5cc857 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -973,6 +973,41 @@ pub struct ImplBlock { pub(crate) id: ImplId, } +impl ImplBlock { + pub fn target_trait(&self, db: &impl DefDatabase) -> Option { + db.impl_data(self.id).target_trait.clone() + } + + pub fn target_type(&self, db: &impl DefDatabase) -> TypeRef { + db.impl_data(self.id).target_type.clone() + } + + pub fn target_ty(&self, db: &impl HirDatabase) -> Ty { + Ty::from_hir(db, &self.id.resolver(db), &self.target_type(db)) + } + + pub fn target_trait_ref(&self, db: &impl HirDatabase) -> Option { + let target_ty = self.target_ty(db); + TraitRef::from_hir(db, &self.id.resolver(db), &self.target_trait(db)?, Some(target_ty)) + } + + pub fn items(&self, db: &impl DefDatabase) -> Vec { + db.impl_data(self.id).items.iter().map(|it| (*it).into()).collect() + } + + pub fn is_negative(&self, db: &impl DefDatabase) -> bool { + db.impl_data(self.id).is_negative + } + + pub fn module(&self, db: &impl DefDatabase) -> Module { + self.id.module(db).into() + } + + pub fn krate(&self, db: &impl DefDatabase) -> Crate { + Crate { crate_id: self.module(db).id.krate } + } +} + /// For IDE only pub enum ScopeDef { ModuleDef(ModuleDef), diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs index a0e605603..a4e317c20 100644 --- a/crates/ra_hir/src/code_model/src.rs +++ b/crates/ra_hir/src/code_model/src.rs @@ -5,8 +5,8 @@ use hir_expand::either::Either; use ra_syntax::ast; use crate::{ - db::DefDatabase, Const, Enum, EnumVariant, FieldSource, Function, Import, MacroDef, Module, - ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, + db::DefDatabase, Const, Enum, EnumVariant, FieldSource, Function, ImplBlock, Import, MacroDef, + Module, ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, }; pub use hir_expand::Source; @@ -108,6 +108,12 @@ impl HasSource for MacroDef { Source { file_id: self.id.ast_id.file_id(), value: self.id.ast_id.to_node(db) } } } +impl HasSource for ImplBlock { + type Ast = ast::ImplBlock; + fn source(self, db: &impl DefDatabase) -> Source { + self.id.source(db) + } +} impl HasSource for Import { type Ast = Either; diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs deleted file mode 100644 index 334eeebac..000000000 --- a/crates/ra_hir/src/impl_block.rs +++ /dev/null @@ -1,52 +0,0 @@ -//! FIXME: write short doc here - -use hir_def::{resolver::HasResolver, type_ref::TypeRef, AstItemDef}; -use ra_syntax::ast; - -use crate::{ - db::{AstDatabase, DefDatabase, HirDatabase}, - ty::Ty, - AssocItem, Crate, HasSource, ImplBlock, Module, Source, TraitRef, -}; - -impl HasSource for ImplBlock { - type Ast = ast::ImplBlock; - fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source { - self.id.source(db) - } -} - -impl ImplBlock { - pub fn target_trait(&self, db: &impl DefDatabase) -> Option { - db.impl_data(self.id).target_trait.clone() - } - - pub fn target_type(&self, db: &impl DefDatabase) -> TypeRef { - db.impl_data(self.id).target_type.clone() - } - - pub fn target_ty(&self, db: &impl HirDatabase) -> Ty { - Ty::from_hir(db, &self.id.resolver(db), &self.target_type(db)) - } - - pub fn target_trait_ref(&self, db: &impl HirDatabase) -> Option { - let target_ty = self.target_ty(db); - TraitRef::from_hir(db, &self.id.resolver(db), &self.target_trait(db)?, Some(target_ty)) - } - - pub fn items(&self, db: &impl DefDatabase) -> Vec { - db.impl_data(self.id).items.iter().map(|it| (*it).into()).collect() - } - - pub fn is_negative(&self, db: &impl DefDatabase) -> bool { - db.impl_data(self.id).is_negative - } - - pub fn module(&self, db: &impl DefDatabase) -> Module { - self.id.module(db).into() - } - - pub fn krate(&self, db: &impl DefDatabase) -> Crate { - Crate { crate_id: self.module(db).id.krate } - } -} diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 70bba2efb..843ce6a88 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -32,7 +32,6 @@ pub mod db; pub mod source_binder; mod ty; -mod impl_block; mod expr; pub mod diagnostics; mod util; -- cgit v1.2.3