diff options
Diffstat (limited to 'crates/hir/src')
-rw-r--r-- | crates/hir/src/attrs.rs | 6 | ||||
-rw-r--r-- | crates/hir/src/code_model.rs | 67 | ||||
-rw-r--r-- | crates/hir/src/has_source.rs | 6 | ||||
-rw-r--r-- | crates/hir/src/semantics/source_to_def.rs | 10 |
4 files changed, 55 insertions, 34 deletions
diff --git a/crates/hir/src/attrs.rs b/crates/hir/src/attrs.rs index 99fb65bac..9e6a3e155 100644 --- a/crates/hir/src/attrs.rs +++ b/crates/hir/src/attrs.rs | |||
@@ -2,6 +2,7 @@ | |||
2 | use hir_def::{ | 2 | use hir_def::{ |
3 | attr::{Attrs, Documentation}, | 3 | attr::{Attrs, Documentation}, |
4 | path::ModPath, | 4 | path::ModPath, |
5 | per_ns::PerNs, | ||
5 | resolver::HasResolver, | 6 | resolver::HasResolver, |
6 | AttrDefId, GenericParamId, ModuleDefId, | 7 | AttrDefId, GenericParamId, ModuleDefId, |
7 | }; | 8 | }; |
@@ -112,6 +113,11 @@ fn resolve_doc_path( | |||
112 | let path = ast::Path::parse(link).ok()?; | 113 | let path = ast::Path::parse(link).ok()?; |
113 | let modpath = ModPath::from_src(path, &Hygiene::new_unhygienic()).unwrap(); | 114 | let modpath = ModPath::from_src(path, &Hygiene::new_unhygienic()).unwrap(); |
114 | let resolved = resolver.resolve_module_path_in_items(db.upcast(), &modpath); | 115 | let resolved = resolver.resolve_module_path_in_items(db.upcast(), &modpath); |
116 | if resolved == PerNs::none() { | ||
117 | if let Some(trait_id) = resolver.resolve_module_path_in_trait_items(db.upcast(), &modpath) { | ||
118 | return Some(ModuleDefId::TraitId(trait_id)); | ||
119 | }; | ||
120 | } | ||
115 | let def = match ns { | 121 | let def = match ns { |
116 | Some(Namespace::Types) => resolved.take_types()?, | 122 | Some(Namespace::Types) => resolved.take_types()?, |
117 | Some(Namespace::Values) => resolved.take_values()?, | 123 | Some(Namespace::Values) => resolved.take_values()?, |
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index aaa7013b6..d9b4cdfce 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs | |||
@@ -270,18 +270,18 @@ 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 | ||
277 | impl Module { | 277 | impl 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. |
283 | pub fn name(self, db: &dyn HirDatabase) -> Option<Name> { | 283 | pub fn name(self, db: &dyn HirDatabase) -> Option<Name> { |
284 | let def_map = db.crate_def_map(self.id.krate); | 284 | let def_map = self.id.def_map(db.upcast()); |
285 | let parent = def_map[self.id.local_id].parent?; | 285 | let parent = def_map[self.id.local_id].parent?; |
286 | def_map[parent].children.iter().find_map(|(name, module_id)| { | 286 | def_map[parent].children.iter().find_map(|(name, module_id)| { |
287 | if *module_id == self.id.local_id { | 287 | if *module_id == self.id.local_id { |
@@ -294,20 +294,20 @@ 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 | ||
308 | /// Iterates over all child modules. | 308 | /// Iterates over all child modules. |
309 | pub fn children(self, db: &dyn HirDatabase) -> impl Iterator<Item = Module> { | 309 | pub fn children(self, db: &dyn HirDatabase) -> impl Iterator<Item = Module> { |
310 | let def_map = db.crate_def_map(self.id.krate); | 310 | let def_map = self.id.def_map(db.upcast()); |
311 | let children = def_map[self.id.local_id] | 311 | let children = def_map[self.id.local_id] |
312 | .children | 312 | .children |
313 | .iter() | 313 | .iter() |
@@ -318,7 +318,8 @@ 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 | let def_map = db.crate_def_map(self.id.krate); | 321 | // FIXME: handle block expressions as modules (their parent is in a different DefMap) |
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)) |
324 | } | 325 | } |
@@ -339,7 +340,7 @@ impl Module { | |||
339 | db: &dyn HirDatabase, | 340 | db: &dyn HirDatabase, |
340 | visible_from: Option<Module>, | 341 | visible_from: Option<Module>, |
341 | ) -> Vec<(Name, ScopeDef)> { | 342 | ) -> Vec<(Name, ScopeDef)> { |
342 | db.crate_def_map(self.id.krate)[self.id.local_id] | 343 | self.id.def_map(db.upcast())[self.id.local_id] |
343 | .scope | 344 | .scope |
344 | .entries() | 345 | .entries() |
345 | .filter_map(|(name, def)| { | 346 | .filter_map(|(name, def)| { |
@@ -362,14 +363,14 @@ impl Module { | |||
362 | } | 363 | } |
363 | 364 | ||
364 | pub fn visibility_of(self, db: &dyn HirDatabase, def: &ModuleDef) -> Option<Visibility> { | 365 | pub fn visibility_of(self, db: &dyn HirDatabase, def: &ModuleDef) -> Option<Visibility> { |
365 | db.crate_def_map(self.id.krate)[self.id.local_id].scope.visibility_of(def.clone().into()) | 366 | self.id.def_map(db.upcast())[self.id.local_id].scope.visibility_of(def.clone().into()) |
366 | } | 367 | } |
367 | 368 | ||
368 | pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) { | 369 | pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) { |
369 | let _p = profile::span("Module::diagnostics").detail(|| { | 370 | let _p = profile::span("Module::diagnostics").detail(|| { |
370 | format!("{:?}", self.name(db).map_or("<unknown>".into(), |name| name.to_string())) | 371 | format!("{:?}", self.name(db).map_or("<unknown>".into(), |name| name.to_string())) |
371 | }); | 372 | }); |
372 | let crate_def_map = db.crate_def_map(self.id.krate); | 373 | let crate_def_map = self.id.def_map(db.upcast()); |
373 | crate_def_map.add_diagnostics(db.upcast(), self.id.local_id, sink); | 374 | crate_def_map.add_diagnostics(db.upcast(), self.id.local_id, sink); |
374 | for decl in self.declarations(db) { | 375 | for decl in self.declarations(db) { |
375 | match decl { | 376 | match decl { |
@@ -396,12 +397,12 @@ impl Module { | |||
396 | } | 397 | } |
397 | 398 | ||
398 | pub fn declarations(self, db: &dyn HirDatabase) -> Vec<ModuleDef> { | 399 | pub fn declarations(self, db: &dyn HirDatabase) -> Vec<ModuleDef> { |
399 | let def_map = db.crate_def_map(self.id.krate); | 400 | let def_map = self.id.def_map(db.upcast()); |
400 | def_map[self.id.local_id].scope.declarations().map(ModuleDef::from).collect() | 401 | def_map[self.id.local_id].scope.declarations().map(ModuleDef::from).collect() |
401 | } | 402 | } |
402 | 403 | ||
403 | pub fn impl_defs(self, db: &dyn HirDatabase) -> Vec<Impl> { | 404 | pub fn impl_defs(self, db: &dyn HirDatabase) -> Vec<Impl> { |
404 | let def_map = db.crate_def_map(self.id.krate); | 405 | let def_map = self.id.def_map(db.upcast()); |
405 | def_map[self.id.local_id].scope.impls().map(Impl::from).collect() | 406 | def_map[self.id.local_id].scope.impls().map(Impl::from).collect() |
406 | } | 407 | } |
407 | 408 | ||
@@ -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/has_source.rs b/crates/hir/src/has_source.rs index 7c57d8378..262002671 100644 --- a/crates/hir/src/has_source.rs +++ b/crates/hir/src/has_source.rs | |||
@@ -24,12 +24,12 @@ pub trait HasSource { | |||
24 | impl Module { | 24 | impl Module { |
25 | /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items. | 25 | /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items. |
26 | pub fn definition_source(self, db: &dyn HirDatabase) -> InFile<ModuleSource> { | 26 | pub fn definition_source(self, db: &dyn HirDatabase) -> InFile<ModuleSource> { |
27 | let def_map = db.crate_def_map(self.id.krate); | 27 | let def_map = self.id.def_map(db.upcast()); |
28 | def_map[self.id.local_id].definition_source(db.upcast()) | 28 | def_map[self.id.local_id].definition_source(db.upcast()) |
29 | } | 29 | } |
30 | 30 | ||
31 | pub fn is_mod_rs(self, db: &dyn HirDatabase) -> bool { | 31 | pub fn is_mod_rs(self, db: &dyn HirDatabase) -> bool { |
32 | let def_map = db.crate_def_map(self.id.krate); | 32 | let def_map = self.id.def_map(db.upcast()); |
33 | match def_map[self.id.local_id].origin { | 33 | match def_map[self.id.local_id].origin { |
34 | ModuleOrigin::File { is_mod_rs, .. } => is_mod_rs, | 34 | ModuleOrigin::File { is_mod_rs, .. } => is_mod_rs, |
35 | _ => false, | 35 | _ => false, |
@@ -39,7 +39,7 @@ impl Module { | |||
39 | /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`. | 39 | /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`. |
40 | /// `None` for the crate root. | 40 | /// `None` for the crate root. |
41 | pub fn declaration_source(self, db: &dyn HirDatabase) -> Option<InFile<ast::Module>> { | 41 | pub fn declaration_source(self, db: &dyn HirDatabase) -> Option<InFile<ast::Module>> { |
42 | let def_map = db.crate_def_map(self.id.krate); | 42 | let def_map = self.id.def_map(db.upcast()); |
43 | def_map[self.id.local_id].declaration_source(db.upcast()) | 43 | def_map[self.id.local_id].declaration_source(db.upcast()) |
44 | } | 44 | } |
45 | } | 45 | } |
diff --git a/crates/hir/src/semantics/source_to_def.rs b/crates/hir/src/semantics/source_to_def.rs index 9bf60c72a..faede3269 100644 --- a/crates/hir/src/semantics/source_to_def.rs +++ b/crates/hir/src/semantics/source_to_def.rs | |||
@@ -31,11 +31,12 @@ impl SourceToDefCtx<'_, '_> { | |||
31 | pub(super) fn file_to_def(&mut self, file: FileId) -> Option<ModuleId> { | 31 | pub(super) fn file_to_def(&mut self, file: FileId) -> Option<ModuleId> { |
32 | let _p = profile::span("SourceBinder::to_module_def"); | 32 | let _p = profile::span("SourceBinder::to_module_def"); |
33 | let (krate, local_id) = self.db.relevant_crates(file).iter().find_map(|&crate_id| { | 33 | let (krate, local_id) = self.db.relevant_crates(file).iter().find_map(|&crate_id| { |
34 | // FIXME: inner items | ||
34 | let crate_def_map = self.db.crate_def_map(crate_id); | 35 | let crate_def_map = self.db.crate_def_map(crate_id); |
35 | let local_id = crate_def_map.modules_for_file(file).next()?; | 36 | let local_id = crate_def_map.modules_for_file(file).next()?; |
36 | Some((crate_id, local_id)) | 37 | Some((crate_id, local_id)) |
37 | })?; | 38 | })?; |
38 | Some(ModuleId { krate, local_id }) | 39 | Some(ModuleId::top_level(krate, local_id)) |
39 | } | 40 | } |
40 | 41 | ||
41 | 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> { |
@@ -60,9 +61,10 @@ impl SourceToDefCtx<'_, '_> { | |||
60 | }?; | 61 | }?; |
61 | 62 | ||
62 | let child_name = src.value.name()?.as_name(); | 63 | let child_name = src.value.name()?.as_name(); |
63 | let def_map = self.db.crate_def_map(parent_module.krate); | 64 | let def_map = parent_module.def_map(self.db.upcast()); |
64 | 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)?; |
65 | 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)) | ||
66 | } | 68 | } |
67 | 69 | ||
68 | 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> { |
@@ -185,7 +187,7 @@ impl SourceToDefCtx<'_, '_> { | |||
185 | ) -> Option<MacroDefId> { | 187 | ) -> Option<MacroDefId> { |
186 | let kind = MacroDefKind::Declarative; | 188 | let kind = MacroDefKind::Declarative; |
187 | let file_id = src.file_id.original_file(self.db.upcast()); | 189 | let file_id = src.file_id.original_file(self.db.upcast()); |
188 | let krate = self.file_to_def(file_id)?.krate; | 190 | let krate = self.file_to_def(file_id)?.krate(); |
189 | 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); |
190 | 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())); |
191 | Some(MacroDefId { krate, ast_id, kind, local_inner: false }) | 193 | Some(MacroDefId { krate, ast_id, kind, local_inner: false }) |