diff options
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r-- | crates/ra_hir_def/src/adt.rs | 14 | ||||
-rw-r--r-- | crates/ra_hir_def/src/body.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir_def/src/body/lower.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir_def/src/body/scope.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 23 | ||||
-rw-r--r-- | crates/ra_hir_def/src/path.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/per_ns.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir_def/src/resolver.rs | 18 |
8 files changed, 44 insertions, 26 deletions
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs index a43f553aa..c9f30923e 100644 --- a/crates/ra_hir_def/src/adt.rs +++ b/crates/ra_hir_def/src/adt.rs | |||
@@ -109,10 +109,18 @@ impl VariantData { | |||
109 | } | 109 | } |
110 | } | 110 | } |
111 | 111 | ||
112 | pub fn fields(&self) -> Option<&Arena<LocalStructFieldId, StructFieldData>> { | 112 | pub fn fields(&self) -> &Arena<LocalStructFieldId, StructFieldData> { |
113 | const EMPTY: &Arena<LocalStructFieldId, StructFieldData> = &Arena::new(); | ||
113 | match &self { | 114 | match &self { |
114 | VariantData::Record(fields) | VariantData::Tuple(fields) => Some(fields), | 115 | VariantData::Record(fields) | VariantData::Tuple(fields) => fields, |
115 | _ => None, | 116 | _ => EMPTY, |
117 | } | ||
118 | } | ||
119 | |||
120 | pub fn is_unit(&self) -> bool { | ||
121 | match self { | ||
122 | VariantData::Unit => true, | ||
123 | _ => false, | ||
116 | } | 124 | } |
117 | } | 125 | } |
118 | } | 126 | } |
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs index 45a36d793..d77ccb272 100644 --- a/crates/ra_hir_def/src/body.rs +++ b/crates/ra_hir_def/src/body.rs | |||
@@ -1,4 +1,5 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! Defines `Body`: a lowered representation of bodies of functions, statics and |
2 | //! consts. | ||
2 | mod lower; | 3 | mod lower; |
3 | pub mod scope; | 4 | pub mod scope; |
4 | 5 | ||
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index f4640dfa4..331736cb2 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs | |||
@@ -1,4 +1,5 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! Transforms `ast::Expr` into an equivalent `hir_def::expr::Expr` |
2 | //! representation. | ||
2 | 3 | ||
3 | use hir_expand::{ | 4 | use hir_expand::{ |
4 | either::Either, | 5 | either::Either, |
diff --git a/crates/ra_hir_def/src/body/scope.rs b/crates/ra_hir_def/src/body/scope.rs index 5240a59d5..625aa39dd 100644 --- a/crates/ra_hir_def/src/body/scope.rs +++ b/crates/ra_hir_def/src/body/scope.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! Name resolution for expressions. |
2 | use std::sync::Arc; | 2 | use std::sync::Arc; |
3 | 3 | ||
4 | use hir_expand::name::Name; | 4 | use hir_expand::name::Name; |
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index f63c3dd64..8e8c2d749 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -192,12 +192,6 @@ pub struct LocalEnumVariantId(RawId); | |||
192 | impl_arena_id!(LocalEnumVariantId); | 192 | impl_arena_id!(LocalEnumVariantId); |
193 | 193 | ||
194 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 194 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
195 | pub enum VariantId { | ||
196 | EnumVariantId(EnumVariantId), | ||
197 | StructId(StructId), | ||
198 | } | ||
199 | |||
200 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
201 | pub struct StructFieldId { | 195 | pub struct StructFieldId { |
202 | pub parent: VariantId, | 196 | pub parent: VariantId, |
203 | pub local_id: LocalStructFieldId, | 197 | pub local_id: LocalStructFieldId, |
@@ -437,6 +431,13 @@ impl_froms!( | |||
437 | ImplId | 431 | ImplId |
438 | ); | 432 | ); |
439 | 433 | ||
434 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
435 | pub enum VariantId { | ||
436 | EnumVariantId(EnumVariantId), | ||
437 | StructId(StructId), | ||
438 | } | ||
439 | impl_froms!(VariantId: EnumVariantId, StructId); | ||
440 | |||
440 | trait Intern { | 441 | trait Intern { |
441 | type ID; | 442 | type ID; |
442 | fn intern(self, db: &impl db::DefDatabase) -> Self::ID; | 443 | fn intern(self, db: &impl db::DefDatabase) -> Self::ID; |
@@ -481,6 +482,16 @@ impl HasModule for ConstLoc { | |||
481 | } | 482 | } |
482 | } | 483 | } |
483 | 484 | ||
485 | impl HasModule for AdtId { | ||
486 | fn module(&self, db: &impl db::DefDatabase) -> ModuleId { | ||
487 | match self { | ||
488 | AdtId::StructId(it) => it.0.module(db), | ||
489 | AdtId::UnionId(it) => it.0.module(db), | ||
490 | AdtId::EnumId(it) => it.module(db), | ||
491 | } | ||
492 | } | ||
493 | } | ||
494 | |||
484 | impl HasModule for StaticLoc { | 495 | impl HasModule for StaticLoc { |
485 | fn module(&self, _db: &impl db::DefDatabase) -> ModuleId { | 496 | fn module(&self, _db: &impl db::DefDatabase) -> ModuleId { |
486 | self.container | 497 | self.container |
diff --git a/crates/ra_hir_def/src/path.rs b/crates/ra_hir_def/src/path.rs index 7b2723d57..0e606fd0e 100644 --- a/crates/ra_hir_def/src/path.rs +++ b/crates/ra_hir_def/src/path.rs | |||
@@ -195,7 +195,7 @@ impl Path { | |||
195 | } | 195 | } |
196 | 196 | ||
197 | /// Converts an `ast::NameRef` into a single-identifier `Path`. | 197 | /// Converts an `ast::NameRef` into a single-identifier `Path`. |
198 | pub fn from_name_ref(name_ref: &ast::NameRef) -> Path { | 198 | pub(crate) fn from_name_ref(name_ref: &ast::NameRef) -> Path { |
199 | name_ref.as_name().into() | 199 | name_ref.as_name().into() |
200 | } | 200 | } |
201 | 201 | ||
diff --git a/crates/ra_hir_def/src/per_ns.rs b/crates/ra_hir_def/src/per_ns.rs index 06ef6c9fc..00e866bf9 100644 --- a/crates/ra_hir_def/src/per_ns.rs +++ b/crates/ra_hir_def/src/per_ns.rs | |||
@@ -1,4 +1,7 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! In rust, it is possible to have a value, a type and a macro with the same |
2 | //! name without conflicts. | ||
3 | //! | ||
4 | //! `PerNs` (per namespace) captures this. | ||
2 | 5 | ||
3 | use hir_expand::MacroDefId; | 6 | use hir_expand::MacroDefId; |
4 | 7 | ||
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs index c24a9b165..95b3c926d 100644 --- a/crates/ra_hir_def/src/resolver.rs +++ b/crates/ra_hir_def/src/resolver.rs | |||
@@ -18,8 +18,8 @@ use crate::{ | |||
18 | path::{Path, PathKind}, | 18 | path::{Path, PathKind}, |
19 | per_ns::PerNs, | 19 | per_ns::PerNs, |
20 | AdtId, AstItemDef, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, | 20 | AdtId, AstItemDef, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, |
21 | GenericDefId, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId, StaticId, StructId, | 21 | GenericDefId, HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId, StaticId, |
22 | TraitId, TypeAliasId, | 22 | StructId, TraitId, TypeAliasId, |
23 | }; | 23 | }; |
24 | 24 | ||
25 | #[derive(Debug, Clone, Default)] | 25 | #[derive(Debug, Clone, Default)] |
@@ -29,20 +29,20 @@ pub struct Resolver { | |||
29 | 29 | ||
30 | // FIXME how to store these best | 30 | // FIXME how to store these best |
31 | #[derive(Debug, Clone)] | 31 | #[derive(Debug, Clone)] |
32 | pub(crate) struct ModuleItemMap { | 32 | struct ModuleItemMap { |
33 | crate_def_map: Arc<CrateDefMap>, | 33 | crate_def_map: Arc<CrateDefMap>, |
34 | module_id: LocalModuleId, | 34 | module_id: LocalModuleId, |
35 | } | 35 | } |
36 | 36 | ||
37 | #[derive(Debug, Clone)] | 37 | #[derive(Debug, Clone)] |
38 | pub(crate) struct ExprScope { | 38 | struct ExprScope { |
39 | owner: DefWithBodyId, | 39 | owner: DefWithBodyId, |
40 | expr_scopes: Arc<ExprScopes>, | 40 | expr_scopes: Arc<ExprScopes>, |
41 | scope_id: ScopeId, | 41 | scope_id: ScopeId, |
42 | } | 42 | } |
43 | 43 | ||
44 | #[derive(Debug, Clone)] | 44 | #[derive(Debug, Clone)] |
45 | pub(crate) enum Scope { | 45 | enum Scope { |
46 | /// All the items and imported names of a module | 46 | /// All the items and imported names of a module |
47 | ModuleScope(ModuleItemMap), | 47 | ModuleScope(ModuleItemMap), |
48 | /// Brings the generic parameters of an item into scope | 48 | /// Brings the generic parameters of an item into scope |
@@ -503,13 +503,7 @@ impl HasResolver for TraitId { | |||
503 | impl<T: Into<AdtId>> HasResolver for T { | 503 | impl<T: Into<AdtId>> HasResolver for T { |
504 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | 504 | fn resolver(self, db: &impl DefDatabase) -> Resolver { |
505 | let def = self.into(); | 505 | let def = self.into(); |
506 | let module = match def { | 506 | def.module(db) |
507 | AdtId::StructId(it) => it.0.module(db), | ||
508 | AdtId::UnionId(it) => it.0.module(db), | ||
509 | AdtId::EnumId(it) => it.module(db), | ||
510 | }; | ||
511 | |||
512 | module | ||
513 | .resolver(db) | 507 | .resolver(db) |
514 | .push_generic_params_scope(db, def.into()) | 508 | .push_generic_params_scope(db, def.into()) |
515 | .push_scope(Scope::AdtScope(def)) | 509 | .push_scope(Scope::AdtScope(def)) |