aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/hir/src/lib.rs30
-rw-r--r--crates/hir_def/src/adt.rs21
-rw-r--r--crates/hir_def/src/attr.rs2
-rw-r--r--crates/hir_def/src/data.rs4
-rw-r--r--crates/hir_def/src/lib.rs50
-rw-r--r--crates/hir_def/src/nameres/collector.rs23
-rw-r--r--crates/hir_def/src/resolver.rs17
-rw-r--r--crates/hir_ty/src/display.rs4
-rw-r--r--crates/hir_ty/src/lower.rs4
-rw-r--r--crates/hir_ty/src/method_resolution.rs2
-rw-r--r--crates/hir_ty/src/traits/chalk.rs4
11 files changed, 61 insertions, 100 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index c6d424c48..4ef38c0f0 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -535,7 +535,7 @@ pub struct Struct {
535 535
536impl Struct { 536impl Struct {
537 pub fn module(self, db: &dyn HirDatabase) -> Module { 537 pub fn module(self, db: &dyn HirDatabase) -> Module {
538 Module { id: self.id.lookup(db.upcast()).container.module(db.upcast()) } 538 Module { id: self.id.lookup(db.upcast()).container }
539 } 539 }
540 540
541 pub fn krate(self, db: &dyn HirDatabase) -> Option<Crate> { 541 pub fn krate(self, db: &dyn HirDatabase) -> Option<Crate> {
@@ -556,11 +556,7 @@ impl Struct {
556 } 556 }
557 557
558 pub fn ty(self, db: &dyn HirDatabase) -> Type { 558 pub fn ty(self, db: &dyn HirDatabase) -> Type {
559 Type::from_def( 559 Type::from_def(db, self.id.lookup(db.upcast()).container.krate(), self.id)
560 db,
561 self.id.lookup(db.upcast()).container.module(db.upcast()).krate(),
562 self.id,
563 )
564 } 560 }
565 561
566 pub fn repr(self, db: &dyn HirDatabase) -> Option<ReprKind> { 562 pub fn repr(self, db: &dyn HirDatabase) -> Option<ReprKind> {
@@ -587,15 +583,11 @@ impl Union {
587 } 583 }
588 584
589 pub fn module(self, db: &dyn HirDatabase) -> Module { 585 pub fn module(self, db: &dyn HirDatabase) -> Module {
590 Module { id: self.id.lookup(db.upcast()).container.module(db.upcast()) } 586 Module { id: self.id.lookup(db.upcast()).container }
591 } 587 }
592 588
593 pub fn ty(self, db: &dyn HirDatabase) -> Type { 589 pub fn ty(self, db: &dyn HirDatabase) -> Type {
594 Type::from_def( 590 Type::from_def(db, self.id.lookup(db.upcast()).container.krate(), self.id)
595 db,
596 self.id.lookup(db.upcast()).container.module(db.upcast()).krate(),
597 self.id,
598 )
599 } 591 }
600 592
601 pub fn fields(self, db: &dyn HirDatabase) -> Vec<Field> { 593 pub fn fields(self, db: &dyn HirDatabase) -> Vec<Field> {
@@ -619,7 +611,7 @@ pub struct Enum {
619 611
620impl Enum { 612impl Enum {
621 pub fn module(self, db: &dyn HirDatabase) -> Module { 613 pub fn module(self, db: &dyn HirDatabase) -> Module {
622 Module { id: self.id.lookup(db.upcast()).container.module(db.upcast()) } 614 Module { id: self.id.lookup(db.upcast()).container }
623 } 615 }
624 616
625 pub fn krate(self, db: &dyn HirDatabase) -> Option<Crate> { 617 pub fn krate(self, db: &dyn HirDatabase) -> Option<Crate> {
@@ -635,11 +627,7 @@ impl Enum {
635 } 627 }
636 628
637 pub fn ty(self, db: &dyn HirDatabase) -> Type { 629 pub fn ty(self, db: &dyn HirDatabase) -> Type {
638 Type::from_def( 630 Type::from_def(db, self.id.lookup(db.upcast()).container.krate(), self.id)
639 db,
640 self.id.lookup(db.upcast()).container.module(db.upcast()).krate(),
641 self.id,
642 )
643 } 631 }
644} 632}
645 633
@@ -1001,7 +989,7 @@ pub struct Trait {
1001 989
1002impl Trait { 990impl Trait {
1003 pub fn module(self, db: &dyn HirDatabase) -> Module { 991 pub fn module(self, db: &dyn HirDatabase) -> Module {
1004 Module { id: self.id.lookup(db.upcast()).container.module(db.upcast()) } 992 Module { id: self.id.lookup(db.upcast()).container }
1005 } 993 }
1006 994
1007 pub fn name(self, db: &dyn HirDatabase) -> Name { 995 pub fn name(self, db: &dyn HirDatabase) -> Name {
@@ -1510,7 +1498,7 @@ impl Impl {
1510 pub fn target_ty(self, db: &dyn HirDatabase) -> Type { 1498 pub fn target_ty(self, db: &dyn HirDatabase) -> Type {
1511 let impl_data = db.impl_data(self.id); 1499 let impl_data = db.impl_data(self.id);
1512 let resolver = self.id.resolver(db.upcast()); 1500 let resolver = self.id.resolver(db.upcast());
1513 let krate = self.id.lookup(db.upcast()).container.module(db.upcast()).krate(); 1501 let krate = self.id.lookup(db.upcast()).container.krate();
1514 let ctx = hir_ty::TyLoweringContext::new(db, &resolver); 1502 let ctx = hir_ty::TyLoweringContext::new(db, &resolver);
1515 let ty = Ty::from_hir(&ctx, &impl_data.target_type); 1503 let ty = Ty::from_hir(&ctx, &impl_data.target_type);
1516 Type::new_with_resolver_inner(db, krate, &resolver, ty) 1504 Type::new_with_resolver_inner(db, krate, &resolver, ty)
@@ -1525,7 +1513,7 @@ impl Impl {
1525 } 1513 }
1526 1514
1527 pub fn module(self, db: &dyn HirDatabase) -> Module { 1515 pub fn module(self, db: &dyn HirDatabase) -> Module {
1528 self.id.lookup(db.upcast()).container.module(db.upcast()).into() 1516 self.id.lookup(db.upcast()).container.into()
1529 } 1517 }
1530 1518
1531 pub fn krate(self, db: &dyn HirDatabase) -> Crate { 1519 pub fn krate(self, db: &dyn HirDatabase) -> Crate {
diff --git a/crates/hir_def/src/adt.rs b/crates/hir_def/src/adt.rs
index ed36c3109..efbde17d8 100644
--- a/crates/hir_def/src/adt.rs
+++ b/crates/hir_def/src/adt.rs
@@ -21,8 +21,7 @@ use crate::{
21 trace::Trace, 21 trace::Trace,
22 type_ref::TypeRef, 22 type_ref::TypeRef,
23 visibility::RawVisibility, 23 visibility::RawVisibility,
24 EnumId, HasModule, LocalEnumVariantId, LocalFieldId, Lookup, ModuleId, StructId, UnionId, 24 EnumId, LocalEnumVariantId, LocalFieldId, Lookup, ModuleId, StructId, UnionId, VariantId,
25 VariantId,
26}; 25};
27use cfg::CfgOptions; 26use cfg::CfgOptions;
28 27
@@ -92,10 +91,10 @@ fn parse_repr_tt(tt: &Subtree) -> Option<ReprKind> {
92impl StructData { 91impl StructData {
93 pub(crate) fn struct_data_query(db: &dyn DefDatabase, id: StructId) -> Arc<StructData> { 92 pub(crate) fn struct_data_query(db: &dyn DefDatabase, id: StructId) -> Arc<StructData> {
94 let loc = id.lookup(db); 93 let loc = id.lookup(db);
95 let krate = loc.container.module(db).krate; 94 let krate = loc.container.krate;
96 let item_tree = db.item_tree(loc.id.file_id); 95 let item_tree = db.item_tree(loc.id.file_id);
97 let repr = repr_from_value(db, krate, &item_tree, ModItem::from(loc.id.value).into()); 96 let repr = repr_from_value(db, krate, &item_tree, ModItem::from(loc.id.value).into());
98 let cfg_options = db.crate_graph()[loc.container.module(db).krate].cfg_options.clone(); 97 let cfg_options = db.crate_graph()[loc.container.krate].cfg_options.clone();
99 98
100 let strukt = &item_tree[loc.id.value]; 99 let strukt = &item_tree[loc.id.value];
101 let variant_data = lower_fields(db, krate, &item_tree, &cfg_options, &strukt.fields, None); 100 let variant_data = lower_fields(db, krate, &item_tree, &cfg_options, &strukt.fields, None);
@@ -107,10 +106,10 @@ impl StructData {
107 } 106 }
108 pub(crate) fn union_data_query(db: &dyn DefDatabase, id: UnionId) -> Arc<StructData> { 107 pub(crate) fn union_data_query(db: &dyn DefDatabase, id: UnionId) -> Arc<StructData> {
109 let loc = id.lookup(db); 108 let loc = id.lookup(db);
110 let krate = loc.container.module(db).krate; 109 let krate = loc.container.krate;
111 let item_tree = db.item_tree(loc.id.file_id); 110 let item_tree = db.item_tree(loc.id.file_id);
112 let repr = repr_from_value(db, krate, &item_tree, ModItem::from(loc.id.value).into()); 111 let repr = repr_from_value(db, krate, &item_tree, ModItem::from(loc.id.value).into());
113 let cfg_options = db.crate_graph()[loc.container.module(db).krate].cfg_options.clone(); 112 let cfg_options = db.crate_graph()[loc.container.krate].cfg_options.clone();
114 113
115 let union = &item_tree[loc.id.value]; 114 let union = &item_tree[loc.id.value];
116 let variant_data = lower_fields(db, krate, &item_tree, &cfg_options, &union.fields, None); 115 let variant_data = lower_fields(db, krate, &item_tree, &cfg_options, &union.fields, None);
@@ -126,7 +125,7 @@ impl StructData {
126impl EnumData { 125impl EnumData {
127 pub(crate) fn enum_data_query(db: &dyn DefDatabase, e: EnumId) -> Arc<EnumData> { 126 pub(crate) fn enum_data_query(db: &dyn DefDatabase, e: EnumId) -> Arc<EnumData> {
128 let loc = e.lookup(db); 127 let loc = e.lookup(db);
129 let krate = loc.container.module(db).krate; 128 let krate = loc.container.krate;
130 let item_tree = db.item_tree(loc.id.file_id); 129 let item_tree = db.item_tree(loc.id.file_id);
131 let cfg_options = db.crate_graph()[krate].cfg_options.clone(); 130 let cfg_options = db.crate_graph()[krate].cfg_options.clone();
132 131
@@ -168,7 +167,7 @@ impl HasChildSource<LocalEnumVariantId> for EnumId {
168 ) -> InFile<ArenaMap<LocalEnumVariantId, Self::Value>> { 167 ) -> InFile<ArenaMap<LocalEnumVariantId, Self::Value>> {
169 let src = self.lookup(db).source(db); 168 let src = self.lookup(db).source(db);
170 let mut trace = Trace::new_for_map(); 169 let mut trace = Trace::new_for_map();
171 lower_enum(db, &mut trace, &src, self.lookup(db).container.module(db)); 170 lower_enum(db, &mut trace, &src, self.lookup(db).container);
172 src.with_value(trace.into_map()) 171 src.with_value(trace.into_map())
173 } 172 }
174} 173}
@@ -238,10 +237,10 @@ impl HasChildSource<LocalFieldId> for VariantId {
238 // I don't really like the fact that we call into parent source 237 // I don't really like the fact that we call into parent source
239 // here, this might add to more queries then necessary. 238 // here, this might add to more queries then necessary.
240 let src = it.parent.child_source(db); 239 let src = it.parent.child_source(db);
241 (src.map(|map| map[it.local_id].kind()), it.parent.lookup(db).container.module(db)) 240 (src.map(|map| map[it.local_id].kind()), it.parent.lookup(db).container)
242 } 241 }
243 VariantId::StructId(it) => { 242 VariantId::StructId(it) => {
244 (it.lookup(db).source(db).map(|it| it.kind()), it.lookup(db).container.module(db)) 243 (it.lookup(db).source(db).map(|it| it.kind()), it.lookup(db).container)
245 } 244 }
246 VariantId::UnionId(it) => ( 245 VariantId::UnionId(it) => (
247 it.lookup(db).source(db).map(|it| { 246 it.lookup(db).source(db).map(|it| {
@@ -249,7 +248,7 @@ impl HasChildSource<LocalFieldId> for VariantId {
249 .map(ast::StructKind::Record) 248 .map(ast::StructKind::Record)
250 .unwrap_or(ast::StructKind::Unit) 249 .unwrap_or(ast::StructKind::Unit)
251 }), 250 }),
252 it.lookup(db).container.module(db), 251 it.lookup(db).container,
253 ), 252 ),
254 }; 253 };
255 let mut expander = CfgExpander::new(db, src.file_id, module_id.krate); 254 let mut expander = CfgExpander::new(db, src.file_id, module_id.krate);
diff --git a/crates/hir_def/src/attr.rs b/crates/hir_def/src/attr.rs
index b716d5f6e..97cdbbb9e 100644
--- a/crates/hir_def/src/attr.rs
+++ b/crates/hir_def/src/attr.rs
@@ -267,7 +267,7 @@ impl Attrs {
267 db: &dyn DefDatabase, 267 db: &dyn DefDatabase,
268 e: EnumId, 268 e: EnumId,
269 ) -> Arc<ArenaMap<LocalEnumVariantId, Attrs>> { 269 ) -> Arc<ArenaMap<LocalEnumVariantId, Attrs>> {
270 let krate = e.lookup(db).container.module(db).krate; 270 let krate = e.lookup(db).container.krate;
271 let src = e.child_source(db); 271 let src = e.child_source(db);
272 let mut res = ArenaMap::default(); 272 let mut res = ArenaMap::default();
273 273
diff --git a/crates/hir_def/src/data.rs b/crates/hir_def/src/data.rs
index d3380e0f4..aea53d527 100644
--- a/crates/hir_def/src/data.rs
+++ b/crates/hir_def/src/data.rs
@@ -97,7 +97,7 @@ impl TraitData {
97 let tr_def = &item_tree[tr_loc.id.value]; 97 let tr_def = &item_tree[tr_loc.id.value];
98 let name = tr_def.name.clone(); 98 let name = tr_def.name.clone();
99 let auto = tr_def.auto; 99 let auto = tr_def.auto;
100 let module_id = tr_loc.container.module(db); 100 let module_id = tr_loc.container;
101 let container = AssocContainerId::TraitId(tr); 101 let container = AssocContainerId::TraitId(tr);
102 let mut expander = Expander::new(db, tr_loc.id.file_id, module_id); 102 let mut expander = Expander::new(db, tr_loc.id.file_id, module_id);
103 103
@@ -147,7 +147,7 @@ impl ImplData {
147 let target_trait = impl_def.target_trait.map(|id| item_tree[id].clone()); 147 let target_trait = impl_def.target_trait.map(|id| item_tree[id].clone());
148 let target_type = item_tree[impl_def.target_type].clone(); 148 let target_type = item_tree[impl_def.target_type].clone();
149 let is_negative = impl_def.is_negative; 149 let is_negative = impl_def.is_negative;
150 let module_id = impl_loc.container.module(db); 150 let module_id = impl_loc.container;
151 let container = AssocContainerId::ImplId(id); 151 let container = AssocContainerId::ImplId(id);
152 let mut expander = Expander::new(db, impl_loc.id.file_id, module_id); 152 let mut expander = Expander::new(db, impl_loc.id.file_id, module_id);
153 153
diff --git a/crates/hir_def/src/lib.rs b/crates/hir_def/src/lib.rs
index ab3b17f6c..6d11c5be4 100644
--- a/crates/hir_def/src/lib.rs
+++ b/crates/hir_def/src/lib.rs
@@ -108,7 +108,7 @@ pub type LocalModuleId = Idx<nameres::ModuleData>;
108 108
109#[derive(Debug)] 109#[derive(Debug)]
110pub struct ItemLoc<N: ItemTreeNode> { 110pub struct ItemLoc<N: ItemTreeNode> {
111 pub container: ContainerId, 111 pub container: ModuleId,
112 pub id: ItemTreeId<N>, 112 pub id: ItemTreeId<N>,
113} 113}
114 114
@@ -279,12 +279,6 @@ pub struct ConstParamId {
279pub type LocalConstParamId = Idx<generics::ConstParamData>; 279pub type LocalConstParamId = Idx<generics::ConstParamData>;
280 280
281#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 281#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
282pub enum ContainerId {
283 ModuleId(ModuleId),
284 DefWithBodyId(DefWithBodyId),
285}
286
287#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
288pub enum AssocContainerId { 282pub enum AssocContainerId {
289 ModuleId(ModuleId), 283 ModuleId(ModuleId),
290 ImplId(ImplId), 284 ImplId(ImplId),
@@ -447,21 +441,12 @@ pub trait HasModule {
447 fn module(&self, db: &dyn db::DefDatabase) -> ModuleId; 441 fn module(&self, db: &dyn db::DefDatabase) -> ModuleId;
448} 442}
449 443
450impl HasModule for ContainerId {
451 fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
452 match *self {
453 ContainerId::ModuleId(it) => it,
454 ContainerId::DefWithBodyId(it) => it.module(db),
455 }
456 }
457}
458
459impl HasModule for AssocContainerId { 444impl HasModule for AssocContainerId {
460 fn module(&self, db: &dyn db::DefDatabase) -> ModuleId { 445 fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
461 match *self { 446 match *self {
462 AssocContainerId::ModuleId(it) => it, 447 AssocContainerId::ModuleId(it) => it,
463 AssocContainerId::ImplId(it) => it.lookup(db).container.module(db), 448 AssocContainerId::ImplId(it) => it.lookup(db).container,
464 AssocContainerId::TraitId(it) => it.lookup(db).container.module(db), 449 AssocContainerId::TraitId(it) => it.lookup(db).container,
465 } 450 }
466 } 451 }
467} 452}
@@ -479,16 +464,15 @@ impl HasModule for AdtId {
479 AdtId::UnionId(it) => it.lookup(db).container, 464 AdtId::UnionId(it) => it.lookup(db).container,
480 AdtId::EnumId(it) => it.lookup(db).container, 465 AdtId::EnumId(it) => it.lookup(db).container,
481 } 466 }
482 .module(db)
483 } 467 }
484} 468}
485 469
486impl HasModule for VariantId { 470impl HasModule for VariantId {
487 fn module(&self, db: &dyn db::DefDatabase) -> ModuleId { 471 fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
488 match self { 472 match self {
489 VariantId::EnumVariantId(it) => it.parent.lookup(db).container.module(db), 473 VariantId::EnumVariantId(it) => it.parent.lookup(db).container,
490 VariantId::StructId(it) => it.lookup(db).container.module(db), 474 VariantId::StructId(it) => it.lookup(db).container,
491 VariantId::UnionId(it) => it.lookup(db).container.module(db), 475 VariantId::UnionId(it) => it.lookup(db).container,
492 } 476 }
493 } 477 }
494} 478}
@@ -518,18 +502,18 @@ impl HasModule for GenericDefId {
518 match self { 502 match self {
519 GenericDefId::FunctionId(it) => it.lookup(db).module(db), 503 GenericDefId::FunctionId(it) => it.lookup(db).module(db),
520 GenericDefId::AdtId(it) => it.module(db), 504 GenericDefId::AdtId(it) => it.module(db),
521 GenericDefId::TraitId(it) => it.lookup(db).container.module(db), 505 GenericDefId::TraitId(it) => it.lookup(db).container,
522 GenericDefId::TypeAliasId(it) => it.lookup(db).module(db), 506 GenericDefId::TypeAliasId(it) => it.lookup(db).module(db),
523 GenericDefId::ImplId(it) => it.lookup(db).container.module(db), 507 GenericDefId::ImplId(it) => it.lookup(db).container,
524 GenericDefId::EnumVariantId(it) => it.parent.lookup(db).container.module(db), 508 GenericDefId::EnumVariantId(it) => it.parent.lookup(db).container,
525 GenericDefId::ConstId(it) => it.lookup(db).module(db), 509 GenericDefId::ConstId(it) => it.lookup(db).module(db),
526 } 510 }
527 } 511 }
528} 512}
529 513
530impl HasModule for StaticLoc { 514impl HasModule for StaticLoc {
531 fn module(&self, db: &dyn db::DefDatabase) -> ModuleId { 515 fn module(&self, _db: &dyn db::DefDatabase) -> ModuleId {
532 self.container.module(db) 516 self.container
533 } 517 }
534} 518}
535 519
@@ -542,10 +526,10 @@ impl ModuleDefId {
542 ModuleDefId::ModuleId(id) => *id, 526 ModuleDefId::ModuleId(id) => *id,
543 ModuleDefId::FunctionId(id) => id.lookup(db).module(db), 527 ModuleDefId::FunctionId(id) => id.lookup(db).module(db),
544 ModuleDefId::AdtId(id) => id.module(db), 528 ModuleDefId::AdtId(id) => id.module(db),
545 ModuleDefId::EnumVariantId(id) => id.parent.lookup(db).container.module(db), 529 ModuleDefId::EnumVariantId(id) => id.parent.lookup(db).container,
546 ModuleDefId::ConstId(id) => id.lookup(db).container.module(db), 530 ModuleDefId::ConstId(id) => id.lookup(db).container.module(db),
547 ModuleDefId::StaticId(id) => id.lookup(db).container.module(db), 531 ModuleDefId::StaticId(id) => id.lookup(db).container,
548 ModuleDefId::TraitId(id) => id.lookup(db).container.module(db), 532 ModuleDefId::TraitId(id) => id.lookup(db).container,
549 ModuleDefId::TypeAliasId(id) => id.lookup(db).module(db), 533 ModuleDefId::TypeAliasId(id) => id.lookup(db).module(db),
550 ModuleDefId::BuiltinType(_) => return None, 534 ModuleDefId::BuiltinType(_) => return None,
551 }) 535 })
@@ -559,12 +543,12 @@ impl AttrDefId {
559 AttrDefId::FieldId(it) => it.parent.module(db).krate, 543 AttrDefId::FieldId(it) => it.parent.module(db).krate,
560 AttrDefId::AdtId(it) => it.module(db).krate, 544 AttrDefId::AdtId(it) => it.module(db).krate,
561 AttrDefId::FunctionId(it) => it.lookup(db).module(db).krate, 545 AttrDefId::FunctionId(it) => it.lookup(db).module(db).krate,
562 AttrDefId::EnumVariantId(it) => it.parent.lookup(db).container.module(db).krate, 546 AttrDefId::EnumVariantId(it) => it.parent.lookup(db).container.krate,
563 AttrDefId::StaticId(it) => it.lookup(db).module(db).krate, 547 AttrDefId::StaticId(it) => it.lookup(db).module(db).krate,
564 AttrDefId::ConstId(it) => it.lookup(db).module(db).krate, 548 AttrDefId::ConstId(it) => it.lookup(db).module(db).krate,
565 AttrDefId::TraitId(it) => it.lookup(db).container.module(db).krate, 549 AttrDefId::TraitId(it) => it.lookup(db).container.krate,
566 AttrDefId::TypeAliasId(it) => it.lookup(db).module(db).krate, 550 AttrDefId::TypeAliasId(it) => it.lookup(db).module(db).krate,
567 AttrDefId::ImplId(it) => it.lookup(db).container.module(db).krate, 551 AttrDefId::ImplId(it) => it.lookup(db).container.krate,
568 AttrDefId::GenericParamId(it) => { 552 AttrDefId::GenericParamId(it) => {
569 match it { 553 match it {
570 GenericParamId::TypeParamId(it) => it.parent, 554 GenericParamId::TypeParamId(it) => it.parent,
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs
index 5bf2ba721..9ed48c506 100644
--- a/crates/hir_def/src/nameres/collector.rs
+++ b/crates/hir_def/src/nameres/collector.rs
@@ -37,9 +37,9 @@ use crate::{
37 path::{ImportAlias, ModPath, PathKind}, 37 path::{ImportAlias, ModPath, PathKind},
38 per_ns::PerNs, 38 per_ns::PerNs,
39 visibility::{RawVisibility, Visibility}, 39 visibility::{RawVisibility, Visibility},
40 AdtId, AstId, AstIdWithPath, ConstLoc, ContainerId, EnumLoc, EnumVariantId, FunctionLoc, 40 AdtId, AstId, AstIdWithPath, ConstLoc, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern,
41 ImplLoc, Intern, LocalModuleId, ModuleDefId, StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, 41 LocalModuleId, ModuleDefId, StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, UnionLoc,
42 UnionLoc, UnresolvedMacro, 42 UnresolvedMacro,
43}; 43};
44 44
45const GLOB_RECURSION_LIMIT: usize = 100; 45const GLOB_RECURSION_LIMIT: usize = 100;
@@ -1042,7 +1042,6 @@ impl ModCollector<'_, '_> {
1042 } 1042 }
1043 } 1043 }
1044 let module = self.def_collector.def_map.module_id(self.module_id); 1044 let module = self.def_collector.def_map.module_id(self.module_id);
1045 let container = ContainerId::ModuleId(module);
1046 1045
1047 let mut def = None; 1046 let mut def = None;
1048 match item { 1047 match item {
@@ -1109,9 +1108,9 @@ impl ModCollector<'_, '_> {
1109 } 1108 }
1110 ModItem::Impl(imp) => { 1109 ModItem::Impl(imp) => {
1111 let module = self.def_collector.def_map.module_id(self.module_id); 1110 let module = self.def_collector.def_map.module_id(self.module_id);
1112 let container = ContainerId::ModuleId(module); 1111 let impl_id =
1113 let impl_id = ImplLoc { container, id: ItemTreeId::new(self.file_id, imp) } 1112 ImplLoc { container: module, id: ItemTreeId::new(self.file_id, imp) }
1114 .intern(self.def_collector.db); 1113 .intern(self.def_collector.db);
1115 self.def_collector.def_map.modules[self.module_id].scope.define_impl(impl_id) 1114 self.def_collector.def_map.modules[self.module_id].scope.define_impl(impl_id)
1116 } 1115 }
1117 ModItem::Function(id) => { 1116 ModItem::Function(id) => {
@@ -1140,7 +1139,7 @@ impl ModCollector<'_, '_> {
1140 self.collect_derives(&attrs, it.ast_id.upcast()); 1139 self.collect_derives(&attrs, it.ast_id.upcast());
1141 1140
1142 def = Some(DefData { 1141 def = Some(DefData {
1143 id: StructLoc { container, id: ItemTreeId::new(self.file_id, id) } 1142 id: StructLoc { container: module, id: ItemTreeId::new(self.file_id, id) }
1144 .intern(self.def_collector.db) 1143 .intern(self.def_collector.db)
1145 .into(), 1144 .into(),
1146 name: &it.name, 1145 name: &it.name,
@@ -1157,7 +1156,7 @@ impl ModCollector<'_, '_> {
1157 self.collect_derives(&attrs, it.ast_id.upcast()); 1156 self.collect_derives(&attrs, it.ast_id.upcast());
1158 1157
1159 def = Some(DefData { 1158 def = Some(DefData {
1160 id: UnionLoc { container, id: ItemTreeId::new(self.file_id, id) } 1159 id: UnionLoc { container: module, id: ItemTreeId::new(self.file_id, id) }
1161 .intern(self.def_collector.db) 1160 .intern(self.def_collector.db)
1162 .into(), 1161 .into(),
1163 name: &it.name, 1162 name: &it.name,
@@ -1174,7 +1173,7 @@ impl ModCollector<'_, '_> {
1174 self.collect_derives(&attrs, it.ast_id.upcast()); 1173 self.collect_derives(&attrs, it.ast_id.upcast());
1175 1174
1176 def = Some(DefData { 1175 def = Some(DefData {
1177 id: EnumLoc { container, id: ItemTreeId::new(self.file_id, id) } 1176 id: EnumLoc { container: module, id: ItemTreeId::new(self.file_id, id) }
1178 .intern(self.def_collector.db) 1177 .intern(self.def_collector.db)
1179 .into(), 1178 .into(),
1180 name: &it.name, 1179 name: &it.name,
@@ -1203,7 +1202,7 @@ impl ModCollector<'_, '_> {
1203 let it = &self.item_tree[id]; 1202 let it = &self.item_tree[id];
1204 1203
1205 def = Some(DefData { 1204 def = Some(DefData {
1206 id: StaticLoc { container, id: ItemTreeId::new(self.file_id, id) } 1205 id: StaticLoc { container: module, id: ItemTreeId::new(self.file_id, id) }
1207 .intern(self.def_collector.db) 1206 .intern(self.def_collector.db)
1208 .into(), 1207 .into(),
1209 name: &it.name, 1208 name: &it.name,
@@ -1215,7 +1214,7 @@ impl ModCollector<'_, '_> {
1215 let it = &self.item_tree[id]; 1214 let it = &self.item_tree[id];
1216 1215
1217 def = Some(DefData { 1216 def = Some(DefData {
1218 id: TraitLoc { container, id: ItemTreeId::new(self.file_id, id) } 1217 id: TraitLoc { container: module, id: ItemTreeId::new(self.file_id, id) }
1219 .intern(self.def_collector.db) 1218 .intern(self.def_collector.db)
1220 .into(), 1219 .into(),
1221 name: &it.name, 1220 name: &it.name,
diff --git a/crates/hir_def/src/resolver.rs b/crates/hir_def/src/resolver.rs
index 6f036c8c4..42736171e 100644
--- a/crates/hir_def/src/resolver.rs
+++ b/crates/hir_def/src/resolver.rs
@@ -19,10 +19,10 @@ use crate::{
19 path::{ModPath, PathKind}, 19 path::{ModPath, PathKind},
20 per_ns::PerNs, 20 per_ns::PerNs,
21 visibility::{RawVisibility, Visibility}, 21 visibility::{RawVisibility, Visibility},
22 AdtId, AssocContainerId, ConstId, ConstParamId, ContainerId, DefWithBodyId, EnumId, 22 AdtId, AssocContainerId, ConstId, ConstParamId, DefWithBodyId, EnumId, EnumVariantId,
23 EnumVariantId, FunctionId, GenericDefId, GenericParamId, HasModule, ImplId, LifetimeParamId, 23 FunctionId, GenericDefId, GenericParamId, HasModule, ImplId, LifetimeParamId, LocalModuleId,
24 LocalModuleId, Lookup, ModuleDefId, ModuleId, StaticId, StructId, TraitId, TypeAliasId, 24 Lookup, ModuleDefId, ModuleId, StaticId, StructId, TraitId, TypeAliasId, TypeParamId,
25 TypeParamId, VariantId, 25 VariantId,
26}; 26};
27 27
28#[derive(Debug, Clone, Default)] 28#[derive(Debug, Clone, Default)]
@@ -688,15 +688,6 @@ impl HasResolver for DefWithBodyId {
688 } 688 }
689} 689}
690 690
691impl HasResolver for ContainerId {
692 fn resolver(self, db: &dyn DefDatabase) -> Resolver {
693 match self {
694 ContainerId::ModuleId(it) => it.resolver(db),
695 ContainerId::DefWithBodyId(it) => it.module(db).resolver(db),
696 }
697 }
698}
699
700impl HasResolver for AssocContainerId { 691impl HasResolver for AssocContainerId {
701 fn resolver(self, db: &dyn DefDatabase) -> Resolver { 692 fn resolver(self, db: &dyn DefDatabase) -> Resolver {
702 match self { 693 match self {
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs
index a0882a2a1..ab51cb0a6 100644
--- a/crates/hir_ty/src/display.rs
+++ b/crates/hir_ty/src/display.rs
@@ -6,7 +6,7 @@ use arrayvec::ArrayVec;
6use chalk_ir::Mutability; 6use chalk_ir::Mutability;
7use hir_def::{ 7use hir_def::{
8 db::DefDatabase, find_path, generics::TypeParamProvenance, item_scope::ItemInNs, 8 db::DefDatabase, find_path, generics::TypeParamProvenance, item_scope::ItemInNs,
9 AssocContainerId, HasModule, Lookup, ModuleId, TraitId, 9 AssocContainerId, Lookup, ModuleId, TraitId,
10}; 10};
11use hir_expand::name::Name; 11use hir_expand::name::Name;
12 12
@@ -611,7 +611,7 @@ impl HirDisplay for CallableSig {
611} 611}
612 612
613fn fn_traits(db: &dyn DefDatabase, trait_: TraitId) -> impl Iterator<Item = TraitId> { 613fn fn_traits(db: &dyn DefDatabase, trait_: TraitId) -> impl Iterator<Item = TraitId> {
614 let krate = trait_.lookup(db).container.module(db).krate(); 614 let krate = trait_.lookup(db).container.krate();
615 let fn_traits = [ 615 let fn_traits = [
616 db.lang_item(krate, "fn".into()), 616 db.lang_item(krate, "fn".into()),
617 db.lang_item(krate, "fn_mut".into()), 617 db.lang_item(krate, "fn_mut".into()),
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs
index b90fdc382..5fa83567b 100644
--- a/crates/hir_ty/src/lower.rs
+++ b/crates/hir_ty/src/lower.rs
@@ -1130,8 +1130,8 @@ impl CallableDefId {
1130 let db = db.upcast(); 1130 let db = db.upcast();
1131 match self { 1131 match self {
1132 CallableDefId::FunctionId(f) => f.lookup(db).module(db), 1132 CallableDefId::FunctionId(f) => f.lookup(db).module(db),
1133 CallableDefId::StructId(s) => s.lookup(db).container.module(db), 1133 CallableDefId::StructId(s) => s.lookup(db).container,
1134 CallableDefId::EnumVariantId(e) => e.parent.lookup(db).container.module(db), 1134 CallableDefId::EnumVariantId(e) => e.parent.lookup(db).container,
1135 } 1135 }
1136 .krate() 1136 .krate()
1137 } 1137 }
diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs
index 248367267..ccc12c075 100644
--- a/crates/hir_ty/src/method_resolution.rs
+++ b/crates/hir_ty/src/method_resolution.rs
@@ -267,7 +267,7 @@ impl Ty {
267 LangItemTarget::ImplDefId(it) => Some(it), 267 LangItemTarget::ImplDefId(it) => Some(it),
268 _ => None, 268 _ => None,
269 }) 269 })
270 .map(|it| it.lookup(db.upcast()).container.module(db.upcast()).krate()) 270 .map(|it| it.lookup(db.upcast()).container.krate())
271 .collect(); 271 .collect();
272 Some(res) 272 Some(res)
273 } 273 }
diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs
index 4378a9723..565672b6b 100644
--- a/crates/hir_ty/src/traits/chalk.rs
+++ b/crates/hir_ty/src/traits/chalk.rs
@@ -424,7 +424,7 @@ pub(crate) fn trait_datum_query(
424 let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST); 424 let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST);
425 let flags = rust_ir::TraitFlags { 425 let flags = rust_ir::TraitFlags {
426 auto: trait_data.auto, 426 auto: trait_data.auto,
427 upstream: trait_.lookup(db.upcast()).container.module(db.upcast()).krate() != krate, 427 upstream: trait_.lookup(db.upcast()).container.krate() != krate,
428 non_enumerable: true, 428 non_enumerable: true,
429 coinductive: false, // only relevant for Chalk testing 429 coinductive: false, // only relevant for Chalk testing
430 // FIXME: set these flags correctly 430 // FIXME: set these flags correctly
@@ -548,7 +548,7 @@ fn impl_def_datum(
548 let generic_params = generics(db.upcast(), impl_id.into()); 548 let generic_params = generics(db.upcast(), impl_id.into());
549 let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST); 549 let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST);
550 let trait_ = trait_ref.trait_; 550 let trait_ = trait_ref.trait_;
551 let impl_type = if impl_id.lookup(db.upcast()).container.module(db.upcast()).krate() == krate { 551 let impl_type = if impl_id.lookup(db.upcast()).container.krate() == krate {
552 rust_ir::ImplType::Local 552 rust_ir::ImplType::Local
553 } else { 553 } else {
554 rust_ir::ImplType::External 554 rust_ir::ImplType::External