aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/hir/src/code_model.rs51
-rw-r--r--crates/hir/src/semantics/source_to_def.rs7
-rw-r--r--crates/hir_def/src/lib.rs10
-rw-r--r--crates/hir_ty/src/display.rs2
-rw-r--r--crates/hir_ty/src/lib.rs14
-rw-r--r--crates/hir_ty/src/lower.rs2
-rw-r--r--crates/hir_ty/src/method_resolution.rs6
-rw-r--r--crates/hir_ty/src/test_db.rs2
-rw-r--r--crates/hir_ty/src/tests.rs2
-rw-r--r--crates/hir_ty/src/traits/chalk.rs4
10 files changed, 62 insertions, 38 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs
index c34a99d90..d9b4cdfce 100644
--- a/crates/hir/src/code_model.rs
+++ b/crates/hir/src/code_model.rs
@@ -270,13 +270,13 @@ impl ModuleDef {
270 None => return, 270 None => return,
271 }; 271 };
272 272
273 hir_ty::diagnostics::validate_module_item(db, module.id.krate, id, sink) 273 hir_ty::diagnostics::validate_module_item(db, module.id.krate(), id, sink)
274 } 274 }
275} 275}
276 276
277impl Module { 277impl Module {
278 pub(crate) fn new(krate: Crate, crate_module_id: LocalModuleId) -> Module { 278 pub(crate) fn new(krate: Crate, crate_module_id: LocalModuleId) -> Module {
279 Module { id: ModuleId { krate: krate.id, local_id: crate_module_id } } 279 Module { id: ModuleId::top_level(krate.id, crate_module_id) }
280 } 280 }
281 281
282 /// Name of this module. 282 /// Name of this module.
@@ -294,14 +294,14 @@ impl Module {
294 294
295 /// Returns the crate this module is part of. 295 /// Returns the crate this module is part of.
296 pub fn krate(self) -> Crate { 296 pub fn krate(self) -> Crate {
297 Crate { id: self.id.krate } 297 Crate { id: self.id.krate() }
298 } 298 }
299 299
300 /// Topmost parent of this module. Every module has a `crate_root`, but some 300 /// Topmost parent of this module. Every module has a `crate_root`, but some
301 /// might be missing `krate`. This can happen if a module's file is not included 301 /// might be missing `krate`. This can happen if a module's file is not included
302 /// in the module tree of any target in `Cargo.toml`. 302 /// in the module tree of any target in `Cargo.toml`.
303 pub fn crate_root(self, db: &dyn HirDatabase) -> Module { 303 pub fn crate_root(self, db: &dyn HirDatabase) -> Module {
304 let def_map = db.crate_def_map(self.id.krate); 304 let def_map = db.crate_def_map(self.id.krate());
305 self.with_module_id(def_map.root()) 305 self.with_module_id(def_map.root())
306 } 306 }
307 307
@@ -318,6 +318,7 @@ impl Module {
318 318
319 /// Finds a parent module. 319 /// Finds a parent module.
320 pub fn parent(self, db: &dyn HirDatabase) -> Option<Module> { 320 pub fn parent(self, db: &dyn HirDatabase) -> Option<Module> {
321 // FIXME: handle block expressions as modules (their parent is in a different DefMap)
321 let def_map = self.id.def_map(db.upcast()); 322 let def_map = self.id.def_map(db.upcast());
322 let parent_id = def_map[self.id.local_id].parent?; 323 let parent_id = def_map[self.id.local_id].parent?;
323 Some(self.with_module_id(parent_id)) 324 Some(self.with_module_id(parent_id))
@@ -457,7 +458,7 @@ impl Field {
457 }; 458 };
458 let substs = Substs::type_params(db, generic_def_id); 459 let substs = Substs::type_params(db, generic_def_id);
459 let ty = db.field_types(var_id)[self.id].clone().subst(&substs); 460 let ty = db.field_types(var_id)[self.id].clone().subst(&substs);
460 Type::new(db, self.parent.module(db).id.krate, var_id, ty) 461 Type::new(db, self.parent.module(db).id.krate(), var_id, ty)
461 } 462 }
462 463
463 pub fn parent_def(&self, _db: &dyn HirDatabase) -> VariantDef { 464 pub fn parent_def(&self, _db: &dyn HirDatabase) -> VariantDef {
@@ -502,7 +503,11 @@ impl Struct {
502 } 503 }
503 504
504 pub fn ty(self, db: &dyn HirDatabase) -> Type { 505 pub fn ty(self, db: &dyn HirDatabase) -> Type {
505 Type::from_def(db, self.id.lookup(db.upcast()).container.module(db.upcast()).krate, self.id) 506 Type::from_def(
507 db,
508 self.id.lookup(db.upcast()).container.module(db.upcast()).krate(),
509 self.id,
510 )
506 } 511 }
507 512
508 pub fn repr(self, db: &dyn HirDatabase) -> Option<ReprKind> { 513 pub fn repr(self, db: &dyn HirDatabase) -> Option<ReprKind> {
@@ -533,7 +538,11 @@ impl Union {
533 } 538 }
534 539
535 pub fn ty(self, db: &dyn HirDatabase) -> Type { 540 pub fn ty(self, db: &dyn HirDatabase) -> Type {
536 Type::from_def(db, self.id.lookup(db.upcast()).container.module(db.upcast()).krate, self.id) 541 Type::from_def(
542 db,
543 self.id.lookup(db.upcast()).container.module(db.upcast()).krate(),
544 self.id,
545 )
537 } 546 }
538 547
539 pub fn fields(self, db: &dyn HirDatabase) -> Vec<Field> { 548 pub fn fields(self, db: &dyn HirDatabase) -> Vec<Field> {
@@ -573,7 +582,11 @@ impl Enum {
573 } 582 }
574 583
575 pub fn ty(self, db: &dyn HirDatabase) -> Type { 584 pub fn ty(self, db: &dyn HirDatabase) -> Type {
576 Type::from_def(db, self.id.lookup(db.upcast()).container.module(db.upcast()).krate, self.id) 585 Type::from_def(
586 db,
587 self.id.lookup(db.upcast()).container.module(db.upcast()).krate(),
588 self.id,
589 )
577 } 590 }
578} 591}
579 592
@@ -632,7 +645,7 @@ impl Adt {
632 /// general set of completions, but will not look very nice when printed. 645 /// general set of completions, but will not look very nice when printed.
633 pub fn ty(self, db: &dyn HirDatabase) -> Type { 646 pub fn ty(self, db: &dyn HirDatabase) -> Type {
634 let id = AdtId::from(self); 647 let id = AdtId::from(self);
635 Type::from_def(db, id.module(db.upcast()).krate, id) 648 Type::from_def(db, id.module(db.upcast()).krate(), id)
636 } 649 }
637 650
638 pub fn module(self, db: &dyn HirDatabase) -> Module { 651 pub fn module(self, db: &dyn HirDatabase) -> Module {
@@ -750,7 +763,7 @@ impl Function {
750 let ctx = hir_ty::TyLoweringContext::new(db, &resolver); 763 let ctx = hir_ty::TyLoweringContext::new(db, &resolver);
751 let environment = TraitEnvironment::lower(db, &resolver); 764 let environment = TraitEnvironment::lower(db, &resolver);
752 Type { 765 Type {
753 krate: self.id.lookup(db.upcast()).container.module(db.upcast()).krate, 766 krate: self.id.lookup(db.upcast()).container.module(db.upcast()).krate(),
754 ty: InEnvironment { value: Ty::from_hir_ext(&ctx, ret_type).0, environment }, 767 ty: InEnvironment { value: Ty::from_hir_ext(&ctx, ret_type).0, environment },
755 } 768 }
756 } 769 }
@@ -771,7 +784,7 @@ impl Function {
771 .iter() 784 .iter()
772 .map(|type_ref| { 785 .map(|type_ref| {
773 let ty = Type { 786 let ty = Type {
774 krate: self.id.lookup(db.upcast()).container.module(db.upcast()).krate, 787 krate: self.id.lookup(db.upcast()).container.module(db.upcast()).krate(),
775 ty: InEnvironment { 788 ty: InEnvironment {
776 value: Ty::from_hir_ext(&ctx, type_ref).0, 789 value: Ty::from_hir_ext(&ctx, type_ref).0,
777 environment: environment.clone(), 790 environment: environment.clone(),
@@ -795,7 +808,7 @@ impl Function {
795 } 808 }
796 809
797 pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) { 810 pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) {
798 let krate = self.module(db).id.krate; 811 let krate = self.module(db).id.krate();
799 hir_def::diagnostics::validate_body(db.upcast(), self.id.into(), sink); 812 hir_def::diagnostics::validate_body(db.upcast(), self.id.into(), sink);
800 hir_ty::diagnostics::validate_module_item(db, krate, self.id.into(), sink); 813 hir_ty::diagnostics::validate_module_item(db, krate, self.id.into(), sink);
801 hir_ty::diagnostics::validate_body(db, self.id.into(), sink); 814 hir_ty::diagnostics::validate_body(db, self.id.into(), sink);
@@ -973,7 +986,7 @@ impl TypeAlias {
973 } 986 }
974 987
975 pub fn ty(self, db: &dyn HirDatabase) -> Type { 988 pub fn ty(self, db: &dyn HirDatabase) -> Type {
976 Type::from_def(db, self.id.lookup(db.upcast()).module(db.upcast()).krate, self.id) 989 Type::from_def(db, self.id.lookup(db.upcast()).module(db.upcast()).krate(), self.id)
977 } 990 }
978 991
979 pub fn name(self, db: &dyn HirDatabase) -> Name { 992 pub fn name(self, db: &dyn HirDatabase) -> Name {
@@ -1230,7 +1243,7 @@ impl Local {
1230 let def = DefWithBodyId::from(self.parent); 1243 let def = DefWithBodyId::from(self.parent);
1231 let infer = db.infer(def); 1244 let infer = db.infer(def);
1232 let ty = infer[self.pat_id].clone(); 1245 let ty = infer[self.pat_id].clone();
1233 let krate = def.module(db.upcast()).krate; 1246 let krate = def.module(db.upcast()).krate();
1234 Type::new(db, krate, def, ty) 1247 Type::new(db, krate, def, ty)
1235 } 1248 }
1236 1249
@@ -1318,7 +1331,7 @@ impl TypeParam {
1318 let environment = TraitEnvironment::lower(db, &resolver); 1331 let environment = TraitEnvironment::lower(db, &resolver);
1319 let ty = Ty::Placeholder(self.id); 1332 let ty = Ty::Placeholder(self.id);
1320 Type { 1333 Type {
1321 krate: self.id.parent.module(db.upcast()).krate, 1334 krate: self.id.parent.module(db.upcast()).krate(),
1322 ty: InEnvironment { value: ty, environment }, 1335 ty: InEnvironment { value: ty, environment },
1323 } 1336 }
1324 } 1337 }
@@ -1344,7 +1357,7 @@ impl TypeParam {
1344 let subst = Substs::type_params(db, self.id.parent); 1357 let subst = Substs::type_params(db, self.id.parent);
1345 let ty = ty.subst(&subst.prefix(local_idx)); 1358 let ty = ty.subst(&subst.prefix(local_idx));
1346 Some(Type { 1359 Some(Type {
1347 krate: self.id.parent.module(db.upcast()).krate, 1360 krate: self.id.parent.module(db.upcast()).krate(),
1348 ty: InEnvironment { value: ty, environment }, 1361 ty: InEnvironment { value: ty, environment },
1349 }) 1362 })
1350 } 1363 }
@@ -1405,7 +1418,7 @@ impl ConstParam {
1405 1418
1406 pub fn ty(self, db: &dyn HirDatabase) -> Type { 1419 pub fn ty(self, db: &dyn HirDatabase) -> Type {
1407 let def = self.id.parent; 1420 let def = self.id.parent;
1408 let krate = def.module(db.upcast()).krate; 1421 let krate = def.module(db.upcast()).krate();
1409 Type::new(db, krate, def, db.const_param_ty(self.id)) 1422 Type::new(db, krate, def, db.const_param_ty(self.id))
1410 } 1423 }
1411} 1424}
@@ -1440,7 +1453,7 @@ impl Impl {
1440 let environment = TraitEnvironment::lower(db, &resolver); 1453 let environment = TraitEnvironment::lower(db, &resolver);
1441 let ty = Ty::from_hir(&ctx, &impl_data.target_type); 1454 let ty = Ty::from_hir(&ctx, &impl_data.target_type);
1442 Type { 1455 Type {
1443 krate: self.id.lookup(db.upcast()).container.module(db.upcast()).krate, 1456 krate: self.id.lookup(db.upcast()).container.module(db.upcast()).krate(),
1444 ty: InEnvironment { value: ty, environment }, 1457 ty: InEnvironment { value: ty, environment },
1445 } 1458 }
1446 } 1459 }
@@ -1458,7 +1471,7 @@ impl Impl {
1458 } 1471 }
1459 1472
1460 pub fn krate(self, db: &dyn HirDatabase) -> Crate { 1473 pub fn krate(self, db: &dyn HirDatabase) -> Crate {
1461 Crate { id: self.module(db).id.krate } 1474 Crate { id: self.module(db).id.krate() }
1462 } 1475 }
1463 1476
1464 pub fn is_builtin_derive(self, db: &dyn HirDatabase) -> Option<InFile<ast::Attr>> { 1477 pub fn is_builtin_derive(self, db: &dyn HirDatabase) -> Option<InFile<ast::Attr>> {
diff --git a/crates/hir/src/semantics/source_to_def.rs b/crates/hir/src/semantics/source_to_def.rs
index 775f7ec8b..faede3269 100644
--- a/crates/hir/src/semantics/source_to_def.rs
+++ b/crates/hir/src/semantics/source_to_def.rs
@@ -36,7 +36,7 @@ impl SourceToDefCtx<'_, '_> {
36 let local_id = crate_def_map.modules_for_file(file).next()?; 36 let local_id = crate_def_map.modules_for_file(file).next()?;
37 Some((crate_id, local_id)) 37 Some((crate_id, local_id))
38 })?; 38 })?;
39 Some(ModuleId { krate, local_id }) 39 Some(ModuleId::top_level(krate, local_id))
40 } 40 }
41 41
42 pub(super) fn module_to_def(&mut self, src: InFile<ast::Module>) -> Option<ModuleId> { 42 pub(super) fn module_to_def(&mut self, src: InFile<ast::Module>) -> Option<ModuleId> {
@@ -63,7 +63,8 @@ impl SourceToDefCtx<'_, '_> {
63 let child_name = src.value.name()?.as_name(); 63 let child_name = src.value.name()?.as_name();
64 let def_map = parent_module.def_map(self.db.upcast()); 64 let def_map = parent_module.def_map(self.db.upcast());
65 let child_id = *def_map[parent_module.local_id].children.get(&child_name)?; 65 let child_id = *def_map[parent_module.local_id].children.get(&child_name)?;
66 Some(ModuleId { krate: parent_module.krate, local_id: child_id }) 66 // FIXME: handle block expression modules
67 Some(ModuleId::top_level(parent_module.krate(), child_id))
67 } 68 }
68 69
69 pub(super) fn trait_to_def(&mut self, src: InFile<ast::Trait>) -> Option<TraitId> { 70 pub(super) fn trait_to_def(&mut self, src: InFile<ast::Trait>) -> Option<TraitId> {
@@ -186,7 +187,7 @@ impl SourceToDefCtx<'_, '_> {
186 ) -> Option<MacroDefId> { 187 ) -> Option<MacroDefId> {
187 let kind = MacroDefKind::Declarative; 188 let kind = MacroDefKind::Declarative;
188 let file_id = src.file_id.original_file(self.db.upcast()); 189 let file_id = src.file_id.original_file(self.db.upcast());
189 let krate = self.file_to_def(file_id)?.krate; 190 let krate = self.file_to_def(file_id)?.krate();
190 let file_ast_id = self.db.ast_id_map(src.file_id).ast_id(&src.value); 191 let file_ast_id = self.db.ast_id_map(src.file_id).ast_id(&src.value);
191 let ast_id = Some(AstId::new(src.file_id, file_ast_id.upcast())); 192 let ast_id = Some(AstId::new(src.file_id, file_ast_id.upcast()));
192 Some(MacroDefId { krate, ast_id, kind, local_inner: false }) 193 Some(MacroDefId { krate, ast_id, kind, local_inner: false })
diff --git a/crates/hir_def/src/lib.rs b/crates/hir_def/src/lib.rs
index 2f9261a7f..c8dbb2aeb 100644
--- a/crates/hir_def/src/lib.rs
+++ b/crates/hir_def/src/lib.rs
@@ -73,14 +73,22 @@ use stdx::impl_from;
73 73
74#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 74#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
75pub struct ModuleId { 75pub struct ModuleId {
76 pub krate: CrateId, 76 krate: CrateId,
77 pub local_id: LocalModuleId, 77 pub local_id: LocalModuleId,
78} 78}
79 79
80impl ModuleId { 80impl ModuleId {
81 pub fn top_level(krate: CrateId, local_id: LocalModuleId) -> Self {
82 Self { krate, local_id }
83 }
84
81 pub fn def_map(&self, db: &dyn db::DefDatabase) -> Arc<DefMap> { 85 pub fn def_map(&self, db: &dyn db::DefDatabase) -> Arc<DefMap> {
82 db.crate_def_map(self.krate) 86 db.crate_def_map(self.krate)
83 } 87 }
88
89 pub fn krate(&self) -> CrateId {
90 self.krate
91 }
84} 92}
85 93
86/// An ID of a module, **local** to a specific crate 94/// An ID of a module, **local** to a specific crate
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs
index d2f1b4014..38a043c48 100644
--- a/crates/hir_ty/src/display.rs
+++ b/crates/hir_ty/src/display.rs
@@ -617,7 +617,7 @@ impl HirDisplay for FnSig {
617} 617}
618 618
619fn fn_traits(db: &dyn DefDatabase, trait_: TraitId) -> impl Iterator<Item = TraitId> { 619fn fn_traits(db: &dyn DefDatabase, trait_: TraitId) -> impl Iterator<Item = TraitId> {
620 let krate = trait_.lookup(db).container.module(db).krate; 620 let krate = trait_.lookup(db).container.module(db).krate();
621 let fn_traits = [ 621 let fn_traits = [
622 db.lang_item(krate, "fn".into()), 622 db.lang_item(krate, "fn".into()),
623 db.lang_item(krate, "fn_mut".into()), 623 db.lang_item(krate, "fn_mut".into()),
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index e00c7e176..d47f975d2 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -211,19 +211,21 @@ impl TypeCtor {
211 | TypeCtor::Tuple { .. } => None, 211 | TypeCtor::Tuple { .. } => None,
212 // Closure's krate is irrelevant for coherence I would think? 212 // Closure's krate is irrelevant for coherence I would think?
213 TypeCtor::Closure { .. } => None, 213 TypeCtor::Closure { .. } => None,
214 TypeCtor::Adt(adt) => Some(adt.module(db.upcast()).krate), 214 TypeCtor::Adt(adt) => Some(adt.module(db.upcast()).krate()),
215 TypeCtor::FnDef(callable) => Some(callable.krate(db)), 215 TypeCtor::FnDef(callable) => Some(callable.krate(db)),
216 TypeCtor::AssociatedType(type_alias) => { 216 TypeCtor::AssociatedType(type_alias) => {
217 Some(type_alias.lookup(db.upcast()).module(db.upcast()).krate) 217 Some(type_alias.lookup(db.upcast()).module(db.upcast()).krate())
218 } 218 }
219 TypeCtor::ForeignType(type_alias) => { 219 TypeCtor::ForeignType(type_alias) => {
220 Some(type_alias.lookup(db.upcast()).module(db.upcast()).krate) 220 Some(type_alias.lookup(db.upcast()).module(db.upcast()).krate())
221 } 221 }
222 TypeCtor::OpaqueType(opaque_ty_id) => match opaque_ty_id { 222 TypeCtor::OpaqueType(opaque_ty_id) => match opaque_ty_id {
223 OpaqueTyId::ReturnTypeImplTrait(func, _) => { 223 OpaqueTyId::ReturnTypeImplTrait(func, _) => {
224 Some(func.lookup(db.upcast()).module(db.upcast()).krate) 224 Some(func.lookup(db.upcast()).module(db.upcast()).krate())
225 }
226 OpaqueTyId::AsyncBlockTypeImplTrait(def, _) => {
227 Some(def.module(db.upcast()).krate())
225 } 228 }
226 OpaqueTyId::AsyncBlockTypeImplTrait(def, _) => Some(def.module(db.upcast()).krate),
227 }, 229 },
228 } 230 }
229 } 231 }
@@ -870,7 +872,7 @@ impl Ty {
870 Ty::Apply(ApplicationTy { ctor: TypeCtor::OpaqueType(opaque_ty_id), .. }) => { 872 Ty::Apply(ApplicationTy { ctor: TypeCtor::OpaqueType(opaque_ty_id), .. }) => {
871 match opaque_ty_id { 873 match opaque_ty_id {
872 OpaqueTyId::AsyncBlockTypeImplTrait(def, _expr) => { 874 OpaqueTyId::AsyncBlockTypeImplTrait(def, _expr) => {
873 let krate = def.module(db.upcast()).krate; 875 let krate = def.module(db.upcast()).krate();
874 if let Some(future_trait) = db 876 if let Some(future_trait) = db
875 .lang_item(krate, "future_trait".into()) 877 .lang_item(krate, "future_trait".into())
876 .and_then(|item| item.as_trait()) 878 .and_then(|item| item.as_trait())
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs
index 7a734c8b9..dfb573ff3 100644
--- a/crates/hir_ty/src/lower.rs
+++ b/crates/hir_ty/src/lower.rs
@@ -1147,7 +1147,7 @@ impl CallableDefId {
1147 CallableDefId::StructId(s) => s.lookup(db).container.module(db), 1147 CallableDefId::StructId(s) => s.lookup(db).container.module(db),
1148 CallableDefId::EnumVariantId(e) => e.parent.lookup(db).container.module(db), 1148 CallableDefId::EnumVariantId(e) => e.parent.lookup(db).container.module(db),
1149 } 1149 }
1150 .krate 1150 .krate()
1151 } 1151 }
1152} 1152}
1153 1153
diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs
index f06aeeb42..a302456b0 100644
--- a/crates/hir_ty/src/method_resolution.rs
+++ b/crates/hir_ty/src/method_resolution.rs
@@ -248,12 +248,12 @@ impl Ty {
248 let lang_item_targets = match self { 248 let lang_item_targets = match self {
249 Ty::Apply(a_ty) => match a_ty.ctor { 249 Ty::Apply(a_ty) => match a_ty.ctor {
250 TypeCtor::Adt(def_id) => { 250 TypeCtor::Adt(def_id) => {
251 return Some(std::iter::once(def_id.module(db.upcast()).krate).collect()) 251 return Some(std::iter::once(def_id.module(db.upcast()).krate()).collect())
252 } 252 }
253 TypeCtor::ForeignType(type_alias_id) => { 253 TypeCtor::ForeignType(type_alias_id) => {
254 return Some( 254 return Some(
255 std::iter::once( 255 std::iter::once(
256 type_alias_id.lookup(db.upcast()).module(db.upcast()).krate, 256 type_alias_id.lookup(db.upcast()).module(db.upcast()).krate(),
257 ) 257 )
258 .collect(), 258 .collect(),
259 ) 259 )
@@ -280,7 +280,7 @@ impl Ty {
280 LangItemTarget::ImplDefId(it) => Some(it), 280 LangItemTarget::ImplDefId(it) => Some(it),
281 _ => None, 281 _ => None,
282 }) 282 })
283 .map(|it| it.lookup(db.upcast()).container.module(db.upcast()).krate) 283 .map(|it| it.lookup(db.upcast()).container.module(db.upcast()).krate())
284 .collect(); 284 .collect();
285 Some(res) 285 Some(res)
286 } 286 }
diff --git a/crates/hir_ty/src/test_db.rs b/crates/hir_ty/src/test_db.rs
index 3bbcbc242..09696fcf4 100644
--- a/crates/hir_ty/src/test_db.rs
+++ b/crates/hir_ty/src/test_db.rs
@@ -83,7 +83,7 @@ impl TestDB {
83 let crate_def_map = self.crate_def_map(krate); 83 let crate_def_map = self.crate_def_map(krate);
84 for (local_id, data) in crate_def_map.modules() { 84 for (local_id, data) in crate_def_map.modules() {
85 if data.origin.file_id() == Some(file_id) { 85 if data.origin.file_id() == Some(file_id) {
86 return ModuleId { krate, local_id }; 86 return ModuleId::top_level(krate, local_id);
87 } 87 }
88 } 88 }
89 } 89 }
diff --git a/crates/hir_ty/src/tests.rs b/crates/hir_ty/src/tests.rs
index 25ee664d6..7386a4e7b 100644
--- a/crates/hir_ty/src/tests.rs
+++ b/crates/hir_ty/src/tests.rs
@@ -343,7 +343,7 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
343 { 343 {
344 let events = db.log_executed(|| { 344 let events = db.log_executed(|| {
345 let module = db.module_for_file(pos.file_id); 345 let module = db.module_for_file(pos.file_id);
346 let crate_def_map = db.crate_def_map(module.krate); 346 let crate_def_map = module.def_map(&db);
347 visit_module(&db, &crate_def_map, module.local_id, &mut |def| { 347 visit_module(&db, &crate_def_map, module.local_id, &mut |def| {
348 db.infer(def); 348 db.infer(def);
349 }); 349 });
diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs
index 2196af677..cfb756158 100644
--- a/crates/hir_ty/src/traits/chalk.rs
+++ b/crates/hir_ty/src/traits/chalk.rs
@@ -426,7 +426,7 @@ pub(crate) fn trait_datum_query(
426 let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST); 426 let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST);
427 let flags = rust_ir::TraitFlags { 427 let flags = rust_ir::TraitFlags {
428 auto: trait_data.auto, 428 auto: trait_data.auto,
429 upstream: trait_.lookup(db.upcast()).container.module(db.upcast()).krate != krate, 429 upstream: trait_.lookup(db.upcast()).container.module(db.upcast()).krate() != krate,
430 non_enumerable: true, 430 non_enumerable: true,
431 coinductive: false, // only relevant for Chalk testing 431 coinductive: false, // only relevant for Chalk testing
432 // FIXME: set these flags correctly 432 // FIXME: set these flags correctly
@@ -549,7 +549,7 @@ fn impl_def_datum(
549 let generic_params = generics(db.upcast(), impl_id.into()); 549 let generic_params = generics(db.upcast(), impl_id.into());
550 let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST); 550 let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST);
551 let trait_ = trait_ref.trait_; 551 let trait_ = trait_ref.trait_;
552 let impl_type = if impl_id.lookup(db.upcast()).container.module(db.upcast()).krate == krate { 552 let impl_type = if impl_id.lookup(db.upcast()).container.module(db.upcast()).krate() == krate {
553 rust_ir::ImplType::Local 553 rust_ir::ImplType::Local
554 } else { 554 } else {
555 rust_ir::ImplType::External 555 rust_ir::ImplType::External