diff options
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 14 | ||||
-rw-r--r-- | crates/ra_hir_def/src/body/lower.rs | 44 | ||||
-rw-r--r-- | crates/ra_hir_def/src/data.rs | 12 | ||||
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 45 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 17 | ||||
-rw-r--r-- | crates/ra_hir_def/src/resolver.rs | 18 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/infer/expr.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/infer/path.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/lib.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/lower.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/method_resolution.rs | 10 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/traits/chalk.rs | 10 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/utils.rs | 8 |
13 files changed, 130 insertions, 72 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 8dbc0d667..35e1f752b 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 | ||
270 | impl Struct { | 270 | impl 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 | ||
338 | impl Enum { | 338 | impl 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 | ||
@@ -553,7 +553,7 @@ pub struct Trait { | |||
553 | 553 | ||
554 | impl Trait { | 554 | impl Trait { |
555 | pub fn module(self, db: &impl DefDatabase) -> Module { | 555 | pub fn module(self, db: &impl DefDatabase) -> Module { |
556 | Module { id: self.id.lookup(db).container } | 556 | Module { id: self.id.lookup(db).container.module(db) } |
557 | } | 557 | } |
558 | 558 | ||
559 | pub fn name(self, db: &impl DefDatabase) -> Name { | 559 | pub fn name(self, db: &impl DefDatabase) -> Name { |
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 17efa10e2..853e17bae 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::{ | |||
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 | ConstLoc, ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, Intern, ModuleDefId, StaticLoc, |
29 | StructLoc, TraitLoc, TypeAliasLoc, UnionLoc, | ||
29 | }; | 30 | }; |
30 | 31 | ||
31 | pub(super) fn lower( | 32 | pub(super) fn lower( |
@@ -492,14 +493,45 @@ where | |||
492 | fn collect_block_items(&mut self, block: &ast::Block) { | 493 | fn collect_block_items(&mut self, block: &ast::Block) { |
493 | let container = ContainerId::DefWithBodyId(self.def); | 494 | let container = ContainerId::DefWithBodyId(self.def); |
494 | for item in block.items() { | 495 | for item in block.items() { |
495 | match item { | 496 | let def: ModuleDefId = match item { |
496 | ast::ModuleItem::FnDef(def) => { | 497 | ast::ModuleItem::FnDef(def) => { |
497 | let ast_id = self.expander.ast_id(&def); | 498 | let ast_id = self.expander.ast_id(&def); |
498 | self.body.defs.push(FunctionLoc { container, ast_id }.intern(self.db).into()) | 499 | FunctionLoc { container: container.into(), ast_id }.intern(self.db).into() |
499 | } | 500 | } |
500 | // FIXME: handle other items | 501 | ast::ModuleItem::TypeAliasDef(def) => { |
501 | _ => (), | 502 | let ast_id = self.expander.ast_id(&def); |
502 | } | 503 | TypeAliasLoc { container: container.into(), ast_id }.intern(self.db).into() |
504 | } | ||
505 | ast::ModuleItem::ConstDef(def) => { | ||
506 | let ast_id = self.expander.ast_id(&def); | ||
507 | ConstLoc { container: container.into(), ast_id }.intern(self.db).into() | ||
508 | } | ||
509 | ast::ModuleItem::StaticDef(def) => { | ||
510 | let ast_id = self.expander.ast_id(&def); | ||
511 | StaticLoc { container, ast_id }.intern(self.db).into() | ||
512 | } | ||
513 | ast::ModuleItem::StructDef(def) => { | ||
514 | let ast_id = self.expander.ast_id(&def); | ||
515 | StructLoc { container, ast_id }.intern(self.db).into() | ||
516 | } | ||
517 | ast::ModuleItem::EnumDef(def) => { | ||
518 | let ast_id = self.expander.ast_id(&def); | ||
519 | EnumLoc { container, ast_id }.intern(self.db).into() | ||
520 | } | ||
521 | ast::ModuleItem::UnionDef(def) => { | ||
522 | let ast_id = self.expander.ast_id(&def); | ||
523 | UnionLoc { container, ast_id }.intern(self.db).into() | ||
524 | } | ||
525 | ast::ModuleItem::TraitDef(def) => { | ||
526 | let ast_id = self.expander.ast_id(&def); | ||
527 | TraitLoc { container, ast_id }.intern(self.db).into() | ||
528 | } | ||
529 | ast::ModuleItem::ImplBlock(_) | ||
530 | | ast::ModuleItem::UseItem(_) | ||
531 | | ast::ModuleItem::ExternCrateItem(_) | ||
532 | | ast::ModuleItem::Module(_) => continue, | ||
533 | }; | ||
534 | self.body.defs.push(def) | ||
503 | } | 535 | } |
504 | } | 536 | } |
505 | 537 | ||
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::{ | |||
12 | db::DefDatabase, | 12 | db::DefDatabase, |
13 | src::HasSource, | 13 | src::HasSource, |
14 | type_ref::{Mutability, TypeRef}, | 14 | type_ref::{Mutability, TypeRef}, |
15 | AssocItemId, ConstId, ConstLoc, ContainerId, FunctionId, FunctionLoc, ImplId, Intern, Lookup, | 15 | AssocContainerId, AssocItemId, ConstId, ConstLoc, FunctionId, FunctionLoc, ImplId, Intern, |
16 | StaticId, TraitId, TypeAliasId, TypeAliasLoc, | 16 | Lookup, StaticId, TraitId, TypeAliasId, TypeAliasLoc, |
17 | }; | 17 | }; |
18 | 18 | ||
19 | #[derive(Debug, Clone, PartialEq, Eq)] | 19 | #[derive(Debug, Clone, PartialEq, Eq)] |
@@ -99,7 +99,7 @@ impl TraitData { | |||
99 | let auto = src.value.is_auto(); | 99 | let auto = src.value.is_auto(); |
100 | let ast_id_map = db.ast_id_map(src.file_id); | 100 | let ast_id_map = db.ast_id_map(src.file_id); |
101 | 101 | ||
102 | let container = ContainerId::TraitId(tr); | 102 | let container = AssocContainerId::TraitId(tr); |
103 | let items = if let Some(item_list) = src.value.item_list() { | 103 | let items = if let Some(item_list) = src.value.item_list() { |
104 | item_list | 104 | item_list |
105 | .impl_items() | 105 | .impl_items() |
@@ -180,7 +180,7 @@ impl ImplData { | |||
180 | .map(|item_node| match item_node { | 180 | .map(|item_node| match item_node { |
181 | ast::ImplItem::FnDef(it) => { | 181 | ast::ImplItem::FnDef(it) => { |
182 | let def = FunctionLoc { | 182 | let def = FunctionLoc { |
183 | container: ContainerId::ImplId(id), | 183 | container: AssocContainerId::ImplId(id), |
184 | ast_id: AstId::new(src.file_id, items.ast_id(&it)), | 184 | ast_id: AstId::new(src.file_id, items.ast_id(&it)), |
185 | } | 185 | } |
186 | .intern(db); | 186 | .intern(db); |
@@ -188,7 +188,7 @@ impl ImplData { | |||
188 | } | 188 | } |
189 | ast::ImplItem::ConstDef(it) => { | 189 | ast::ImplItem::ConstDef(it) => { |
190 | let def = ConstLoc { | 190 | let def = ConstLoc { |
191 | container: ContainerId::ImplId(id), | 191 | container: AssocContainerId::ImplId(id), |
192 | ast_id: AstId::new(src.file_id, items.ast_id(&it)), | 192 | ast_id: AstId::new(src.file_id, items.ast_id(&it)), |
193 | } | 193 | } |
194 | .intern(db); | 194 | .intern(db); |
@@ -196,7 +196,7 @@ impl ImplData { | |||
196 | } | 196 | } |
197 | ast::ImplItem::TypeAliasDef(it) => { | 197 | ast::ImplItem::TypeAliasDef(it) => { |
198 | let def = TypeAliasLoc { | 198 | let def = TypeAliasLoc { |
199 | container: ContainerId::ImplId(id), | 199 | container: AssocContainerId::ImplId(id), |
200 | ast_id: AstId::new(src.file_id, items.ast_id(&it)), | 200 | ast_id: AstId::new(src.file_id, items.ast_id(&it)), |
201 | } | 201 | } |
202 | .intern(db); | 202 | .intern(db); |
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 4fc3127c4..140eccf26 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); | |||
71 | 71 | ||
72 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 72 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
73 | pub struct FunctionLoc { | 73 | pub struct FunctionLoc { |
74 | pub container: ContainerId, | 74 | pub container: AssocContainerId, |
75 | pub ast_id: AstId<ast::FnDef>, | 75 | pub ast_id: AstId<ast::FnDef>, |
76 | } | 76 | } |
77 | 77 | ||
@@ -95,7 +95,7 @@ impl_intern_key!(StructId); | |||
95 | 95 | ||
96 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 96 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
97 | pub struct StructLoc { | 97 | pub 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)] |
121 | pub struct UnionLoc { | 121 | pub 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)] |
145 | pub struct EnumLoc { | 145 | pub 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 | ||
@@ -187,7 +187,7 @@ pub struct ConstId(salsa::InternId); | |||
187 | impl_intern_key!(ConstId); | 187 | impl_intern_key!(ConstId); |
188 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 188 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
189 | pub struct ConstLoc { | 189 | pub struct ConstLoc { |
190 | pub container: ContainerId, | 190 | pub container: AssocContainerId, |
191 | pub ast_id: AstId<ast::ConstDef>, | 191 | pub ast_id: AstId<ast::ConstDef>, |
192 | } | 192 | } |
193 | 193 | ||
@@ -211,7 +211,7 @@ impl_intern_key!(StaticId); | |||
211 | 211 | ||
212 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 212 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
213 | pub struct StaticLoc { | 213 | pub struct StaticLoc { |
214 | pub container: ModuleId, | 214 | pub container: ContainerId, |
215 | pub ast_id: AstId<ast::StaticDef>, | 215 | pub ast_id: AstId<ast::StaticDef>, |
216 | } | 216 | } |
217 | 217 | ||
@@ -235,7 +235,7 @@ impl_intern_key!(TraitId); | |||
235 | 235 | ||
236 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 236 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
237 | pub struct TraitLoc { | 237 | pub struct TraitLoc { |
238 | pub container: ModuleId, | 238 | pub container: ContainerId, |
239 | pub ast_id: AstId<ast::TraitDef>, | 239 | pub ast_id: AstId<ast::TraitDef>, |
240 | } | 240 | } |
241 | 241 | ||
@@ -259,7 +259,7 @@ impl_intern_key!(TypeAliasId); | |||
259 | 259 | ||
260 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 260 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
261 | pub struct TypeAliasLoc { | 261 | pub struct TypeAliasLoc { |
262 | pub container: ContainerId, | 262 | pub container: AssocContainerId, |
263 | pub ast_id: AstId<ast::TypeAliasDef>, | 263 | pub ast_id: AstId<ast::TypeAliasDef>, |
264 | } | 264 | } |
265 | 265 | ||
@@ -333,10 +333,16 @@ impl_arena_id!(LocalTypeParamId); | |||
333 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 333 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
334 | pub enum ContainerId { | 334 | pub enum ContainerId { |
335 | ModuleId(ModuleId), | 335 | ModuleId(ModuleId), |
336 | DefWithBodyId(DefWithBodyId), | ||
337 | } | ||
338 | |||
339 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
340 | pub enum AssocContainerId { | ||
341 | ContainerId(ContainerId), | ||
336 | ImplId(ImplId), | 342 | ImplId(ImplId), |
337 | TraitId(TraitId), | 343 | TraitId(TraitId), |
338 | DefWithBodyId(DefWithBodyId), | ||
339 | } | 344 | } |
345 | impl_froms!(AssocContainerId: ContainerId); | ||
340 | 346 | ||
341 | /// A Data Type | 347 | /// A Data Type |
342 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | 348 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
@@ -483,13 +489,21 @@ impl HasModule for ContainerId { | |||
483 | fn module(&self, db: &impl db::DefDatabase) -> ModuleId { | 489 | fn module(&self, db: &impl db::DefDatabase) -> ModuleId { |
484 | match *self { | 490 | match *self { |
485 | ContainerId::ModuleId(it) => it, | 491 | ContainerId::ModuleId(it) => it, |
486 | ContainerId::ImplId(it) => it.lookup(db).container, | ||
487 | ContainerId::TraitId(it) => it.lookup(db).container, | ||
488 | ContainerId::DefWithBodyId(it) => it.module(db), | 492 | ContainerId::DefWithBodyId(it) => it.module(db), |
489 | } | 493 | } |
490 | } | 494 | } |
491 | } | 495 | } |
492 | 496 | ||
497 | impl HasModule for AssocContainerId { | ||
498 | fn module(&self, db: &impl db::DefDatabase) -> ModuleId { | ||
499 | match *self { | ||
500 | AssocContainerId::ContainerId(it) => it.module(db), | ||
501 | AssocContainerId::ImplId(it) => it.lookup(db).container, | ||
502 | AssocContainerId::TraitId(it) => it.lookup(db).container.module(db), | ||
503 | } | ||
504 | } | ||
505 | } | ||
506 | |||
493 | impl HasModule for FunctionLoc { | 507 | impl HasModule for FunctionLoc { |
494 | fn module(&self, db: &impl db::DefDatabase) -> ModuleId { | 508 | fn module(&self, db: &impl db::DefDatabase) -> ModuleId { |
495 | self.container.module(db) | 509 | self.container.module(db) |
@@ -515,6 +529,7 @@ impl HasModule for AdtId { | |||
515 | AdtId::UnionId(it) => it.lookup(db).container, | 529 | AdtId::UnionId(it) => it.lookup(db).container, |
516 | AdtId::EnumId(it) => it.lookup(db).container, | 530 | AdtId::EnumId(it) => it.lookup(db).container, |
517 | } | 531 | } |
532 | .module(db) | ||
518 | } | 533 | } |
519 | } | 534 | } |
520 | 535 | ||
@@ -533,17 +548,17 @@ impl HasModule for GenericDefId { | |||
533 | match self { | 548 | match self { |
534 | GenericDefId::FunctionId(it) => it.lookup(db).module(db), | 549 | GenericDefId::FunctionId(it) => it.lookup(db).module(db), |
535 | GenericDefId::AdtId(it) => it.module(db), | 550 | GenericDefId::AdtId(it) => it.module(db), |
536 | GenericDefId::TraitId(it) => it.lookup(db).container, | 551 | GenericDefId::TraitId(it) => it.lookup(db).container.module(db), |
537 | GenericDefId::TypeAliasId(it) => it.lookup(db).module(db), | 552 | GenericDefId::TypeAliasId(it) => it.lookup(db).module(db), |
538 | GenericDefId::ImplId(it) => it.lookup(db).container, | 553 | GenericDefId::ImplId(it) => it.lookup(db).container, |
539 | GenericDefId::EnumVariantId(it) => it.parent.lookup(db).container, | 554 | GenericDefId::EnumVariantId(it) => it.parent.lookup(db).container.module(db), |
540 | GenericDefId::ConstId(it) => it.lookup(db).module(db), | 555 | GenericDefId::ConstId(it) => it.lookup(db).module(db), |
541 | } | 556 | } |
542 | } | 557 | } |
543 | } | 558 | } |
544 | 559 | ||
545 | impl HasModule for StaticLoc { | 560 | impl HasModule for StaticLoc { |
546 | fn module(&self, _db: &impl db::DefDatabase) -> ModuleId { | 561 | fn module(&self, db: &impl db::DefDatabase) -> ModuleId { |
547 | self.container | 562 | self.container.module(db) |
548 | } | 563 | } |
549 | } | 564 | } |
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 8bbf7ffa2..a1ea130e0 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -760,10 +760,11 @@ where | |||
760 | self.collect_derives(attrs, def); | 760 | self.collect_derives(attrs, def); |
761 | 761 | ||
762 | let name = def.name.clone(); | 762 | let name = def.name.clone(); |
763 | let container = ContainerId::ModuleId(module); | ||
763 | let def: PerNs = match def.kind { | 764 | let def: PerNs = match def.kind { |
764 | raw::DefKind::Function(ast_id) => { | 765 | raw::DefKind::Function(ast_id) => { |
765 | let def = FunctionLoc { | 766 | let def = FunctionLoc { |
766 | container: ContainerId::ModuleId(module), | 767 | container: container.into(), |
767 | ast_id: AstId::new(self.file_id, ast_id), | 768 | ast_id: AstId::new(self.file_id, ast_id), |
768 | } | 769 | } |
769 | .intern(self.def_collector.db); | 770 | .intern(self.def_collector.db); |
@@ -771,23 +772,23 @@ where | |||
771 | PerNs::values(def.into()) | 772 | PerNs::values(def.into()) |
772 | } | 773 | } |
773 | raw::DefKind::Struct(ast_id) => { | 774 | raw::DefKind::Struct(ast_id) => { |
774 | 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) } |
775 | .intern(self.def_collector.db); | 776 | .intern(self.def_collector.db); |
776 | PerNs::both(def.into(), def.into()) | 777 | PerNs::both(def.into(), def.into()) |
777 | } | 778 | } |
778 | raw::DefKind::Union(ast_id) => { | 779 | raw::DefKind::Union(ast_id) => { |
779 | 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) } |
780 | .intern(self.def_collector.db); | 781 | .intern(self.def_collector.db); |
781 | PerNs::both(def.into(), def.into()) | 782 | PerNs::both(def.into(), def.into()) |
782 | } | 783 | } |
783 | raw::DefKind::Enum(ast_id) => { | 784 | raw::DefKind::Enum(ast_id) => { |
784 | 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) } |
785 | .intern(self.def_collector.db); | 786 | .intern(self.def_collector.db); |
786 | PerNs::types(def.into()) | 787 | PerNs::types(def.into()) |
787 | } | 788 | } |
788 | raw::DefKind::Const(ast_id) => { | 789 | raw::DefKind::Const(ast_id) => { |
789 | let def = ConstLoc { | 790 | let def = ConstLoc { |
790 | container: ContainerId::ModuleId(module), | 791 | container: container.into(), |
791 | ast_id: AstId::new(self.file_id, ast_id), | 792 | ast_id: AstId::new(self.file_id, ast_id), |
792 | } | 793 | } |
793 | .intern(self.def_collector.db); | 794 | .intern(self.def_collector.db); |
@@ -795,20 +796,20 @@ where | |||
795 | PerNs::values(def.into()) | 796 | PerNs::values(def.into()) |
796 | } | 797 | } |
797 | raw::DefKind::Static(ast_id) => { | 798 | raw::DefKind::Static(ast_id) => { |
798 | let def = StaticLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) } | 799 | let def = StaticLoc { container, ast_id: AstId::new(self.file_id, ast_id) } |
799 | .intern(self.def_collector.db); | 800 | .intern(self.def_collector.db); |
800 | 801 | ||
801 | PerNs::values(def.into()) | 802 | PerNs::values(def.into()) |
802 | } | 803 | } |
803 | raw::DefKind::Trait(ast_id) => { | 804 | raw::DefKind::Trait(ast_id) => { |
804 | let def = TraitLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) } | 805 | let def = TraitLoc { container, ast_id: AstId::new(self.file_id, ast_id) } |
805 | .intern(self.def_collector.db); | 806 | .intern(self.def_collector.db); |
806 | 807 | ||
807 | PerNs::types(def.into()) | 808 | PerNs::types(def.into()) |
808 | } | 809 | } |
809 | raw::DefKind::TypeAlias(ast_id) => { | 810 | raw::DefKind::TypeAlias(ast_id) => { |
810 | let def = TypeAliasLoc { | 811 | let def = TypeAliasLoc { |
811 | container: ContainerId::ModuleId(module), | 812 | container: container.into(), |
812 | ast_id: AstId::new(self.file_id, ast_id), | 813 | ast_id: AstId::new(self.file_id, ast_id), |
813 | } | 814 | } |
814 | .intern(self.def_collector.db); | 815 | .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..af9d194f8 100644 --- a/crates/ra_hir_def/src/resolver.rs +++ b/crates/ra_hir_def/src/resolver.rs | |||
@@ -17,9 +17,9 @@ use crate::{ | |||
17 | nameres::{BuiltinShadowMode, CrateDefMap}, | 17 | nameres::{BuiltinShadowMode, CrateDefMap}, |
18 | path::{ModPath, PathKind}, | 18 | path::{ModPath, PathKind}, |
19 | per_ns::PerNs, | 19 | per_ns::PerNs, |
20 | AdtId, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, GenericDefId, | 20 | AdtId, AssocContainerId, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId, |
21 | HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId, StaticId, StructId, TraitId, | 21 | FunctionId, GenericDefId, HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId, |
22 | TypeAliasId, TypeParamId, VariantId, | 22 | StaticId, StructId, TraitId, TypeAliasId, TypeParamId, VariantId, |
23 | }; | 23 | }; |
24 | 24 | ||
25 | #[derive(Debug, Clone, Default)] | 25 | #[derive(Debug, Clone, Default)] |
@@ -583,14 +583,22 @@ impl HasResolver for DefWithBodyId { | |||
583 | impl HasResolver for ContainerId { | 583 | impl HasResolver for ContainerId { |
584 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | 584 | fn resolver(self, db: &impl DefDatabase) -> Resolver { |
585 | match self { | 585 | match self { |
586 | ContainerId::TraitId(it) => it.resolver(db), | ||
587 | ContainerId::ImplId(it) => it.resolver(db), | ||
588 | ContainerId::ModuleId(it) => it.resolver(db), | 586 | ContainerId::ModuleId(it) => it.resolver(db), |
589 | ContainerId::DefWithBodyId(it) => it.resolver(db), | 587 | ContainerId::DefWithBodyId(it) => it.resolver(db), |
590 | } | 588 | } |
591 | } | 589 | } |
592 | } | 590 | } |
593 | 591 | ||
592 | impl HasResolver for AssocContainerId { | ||
593 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | ||
594 | match self { | ||
595 | AssocContainerId::ContainerId(it) => it.resolver(db), | ||
596 | AssocContainerId::TraitId(it) => it.resolver(db), | ||
597 | AssocContainerId::ImplId(it) => it.resolver(db), | ||
598 | } | ||
599 | } | ||
600 | } | ||
601 | |||
594 | impl HasResolver for GenericDefId { | 602 | impl HasResolver for GenericDefId { |
595 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | 603 | fn resolver(self, db: &impl DefDatabase) -> Resolver { |
596 | match self { | 604 | match self { |
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index 924ad3e81..6917c183b 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs | |||
@@ -8,7 +8,7 @@ use hir_def::{ | |||
8 | expr::{Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, | 8 | expr::{Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, |
9 | path::{GenericArg, GenericArgs}, | 9 | path::{GenericArg, GenericArgs}, |
10 | resolver::resolver_for_expr, | 10 | resolver::resolver_for_expr, |
11 | AdtId, ContainerId, Lookup, StructFieldId, | 11 | AdtId, AssocContainerId, Lookup, StructFieldId, |
12 | }; | 12 | }; |
13 | use hir_expand::name::{name, Name}; | 13 | use hir_expand::name::{name, Name}; |
14 | use ra_syntax::ast::RangeOp; | 14 | use ra_syntax::ast::RangeOp; |
@@ -672,7 +672,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
672 | // add obligation for trait implementation, if this is a trait method | 672 | // add obligation for trait implementation, if this is a trait method |
673 | match def { | 673 | match def { |
674 | CallableDef::FunctionId(f) => { | 674 | CallableDef::FunctionId(f) => { |
675 | if let ContainerId::TraitId(trait_) = f.lookup(self.db).container { | 675 | if let AssocContainerId::TraitId(trait_) = f.lookup(self.db).container { |
676 | // construct a TraitDef | 676 | // construct a TraitDef |
677 | let substs = | 677 | let substs = |
678 | a_ty.parameters.prefix(generics(self.db, trait_.into()).len()); | 678 | a_ty.parameters.prefix(generics(self.db, trait_.into()).len()); |
diff --git a/crates/ra_hir_ty/src/infer/path.rs b/crates/ra_hir_ty/src/infer/path.rs index 31c90ea1e..ffd358367 100644 --- a/crates/ra_hir_ty/src/infer/path.rs +++ b/crates/ra_hir_ty/src/infer/path.rs | |||
@@ -5,7 +5,7 @@ use std::iter; | |||
5 | use hir_def::{ | 5 | use hir_def::{ |
6 | path::{Path, PathSegment}, | 6 | path::{Path, PathSegment}, |
7 | resolver::{ResolveValueResult, Resolver, TypeNs, ValueNs}, | 7 | resolver::{ResolveValueResult, Resolver, TypeNs, ValueNs}, |
8 | AssocItemId, ContainerId, Lookup, | 8 | AssocContainerId, AssocItemId, Lookup, |
9 | }; | 9 | }; |
10 | use hir_expand::name::Name; | 10 | use hir_expand::name::Name; |
11 | 11 | ||
@@ -209,7 +209,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
209 | AssocItemId::TypeAliasId(_) => unreachable!(), | 209 | AssocItemId::TypeAliasId(_) => unreachable!(), |
210 | }; | 210 | }; |
211 | let substs = match container { | 211 | let substs = match container { |
212 | ContainerId::ImplId(impl_id) => { | 212 | AssocContainerId::ImplId(impl_id) => { |
213 | let impl_substs = Substs::build_for_def(self.db, impl_id) | 213 | let impl_substs = Substs::build_for_def(self.db, impl_id) |
214 | .fill(iter::repeat_with(|| self.table.new_type_var())) | 214 | .fill(iter::repeat_with(|| self.table.new_type_var())) |
215 | .build(); | 215 | .build(); |
@@ -221,7 +221,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
221 | self.unify(&impl_self_ty, &ty); | 221 | self.unify(&impl_self_ty, &ty); |
222 | Some(substs) | 222 | Some(substs) |
223 | } | 223 | } |
224 | ContainerId::TraitId(trait_) => { | 224 | AssocContainerId::TraitId(trait_) => { |
225 | // we're picking this method | 225 | // we're picking this method |
226 | let trait_substs = Substs::build_for_def(self.db, trait_) | 226 | let trait_substs = Substs::build_for_def(self.db, trait_) |
227 | .push(ty.clone()) | 227 | .push(ty.clone()) |
@@ -237,7 +237,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
237 | })); | 237 | })); |
238 | Some(substs) | 238 | Some(substs) |
239 | } | 239 | } |
240 | ContainerId::ModuleId(_) | ContainerId::DefWithBodyId(_) => None, | 240 | AssocContainerId::ContainerId(_) => None, |
241 | }; | 241 | }; |
242 | 242 | ||
243 | self.write_assoc_resolution(id, item.into()); | 243 | self.write_assoc_resolution(id, item.into()); |
diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs index 7ca9e6b8a..7310ef10d 100644 --- a/crates/ra_hir_ty/src/lib.rs +++ b/crates/ra_hir_ty/src/lib.rs | |||
@@ -44,8 +44,8 @@ use std::sync::Arc; | |||
44 | use std::{fmt, iter, mem}; | 44 | use std::{fmt, iter, mem}; |
45 | 45 | ||
46 | use hir_def::{ | 46 | use hir_def::{ |
47 | expr::ExprId, type_ref::Mutability, AdtId, ContainerId, DefWithBodyId, GenericDefId, HasModule, | 47 | expr::ExprId, type_ref::Mutability, AdtId, AssocContainerId, DefWithBodyId, GenericDefId, |
48 | Lookup, TraitId, TypeAliasId, | 48 | HasModule, Lookup, TraitId, TypeAliasId, |
49 | }; | 49 | }; |
50 | use hir_expand::name::Name; | 50 | use hir_expand::name::Name; |
51 | use ra_db::{impl_intern_key, salsa, CrateId}; | 51 | use ra_db::{impl_intern_key, salsa, CrateId}; |
@@ -251,7 +251,7 @@ impl ProjectionTy { | |||
251 | 251 | ||
252 | fn trait_(&self, db: &impl HirDatabase) -> TraitId { | 252 | fn trait_(&self, db: &impl HirDatabase) -> TraitId { |
253 | match self.associated_ty.lookup(db).container { | 253 | match self.associated_ty.lookup(db).container { |
254 | ContainerId::TraitId(it) => it, | 254 | AssocContainerId::TraitId(it) => it, |
255 | _ => panic!("projection ty without parent trait"), | 255 | _ => panic!("projection ty without parent trait"), |
256 | } | 256 | } |
257 | } | 257 | } |
@@ -943,7 +943,7 @@ impl HirDisplay for ApplicationTy { | |||
943 | } | 943 | } |
944 | TypeCtor::AssociatedType(type_alias) => { | 944 | TypeCtor::AssociatedType(type_alias) => { |
945 | let trait_ = match type_alias.lookup(f.db).container { | 945 | let trait_ = match type_alias.lookup(f.db).container { |
946 | ContainerId::TraitId(it) => it, | 946 | AssocContainerId::TraitId(it) => it, |
947 | _ => panic!("not an associated type"), | 947 | _ => panic!("not an associated type"), |
948 | }; | 948 | }; |
949 | let trait_name = f.db.trait_data(trait_).name.clone(); | 949 | let trait_name = f.db.trait_data(trait_).name.clone(); |
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 | } |
diff --git a/crates/ra_hir_ty/src/method_resolution.rs b/crates/ra_hir_ty/src/method_resolution.rs index d0b2b016d..1b2f4014c 100644 --- a/crates/ra_hir_ty/src/method_resolution.rs +++ b/crates/ra_hir_ty/src/method_resolution.rs | |||
@@ -6,8 +6,8 @@ use std::sync::Arc; | |||
6 | 6 | ||
7 | use arrayvec::ArrayVec; | 7 | use arrayvec::ArrayVec; |
8 | use hir_def::{ | 8 | use hir_def::{ |
9 | lang_item::LangItemTarget, resolver::Resolver, type_ref::Mutability, AssocItemId, ContainerId, | 9 | lang_item::LangItemTarget, resolver::Resolver, type_ref::Mutability, AssocContainerId, |
10 | FunctionId, HasModule, ImplId, Lookup, TraitId, | 10 | AssocItemId, FunctionId, HasModule, ImplId, Lookup, TraitId, |
11 | }; | 11 | }; |
12 | use hir_expand::name::Name; | 12 | use hir_expand::name::Name; |
13 | use ra_db::CrateId; | 13 | use ra_db::CrateId; |
@@ -451,12 +451,12 @@ fn transform_receiver_ty( | |||
451 | self_ty: &Canonical<Ty>, | 451 | self_ty: &Canonical<Ty>, |
452 | ) -> Option<Ty> { | 452 | ) -> Option<Ty> { |
453 | let substs = match function_id.lookup(db).container { | 453 | let substs = match function_id.lookup(db).container { |
454 | ContainerId::TraitId(_) => Substs::build_for_def(db, function_id) | 454 | AssocContainerId::TraitId(_) => Substs::build_for_def(db, function_id) |
455 | .push(self_ty.value.clone()) | 455 | .push(self_ty.value.clone()) |
456 | .fill_with_unknown() | 456 | .fill_with_unknown() |
457 | .build(), | 457 | .build(), |
458 | ContainerId::ImplId(impl_id) => inherent_impl_substs(db, impl_id, &self_ty)?, | 458 | AssocContainerId::ImplId(impl_id) => inherent_impl_substs(db, impl_id, &self_ty)?, |
459 | ContainerId::ModuleId(_) | ContainerId::DefWithBodyId(_) => unreachable!(), | 459 | AssocContainerId::ContainerId(_) => unreachable!(), |
460 | }; | 460 | }; |
461 | let sig = db.callable_item_signature(function_id.into()); | 461 | let sig = db.callable_item_signature(function_id.into()); |
462 | Some(sig.params()[0].clone().subst(&substs)) | 462 | Some(sig.params()[0].clone().subst(&substs)) |
diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs index fc21872b2..dd4fa9664 100644 --- a/crates/ra_hir_ty/src/traits/chalk.rs +++ b/crates/ra_hir_ty/src/traits/chalk.rs | |||
@@ -9,7 +9,9 @@ use chalk_ir::{ | |||
9 | }; | 9 | }; |
10 | use chalk_rust_ir::{AssociatedTyDatum, AssociatedTyValue, ImplDatum, StructDatum, TraitDatum}; | 10 | use chalk_rust_ir::{AssociatedTyDatum, AssociatedTyValue, ImplDatum, StructDatum, TraitDatum}; |
11 | 11 | ||
12 | use hir_def::{AssocItemId, ContainerId, GenericDefId, ImplId, Lookup, TraitId, TypeAliasId}; | 12 | use hir_def::{ |
13 | AssocContainerId, AssocItemId, GenericDefId, HasModule, ImplId, Lookup, TraitId, TypeAliasId, | ||
14 | }; | ||
13 | use ra_db::{ | 15 | use ra_db::{ |
14 | salsa::{InternId, InternKey}, | 16 | salsa::{InternId, InternKey}, |
15 | CrateId, | 17 | CrateId, |
@@ -542,7 +544,7 @@ pub(crate) fn associated_ty_data_query( | |||
542 | debug!("associated_ty_data {:?}", id); | 544 | debug!("associated_ty_data {:?}", id); |
543 | let type_alias: TypeAliasId = from_chalk(db, id); | 545 | let type_alias: TypeAliasId = from_chalk(db, id); |
544 | let trait_ = match type_alias.lookup(db).container { | 546 | let trait_ = match type_alias.lookup(db).container { |
545 | ContainerId::TraitId(t) => t, | 547 | AssocContainerId::TraitId(t) => t, |
546 | _ => panic!("associated type not in trait"), | 548 | _ => panic!("associated type not in trait"), |
547 | }; | 549 | }; |
548 | let generic_params = generics(db, type_alias.into()); | 550 | let generic_params = generics(db, type_alias.into()); |
@@ -591,7 +593,7 @@ pub(crate) fn trait_datum_query( | |||
591 | let bound_vars = Substs::bound_vars(&generic_params); | 593 | let bound_vars = Substs::bound_vars(&generic_params); |
592 | let flags = chalk_rust_ir::TraitFlags { | 594 | let flags = chalk_rust_ir::TraitFlags { |
593 | auto: trait_data.auto, | 595 | auto: trait_data.auto, |
594 | upstream: trait_.lookup(db).container.krate != krate, | 596 | upstream: trait_.lookup(db).container.module(db).krate != krate, |
595 | non_enumerable: true, | 597 | non_enumerable: true, |
596 | coinductive: false, // only relevant for Chalk testing | 598 | coinductive: false, // only relevant for Chalk testing |
597 | // FIXME set these flags correctly | 599 | // FIXME set these flags correctly |
@@ -755,7 +757,7 @@ fn type_alias_associated_ty_value( | |||
755 | ) -> Arc<AssociatedTyValue<ChalkIr>> { | 757 | ) -> Arc<AssociatedTyValue<ChalkIr>> { |
756 | let type_alias_data = db.type_alias_data(type_alias); | 758 | let type_alias_data = db.type_alias_data(type_alias); |
757 | let impl_id = match type_alias.lookup(db).container { | 759 | let impl_id = match type_alias.lookup(db).container { |
758 | ContainerId::ImplId(it) => it, | 760 | AssocContainerId::ImplId(it) => it, |
759 | _ => panic!("assoc ty value should be in impl"), | 761 | _ => panic!("assoc ty value should be in impl"), |
760 | }; | 762 | }; |
761 | 763 | ||
diff --git a/crates/ra_hir_ty/src/utils.rs b/crates/ra_hir_ty/src/utils.rs index 34defc1a2..0b1806a84 100644 --- a/crates/ra_hir_ty/src/utils.rs +++ b/crates/ra_hir_ty/src/utils.rs | |||
@@ -9,7 +9,7 @@ use hir_def::{ | |||
9 | path::Path, | 9 | path::Path, |
10 | resolver::{HasResolver, TypeNs}, | 10 | resolver::{HasResolver, TypeNs}, |
11 | type_ref::TypeRef, | 11 | type_ref::TypeRef, |
12 | ContainerId, GenericDefId, Lookup, TraitId, TypeAliasId, TypeParamId, VariantId, | 12 | AssocContainerId, GenericDefId, Lookup, TraitId, TypeAliasId, TypeParamId, VariantId, |
13 | }; | 13 | }; |
14 | use hir_expand::name::{name, Name}; | 14 | use hir_expand::name::{name, Name}; |
15 | 15 | ||
@@ -155,8 +155,8 @@ fn parent_generic_def(db: &impl DefDatabase, def: GenericDefId) -> Option<Generi | |||
155 | }; | 155 | }; |
156 | 156 | ||
157 | match container { | 157 | match container { |
158 | ContainerId::ImplId(it) => Some(it.into()), | 158 | AssocContainerId::ImplId(it) => Some(it.into()), |
159 | ContainerId::TraitId(it) => Some(it.into()), | 159 | AssocContainerId::TraitId(it) => Some(it.into()), |
160 | ContainerId::ModuleId(_) | ContainerId::DefWithBodyId(_) => None, | 160 | AssocContainerId::ContainerId(_) => None, |
161 | } | 161 | } |
162 | } | 162 | } |