From 8fc20b65035d93bcc1b3a89127916bd165a8d938 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 20 Dec 2019 11:59:50 +0100 Subject: Rename ContainerId -> AssocContainerId --- crates/ra_hir_def/src/body/lower.rs | 4 ++-- crates/ra_hir_def/src/data.rs | 12 ++++++------ crates/ra_hir_def/src/lib.rs | 18 +++++++++--------- crates/ra_hir_def/src/nameres/collector.rs | 8 ++++---- crates/ra_hir_def/src/resolver.rs | 16 ++++++++-------- 5 files changed, 29 insertions(+), 29 deletions(-) (limited to 'crates/ra_hir_def/src') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 17efa10e2..afd5231cc 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -25,7 +25,7 @@ use crate::{ path::GenericArgs, path::Path, type_ref::{Mutability, TypeRef}, - ContainerId, DefWithBodyId, FunctionLoc, Intern, + AssocContainerId, DefWithBodyId, FunctionLoc, Intern, }; pub(super) fn lower( @@ -490,7 +490,7 @@ where } fn collect_block_items(&mut self, block: &ast::Block) { - let container = ContainerId::DefWithBodyId(self.def); + let container = AssocContainerId::DefWithBodyId(self.def); for item in block.items() { match item { ast::ModuleItem::FnDef(def) => { diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index 4f4ef57cc..14e86936b 100644 --- a/crates/ra_hir_def/src/data.rs +++ b/crates/ra_hir_def/src/data.rs @@ -12,8 +12,8 @@ use crate::{ db::DefDatabase, src::HasSource, type_ref::{Mutability, TypeRef}, - AssocItemId, ConstId, ConstLoc, ContainerId, FunctionId, FunctionLoc, ImplId, Intern, Lookup, - StaticId, TraitId, TypeAliasId, TypeAliasLoc, + AssocContainerId, AssocItemId, ConstId, ConstLoc, FunctionId, FunctionLoc, ImplId, Intern, + Lookup, StaticId, TraitId, TypeAliasId, TypeAliasLoc, }; #[derive(Debug, Clone, PartialEq, Eq)] @@ -99,7 +99,7 @@ impl TraitData { let auto = src.value.is_auto(); let ast_id_map = db.ast_id_map(src.file_id); - let container = ContainerId::TraitId(tr); + let container = AssocContainerId::TraitId(tr); let items = if let Some(item_list) = src.value.item_list() { item_list .impl_items() @@ -180,7 +180,7 @@ impl ImplData { .map(|item_node| match item_node { ast::ImplItem::FnDef(it) => { let def = FunctionLoc { - container: ContainerId::ImplId(id), + container: AssocContainerId::ImplId(id), ast_id: AstId::new(src.file_id, items.ast_id(&it)), } .intern(db); @@ -188,7 +188,7 @@ impl ImplData { } ast::ImplItem::ConstDef(it) => { let def = ConstLoc { - container: ContainerId::ImplId(id), + container: AssocContainerId::ImplId(id), ast_id: AstId::new(src.file_id, items.ast_id(&it)), } .intern(db); @@ -196,7 +196,7 @@ impl ImplData { } ast::ImplItem::TypeAliasDef(it) => { let def = TypeAliasLoc { - container: ContainerId::ImplId(id), + container: AssocContainerId::ImplId(id), ast_id: AstId::new(src.file_id, items.ast_id(&it)), } .intern(db); diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 4fc3127c4..3d42762ae 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs @@ -71,7 +71,7 @@ impl_intern_key!(FunctionId); #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct FunctionLoc { - pub container: ContainerId, + pub container: AssocContainerId, pub ast_id: AstId, } @@ -187,7 +187,7 @@ pub struct ConstId(salsa::InternId); impl_intern_key!(ConstId); #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ConstLoc { - pub container: ContainerId, + pub container: AssocContainerId, pub ast_id: AstId, } @@ -259,7 +259,7 @@ impl_intern_key!(TypeAliasId); #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TypeAliasLoc { - pub container: ContainerId, + pub container: AssocContainerId, pub ast_id: AstId, } @@ -331,7 +331,7 @@ pub struct LocalTypeParamId(RawId); impl_arena_id!(LocalTypeParamId); #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub enum ContainerId { +pub enum AssocContainerId { ModuleId(ModuleId), ImplId(ImplId), TraitId(TraitId), @@ -479,13 +479,13 @@ pub trait HasModule { fn module(&self, db: &impl db::DefDatabase) -> ModuleId; } -impl HasModule for ContainerId { +impl HasModule for AssocContainerId { fn module(&self, db: &impl db::DefDatabase) -> ModuleId { match *self { - ContainerId::ModuleId(it) => it, - ContainerId::ImplId(it) => it.lookup(db).container, - ContainerId::TraitId(it) => it.lookup(db).container, - ContainerId::DefWithBodyId(it) => it.module(db), + AssocContainerId::ModuleId(it) => it, + AssocContainerId::ImplId(it) => it.lookup(db).container, + AssocContainerId::TraitId(it) => it.lookup(db).container, + AssocContainerId::DefWithBodyId(it) => it.module(db), } } } diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 8bbf7ffa2..848959f7c 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs @@ -24,7 +24,7 @@ use crate::{ }, path::{ModPath, PathKind}, per_ns::PerNs, - AdtId, AstId, ConstLoc, ContainerId, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern, + AdtId, AssocContainerId, AstId, ConstLoc, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern, LocalImportId, LocalModuleId, ModuleDefId, ModuleId, StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, UnionLoc, }; @@ -763,7 +763,7 @@ where let def: PerNs = match def.kind { raw::DefKind::Function(ast_id) => { let def = FunctionLoc { - container: ContainerId::ModuleId(module), + container: AssocContainerId::ModuleId(module), ast_id: AstId::new(self.file_id, ast_id), } .intern(self.def_collector.db); @@ -787,7 +787,7 @@ where } raw::DefKind::Const(ast_id) => { let def = ConstLoc { - container: ContainerId::ModuleId(module), + container: AssocContainerId::ModuleId(module), ast_id: AstId::new(self.file_id, ast_id), } .intern(self.def_collector.db); @@ -808,7 +808,7 @@ where } raw::DefKind::TypeAlias(ast_id) => { let def = TypeAliasLoc { - container: ContainerId::ModuleId(module), + container: AssocContainerId::ModuleId(module), ast_id: AstId::new(self.file_id, ast_id), } .intern(self.def_collector.db); diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs index 250329271..d79c9813b 100644 --- a/crates/ra_hir_def/src/resolver.rs +++ b/crates/ra_hir_def/src/resolver.rs @@ -17,9 +17,9 @@ use crate::{ nameres::{BuiltinShadowMode, CrateDefMap}, path::{ModPath, PathKind}, per_ns::PerNs, - AdtId, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, GenericDefId, - HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId, StaticId, StructId, TraitId, - TypeAliasId, TypeParamId, VariantId, + AdtId, AssocContainerId, ConstId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, + GenericDefId, HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId, StaticId, + StructId, TraitId, TypeAliasId, TypeParamId, VariantId, }; #[derive(Debug, Clone, Default)] @@ -580,13 +580,13 @@ impl HasResolver for DefWithBodyId { } } -impl HasResolver for ContainerId { +impl HasResolver for AssocContainerId { fn resolver(self, db: &impl DefDatabase) -> Resolver { match self { - ContainerId::TraitId(it) => it.resolver(db), - ContainerId::ImplId(it) => it.resolver(db), - ContainerId::ModuleId(it) => it.resolver(db), - ContainerId::DefWithBodyId(it) => it.resolver(db), + AssocContainerId::TraitId(it) => it.resolver(db), + AssocContainerId::ImplId(it) => it.resolver(db), + AssocContainerId::ModuleId(it) => it.resolver(db), + AssocContainerId::DefWithBodyId(it) => it.resolver(db), } } } -- cgit v1.2.3 From 94ad07af4bef6a70602e315bf315c6fce95618dd Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 20 Dec 2019 12:07:23 +0100 Subject: Introduce `ContainerId` --- crates/ra_hir_def/src/body/lower.rs | 4 ++-- crates/ra_hir_def/src/lib.rs | 22 ++++++++++++++++++---- crates/ra_hir_def/src/nameres/collector.rs | 9 +++++---- crates/ra_hir_def/src/resolver.rs | 18 +++++++++++++----- 4 files changed, 38 insertions(+), 15 deletions(-) (limited to 'crates/ra_hir_def/src') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index afd5231cc..0103a1aab 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -25,7 +25,7 @@ use crate::{ path::GenericArgs, path::Path, type_ref::{Mutability, TypeRef}, - AssocContainerId, DefWithBodyId, FunctionLoc, Intern, + ContainerId, DefWithBodyId, FunctionLoc, Intern, }; pub(super) fn lower( @@ -490,7 +490,7 @@ where } fn collect_block_items(&mut self, block: &ast::Block) { - let container = AssocContainerId::DefWithBodyId(self.def); + let container = ContainerId::DefWithBodyId(self.def).into(); for item in block.items() { match item { ast::ModuleItem::FnDef(def) => { diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 3d42762ae..5e46db1aa 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs @@ -331,12 +331,18 @@ pub struct LocalTypeParamId(RawId); impl_arena_id!(LocalTypeParamId); #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub enum AssocContainerId { +pub enum ContainerId { ModuleId(ModuleId), + DefWithBodyId(DefWithBodyId), +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub enum AssocContainerId { + ContainerId(ContainerId), ImplId(ImplId), TraitId(TraitId), - DefWithBodyId(DefWithBodyId), } +impl_froms!(AssocContainerId: ContainerId); /// A Data Type #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] @@ -479,13 +485,21 @@ pub trait HasModule { fn module(&self, db: &impl db::DefDatabase) -> ModuleId; } +impl HasModule for ContainerId { + fn module(&self, db: &impl db::DefDatabase) -> ModuleId { + match *self { + ContainerId::ModuleId(it) => it, + ContainerId::DefWithBodyId(it) => it.module(db), + } + } +} + impl HasModule for AssocContainerId { fn module(&self, db: &impl db::DefDatabase) -> ModuleId { match *self { - AssocContainerId::ModuleId(it) => it, + AssocContainerId::ContainerId(it) => it.module(db), AssocContainerId::ImplId(it) => it.lookup(db).container, AssocContainerId::TraitId(it) => it.lookup(db).container, - AssocContainerId::DefWithBodyId(it) => it.module(db), } } } diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 848959f7c..0f3319f30 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs @@ -24,7 +24,7 @@ use crate::{ }, path::{ModPath, PathKind}, per_ns::PerNs, - AdtId, AssocContainerId, AstId, ConstLoc, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern, + AdtId, AstId, ConstLoc, ContainerId, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern, LocalImportId, LocalModuleId, ModuleDefId, ModuleId, StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, UnionLoc, }; @@ -760,10 +760,11 @@ where self.collect_derives(attrs, def); let name = def.name.clone(); + let container = ContainerId::ModuleId(module); let def: PerNs = match def.kind { raw::DefKind::Function(ast_id) => { let def = FunctionLoc { - container: AssocContainerId::ModuleId(module), + container: container.into(), ast_id: AstId::new(self.file_id, ast_id), } .intern(self.def_collector.db); @@ -787,7 +788,7 @@ where } raw::DefKind::Const(ast_id) => { let def = ConstLoc { - container: AssocContainerId::ModuleId(module), + container: container.into(), ast_id: AstId::new(self.file_id, ast_id), } .intern(self.def_collector.db); @@ -808,7 +809,7 @@ where } raw::DefKind::TypeAlias(ast_id) => { let def = TypeAliasLoc { - container: AssocContainerId::ModuleId(module), + container: container.into(), ast_id: AstId::new(self.file_id, ast_id), } .intern(self.def_collector.db); diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs index d79c9813b..af9d194f8 100644 --- a/crates/ra_hir_def/src/resolver.rs +++ b/crates/ra_hir_def/src/resolver.rs @@ -17,9 +17,9 @@ use crate::{ nameres::{BuiltinShadowMode, CrateDefMap}, path::{ModPath, PathKind}, per_ns::PerNs, - AdtId, AssocContainerId, ConstId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, - GenericDefId, HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId, StaticId, - StructId, TraitId, TypeAliasId, TypeParamId, VariantId, + AdtId, AssocContainerId, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId, + FunctionId, GenericDefId, HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId, + StaticId, StructId, TraitId, TypeAliasId, TypeParamId, VariantId, }; #[derive(Debug, Clone, Default)] @@ -580,13 +580,21 @@ impl HasResolver for DefWithBodyId { } } +impl HasResolver for ContainerId { + fn resolver(self, db: &impl DefDatabase) -> Resolver { + match self { + ContainerId::ModuleId(it) => it.resolver(db), + ContainerId::DefWithBodyId(it) => it.resolver(db), + } + } +} + impl HasResolver for AssocContainerId { fn resolver(self, db: &impl DefDatabase) -> Resolver { match self { + AssocContainerId::ContainerId(it) => it.resolver(db), AssocContainerId::TraitId(it) => it.resolver(db), AssocContainerId::ImplId(it) => it.resolver(db), - AssocContainerId::ModuleId(it) => it.resolver(db), - AssocContainerId::DefWithBodyId(it) => it.resolver(db), } } } -- cgit v1.2.3 From ac5a3f611b05dbedd286169539335ae9f0fbb7b0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 20 Dec 2019 12:20:49 +0100 Subject: Support for nested ADT --- crates/ra_hir_def/src/body/lower.rs | 26 +++++++++++++++++++------- crates/ra_hir_def/src/lib.rs | 9 +++++---- crates/ra_hir_def/src/nameres/collector.rs | 6 +++--- 3 files changed, 27 insertions(+), 14 deletions(-) (limited to 'crates/ra_hir_def/src') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 0103a1aab..0d3f946df 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -25,7 +25,7 @@ use crate::{ path::GenericArgs, path::Path, type_ref::{Mutability, TypeRef}, - ContainerId, DefWithBodyId, FunctionLoc, Intern, + ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, Intern, ModuleDefId, StructLoc, UnionLoc, }; pub(super) fn lower( @@ -490,16 +490,28 @@ where } fn collect_block_items(&mut self, block: &ast::Block) { - let container = ContainerId::DefWithBodyId(self.def).into(); + let container = ContainerId::DefWithBodyId(self.def); for item in block.items() { - match item { + let def: ModuleDefId = match item { ast::ModuleItem::FnDef(def) => { let ast_id = self.expander.ast_id(&def); - self.body.defs.push(FunctionLoc { container, ast_id }.intern(self.db).into()) + FunctionLoc { container: container.into(), ast_id }.intern(self.db).into() } - // FIXME: handle other items - _ => (), - } + ast::ModuleItem::StructDef(def) => { + let ast_id = self.expander.ast_id(&def); + StructLoc { container, ast_id }.intern(self.db).into() + } + ast::ModuleItem::EnumDef(def) => { + let ast_id = self.expander.ast_id(&def); + EnumLoc { container, ast_id }.intern(self.db).into() + } + ast::ModuleItem::UnionDef(def) => { + let ast_id = self.expander.ast_id(&def); + UnionLoc { container, ast_id }.intern(self.db).into() + } + _ => continue, + }; + self.body.defs.push(def) } } diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 5e46db1aa..a82de7dec 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs @@ -95,7 +95,7 @@ impl_intern_key!(StructId); #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct StructLoc { - pub container: ModuleId, + pub container: ContainerId, pub ast_id: AstId, } @@ -119,7 +119,7 @@ impl_intern_key!(UnionId); #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct UnionLoc { - pub container: ModuleId, + pub container: ContainerId, pub ast_id: AstId, } @@ -143,7 +143,7 @@ impl_intern_key!(EnumId); #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct EnumLoc { - pub container: ModuleId, + pub container: ContainerId, pub ast_id: AstId, } @@ -529,6 +529,7 @@ impl HasModule for AdtId { AdtId::UnionId(it) => it.lookup(db).container, AdtId::EnumId(it) => it.lookup(db).container, } + .module(db) } } @@ -550,7 +551,7 @@ impl HasModule for GenericDefId { GenericDefId::TraitId(it) => it.lookup(db).container, GenericDefId::TypeAliasId(it) => it.lookup(db).module(db), GenericDefId::ImplId(it) => it.lookup(db).container, - GenericDefId::EnumVariantId(it) => it.parent.lookup(db).container, + GenericDefId::EnumVariantId(it) => it.parent.lookup(db).container.module(db), GenericDefId::ConstId(it) => it.lookup(db).module(db), } } diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 0f3319f30..1b39af61e 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs @@ -772,17 +772,17 @@ where PerNs::values(def.into()) } raw::DefKind::Struct(ast_id) => { - let def = StructLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) } + let def = StructLoc { container, ast_id: AstId::new(self.file_id, ast_id) } .intern(self.def_collector.db); PerNs::both(def.into(), def.into()) } raw::DefKind::Union(ast_id) => { - let def = UnionLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) } + let def = UnionLoc { container, ast_id: AstId::new(self.file_id, ast_id) } .intern(self.def_collector.db); PerNs::both(def.into(), def.into()) } raw::DefKind::Enum(ast_id) => { - let def = EnumLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) } + let def = EnumLoc { container, ast_id: AstId::new(self.file_id, ast_id) } .intern(self.def_collector.db); PerNs::types(def.into()) } -- cgit v1.2.3 From fe1b160dcfdeb3f582ccae1440c9580ade0beb39 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 20 Dec 2019 12:22:55 +0100 Subject: Support for nested statics, consts and type aliases --- crates/ra_hir_def/src/body/lower.rs | 15 ++++++++++++++- crates/ra_hir_def/src/lib.rs | 6 +++--- crates/ra_hir_def/src/nameres/collector.rs | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) (limited to 'crates/ra_hir_def/src') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 0d3f946df..b61f924b7 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -25,7 +25,8 @@ use crate::{ path::GenericArgs, path::Path, type_ref::{Mutability, TypeRef}, - ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, Intern, ModuleDefId, StructLoc, UnionLoc, + ConstLoc, ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, Intern, ModuleDefId, StaticLoc, + StructLoc, TypeAliasLoc, UnionLoc, }; pub(super) fn lower( @@ -497,6 +498,18 @@ where let ast_id = self.expander.ast_id(&def); FunctionLoc { container: container.into(), ast_id }.intern(self.db).into() } + ast::ModuleItem::TypeAliasDef(def) => { + let ast_id = self.expander.ast_id(&def); + TypeAliasLoc { container: container.into(), ast_id }.intern(self.db).into() + } + ast::ModuleItem::ConstDef(def) => { + let ast_id = self.expander.ast_id(&def); + ConstLoc { container: container.into(), ast_id }.intern(self.db).into() + } + ast::ModuleItem::StaticDef(def) => { + let ast_id = self.expander.ast_id(&def); + StaticLoc { container, ast_id }.intern(self.db).into() + } ast::ModuleItem::StructDef(def) => { let ast_id = self.expander.ast_id(&def); StructLoc { container, ast_id }.intern(self.db).into() diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index a82de7dec..9b192b597 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs @@ -211,7 +211,7 @@ impl_intern_key!(StaticId); #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct StaticLoc { - pub container: ModuleId, + pub container: ContainerId, pub ast_id: AstId, } @@ -558,7 +558,7 @@ impl HasModule for GenericDefId { } impl HasModule for StaticLoc { - fn module(&self, _db: &impl db::DefDatabase) -> ModuleId { - self.container + fn module(&self, db: &impl db::DefDatabase) -> ModuleId { + self.container.module(db) } } diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 1b39af61e..74c3d4670 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs @@ -796,7 +796,7 @@ where PerNs::values(def.into()) } raw::DefKind::Static(ast_id) => { - let def = StaticLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) } + let def = StaticLoc { container, ast_id: AstId::new(self.file_id, ast_id) } .intern(self.def_collector.db); PerNs::values(def.into()) -- cgit v1.2.3 From f42697e54b9d0a040011cb04c266d51710e249f1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 20 Dec 2019 12:29:25 +0100 Subject: Support for nested traits --- crates/ra_hir_def/src/body/lower.rs | 11 +++++++++-- crates/ra_hir_def/src/lib.rs | 6 +++--- crates/ra_hir_def/src/nameres/collector.rs | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) (limited to 'crates/ra_hir_def/src') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index b61f924b7..853e17bae 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -26,7 +26,7 @@ use crate::{ path::Path, type_ref::{Mutability, TypeRef}, ConstLoc, ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, Intern, ModuleDefId, StaticLoc, - StructLoc, TypeAliasLoc, UnionLoc, + StructLoc, TraitLoc, TypeAliasLoc, UnionLoc, }; pub(super) fn lower( @@ -522,7 +522,14 @@ where let ast_id = self.expander.ast_id(&def); UnionLoc { container, ast_id }.intern(self.db).into() } - _ => continue, + ast::ModuleItem::TraitDef(def) => { + let ast_id = self.expander.ast_id(&def); + TraitLoc { container, ast_id }.intern(self.db).into() + } + ast::ModuleItem::ImplBlock(_) + | ast::ModuleItem::UseItem(_) + | ast::ModuleItem::ExternCrateItem(_) + | ast::ModuleItem::Module(_) => continue, }; self.body.defs.push(def) } diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 9b192b597..140eccf26 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs @@ -235,7 +235,7 @@ impl_intern_key!(TraitId); #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TraitLoc { - pub container: ModuleId, + pub container: ContainerId, pub ast_id: AstId, } @@ -499,7 +499,7 @@ impl HasModule for AssocContainerId { match *self { AssocContainerId::ContainerId(it) => it.module(db), AssocContainerId::ImplId(it) => it.lookup(db).container, - AssocContainerId::TraitId(it) => it.lookup(db).container, + AssocContainerId::TraitId(it) => it.lookup(db).container.module(db), } } } @@ -548,7 +548,7 @@ impl HasModule for GenericDefId { match self { GenericDefId::FunctionId(it) => it.lookup(db).module(db), GenericDefId::AdtId(it) => it.module(db), - GenericDefId::TraitId(it) => it.lookup(db).container, + GenericDefId::TraitId(it) => it.lookup(db).container.module(db), GenericDefId::TypeAliasId(it) => it.lookup(db).module(db), GenericDefId::ImplId(it) => it.lookup(db).container, GenericDefId::EnumVariantId(it) => it.parent.lookup(db).container.module(db), diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 74c3d4670..a1ea130e0 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs @@ -802,7 +802,7 @@ where PerNs::values(def.into()) } raw::DefKind::Trait(ast_id) => { - let def = TraitLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) } + let def = TraitLoc { container, ast_id: AstId::new(self.file_id, ast_id) } .intern(self.def_collector.db); PerNs::types(def.into()) -- cgit v1.2.3