aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-12-20 11:20:49 +0000
committerAleksey Kladov <[email protected]>2019-12-20 11:20:49 +0000
commitac5a3f611b05dbedd286169539335ae9f0fbb7b0 (patch)
treed3891e65a1f043c9adce655bb88507ade16ac0b9 /crates
parent94ad07af4bef6a70602e315bf315c6fce95618dd (diff)
Support for nested ADT
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/code_model.rs12
-rw-r--r--crates/ra_hir_def/src/body/lower.rs26
-rw-r--r--crates/ra_hir_def/src/lib.rs9
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs6
-rw-r--r--crates/ra_hir_ty/src/lower.rs4
5 files changed, 35 insertions, 22 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 8dbc0d667..d20e9de63 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -269,7 +269,7 @@ pub struct Struct {
269 269
270impl Struct { 270impl Struct {
271 pub fn module(self, db: &impl DefDatabase) -> Module { 271 pub fn module(self, db: &impl DefDatabase) -> Module {
272 Module { id: self.id.lookup(db).container } 272 Module { id: self.id.lookup(db).container.module(db) }
273 } 273 }
274 274
275 pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> { 275 pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> {
@@ -290,7 +290,7 @@ impl Struct {
290 } 290 }
291 291
292 pub fn ty(self, db: &impl HirDatabase) -> Type { 292 pub fn ty(self, db: &impl HirDatabase) -> Type {
293 Type::from_def(db, self.id.lookup(db).container.krate, self.id) 293 Type::from_def(db, self.id.lookup(db).container.module(db).krate, self.id)
294 } 294 }
295 295
296 fn variant_data(self, db: &impl DefDatabase) -> Arc<VariantData> { 296 fn variant_data(self, db: &impl DefDatabase) -> Arc<VariantData> {
@@ -309,11 +309,11 @@ impl Union {
309 } 309 }
310 310
311 pub fn module(self, db: &impl DefDatabase) -> Module { 311 pub fn module(self, db: &impl DefDatabase) -> Module {
312 Module { id: self.id.lookup(db).container } 312 Module { id: self.id.lookup(db).container.module(db) }
313 } 313 }
314 314
315 pub fn ty(self, db: &impl HirDatabase) -> Type { 315 pub fn ty(self, db: &impl HirDatabase) -> Type {
316 Type::from_def(db, self.id.lookup(db).container.krate, self.id) 316 Type::from_def(db, self.id.lookup(db).container.module(db).krate, self.id)
317 } 317 }
318 318
319 pub fn fields(self, db: &impl HirDatabase) -> Vec<StructField> { 319 pub fn fields(self, db: &impl HirDatabase) -> Vec<StructField> {
@@ -337,7 +337,7 @@ pub struct Enum {
337 337
338impl Enum { 338impl Enum {
339 pub fn module(self, db: &impl DefDatabase) -> Module { 339 pub fn module(self, db: &impl DefDatabase) -> Module {
340 Module { id: self.id.lookup(db).container } 340 Module { id: self.id.lookup(db).container.module(db) }
341 } 341 }
342 342
343 pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> { 343 pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> {
@@ -357,7 +357,7 @@ impl Enum {
357 } 357 }
358 358
359 pub fn ty(self, db: &impl HirDatabase) -> Type { 359 pub fn ty(self, db: &impl HirDatabase) -> Type {
360 Type::from_def(db, self.id.lookup(db).container.krate, self.id) 360 Type::from_def(db, self.id.lookup(db).container.module(db).krate, self.id)
361 } 361 }
362} 362}
363 363
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::{
25 path::GenericArgs, 25 path::GenericArgs,
26 path::Path, 26 path::Path,
27 type_ref::{Mutability, TypeRef}, 27 type_ref::{Mutability, TypeRef},
28 ContainerId, DefWithBodyId, FunctionLoc, Intern, 28 ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, Intern, ModuleDefId, StructLoc, UnionLoc,
29}; 29};
30 30
31pub(super) fn lower( 31pub(super) fn lower(
@@ -490,16 +490,28 @@ where
490 } 490 }
491 491
492 fn collect_block_items(&mut self, block: &ast::Block) { 492 fn collect_block_items(&mut self, block: &ast::Block) {
493 let container = ContainerId::DefWithBodyId(self.def).into(); 493 let container = ContainerId::DefWithBodyId(self.def);
494 for item in block.items() { 494 for item in block.items() {
495 match item { 495 let def: ModuleDefId = match item {
496 ast::ModuleItem::FnDef(def) => { 496 ast::ModuleItem::FnDef(def) => {
497 let ast_id = self.expander.ast_id(&def); 497 let ast_id = self.expander.ast_id(&def);
498 self.body.defs.push(FunctionLoc { container, ast_id }.intern(self.db).into()) 498 FunctionLoc { container: container.into(), ast_id }.intern(self.db).into()
499 } 499 }
500 // FIXME: handle other items 500 ast::ModuleItem::StructDef(def) => {
501 _ => (), 501 let ast_id = self.expander.ast_id(&def);
502 } 502 StructLoc { container, ast_id }.intern(self.db).into()
503 }
504 ast::ModuleItem::EnumDef(def) => {
505 let ast_id = self.expander.ast_id(&def);
506 EnumLoc { container, ast_id }.intern(self.db).into()
507 }
508 ast::ModuleItem::UnionDef(def) => {
509 let ast_id = self.expander.ast_id(&def);
510 UnionLoc { container, ast_id }.intern(self.db).into()
511 }
512 _ => continue,
513 };
514 self.body.defs.push(def)
503 } 515 }
504 } 516 }
505 517
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);
95 95
96#[derive(Debug, Clone, PartialEq, Eq, Hash)] 96#[derive(Debug, Clone, PartialEq, Eq, Hash)]
97pub struct StructLoc { 97pub struct StructLoc {
98 pub container: ModuleId, 98 pub container: ContainerId,
99 pub ast_id: AstId<ast::StructDef>, 99 pub ast_id: AstId<ast::StructDef>,
100} 100}
101 101
@@ -119,7 +119,7 @@ impl_intern_key!(UnionId);
119 119
120#[derive(Debug, Clone, PartialEq, Eq, Hash)] 120#[derive(Debug, Clone, PartialEq, Eq, Hash)]
121pub struct UnionLoc { 121pub struct UnionLoc {
122 pub container: ModuleId, 122 pub container: ContainerId,
123 pub ast_id: AstId<ast::UnionDef>, 123 pub ast_id: AstId<ast::UnionDef>,
124} 124}
125 125
@@ -143,7 +143,7 @@ impl_intern_key!(EnumId);
143 143
144#[derive(Debug, Clone, PartialEq, Eq, Hash)] 144#[derive(Debug, Clone, PartialEq, Eq, Hash)]
145pub struct EnumLoc { 145pub struct EnumLoc {
146 pub container: ModuleId, 146 pub container: ContainerId,
147 pub ast_id: AstId<ast::EnumDef>, 147 pub ast_id: AstId<ast::EnumDef>,
148} 148}
149 149
@@ -529,6 +529,7 @@ impl HasModule for AdtId {
529 AdtId::UnionId(it) => it.lookup(db).container, 529 AdtId::UnionId(it) => it.lookup(db).container,
530 AdtId::EnumId(it) => it.lookup(db).container, 530 AdtId::EnumId(it) => it.lookup(db).container,
531 } 531 }
532 .module(db)
532 } 533 }
533} 534}
534 535
@@ -550,7 +551,7 @@ impl HasModule for GenericDefId {
550 GenericDefId::TraitId(it) => it.lookup(db).container, 551 GenericDefId::TraitId(it) => it.lookup(db).container,
551 GenericDefId::TypeAliasId(it) => it.lookup(db).module(db), 552 GenericDefId::TypeAliasId(it) => it.lookup(db).module(db),
552 GenericDefId::ImplId(it) => it.lookup(db).container, 553 GenericDefId::ImplId(it) => it.lookup(db).container,
553 GenericDefId::EnumVariantId(it) => it.parent.lookup(db).container, 554 GenericDefId::EnumVariantId(it) => it.parent.lookup(db).container.module(db),
554 GenericDefId::ConstId(it) => it.lookup(db).module(db), 555 GenericDefId::ConstId(it) => it.lookup(db).module(db),
555 } 556 }
556 } 557 }
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
772 PerNs::values(def.into()) 772 PerNs::values(def.into())
773 } 773 }
774 raw::DefKind::Struct(ast_id) => { 774 raw::DefKind::Struct(ast_id) => {
775 let def = StructLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) } 775 let def = StructLoc { container, ast_id: AstId::new(self.file_id, ast_id) }
776 .intern(self.def_collector.db); 776 .intern(self.def_collector.db);
777 PerNs::both(def.into(), def.into()) 777 PerNs::both(def.into(), def.into())
778 } 778 }
779 raw::DefKind::Union(ast_id) => { 779 raw::DefKind::Union(ast_id) => {
780 let def = UnionLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) } 780 let def = UnionLoc { container, ast_id: AstId::new(self.file_id, ast_id) }
781 .intern(self.def_collector.db); 781 .intern(self.def_collector.db);
782 PerNs::both(def.into(), def.into()) 782 PerNs::both(def.into(), def.into())
783 } 783 }
784 raw::DefKind::Enum(ast_id) => { 784 raw::DefKind::Enum(ast_id) => {
785 let def = EnumLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) } 785 let def = EnumLoc { container, ast_id: AstId::new(self.file_id, ast_id) }
786 .intern(self.def_collector.db); 786 .intern(self.def_collector.db);
787 PerNs::types(def.into()) 787 PerNs::types(def.into())
788 } 788 }
diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/ra_hir_ty/src/lower.rs
index 2b84309d7..af3db2e1d 100644
--- a/crates/ra_hir_ty/src/lower.rs
+++ b/crates/ra_hir_ty/src/lower.rs
@@ -697,8 +697,8 @@ impl CallableDef {
697 pub fn krate(self, db: &impl HirDatabase) -> CrateId { 697 pub fn krate(self, db: &impl HirDatabase) -> CrateId {
698 match self { 698 match self {
699 CallableDef::FunctionId(f) => f.lookup(db).module(db), 699 CallableDef::FunctionId(f) => f.lookup(db).module(db),
700 CallableDef::StructId(s) => s.lookup(db).container, 700 CallableDef::StructId(s) => s.lookup(db).container.module(db),
701 CallableDef::EnumVariantId(e) => e.parent.lookup(db).container, 701 CallableDef::EnumVariantId(e) => e.parent.lookup(db).container.module(db),
702 } 702 }
703 .krate 703 .krate
704 } 704 }