aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/code_model_impl/module.rs15
-rw-r--r--crates/ra_hir/src/ids.rs9
-rw-r--r--crates/ra_hir/src/ty.rs7
3 files changed, 23 insertions, 8 deletions
diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs
index 2014f1090..73c212de8 100644
--- a/crates/ra_hir/src/code_model_impl/module.rs
+++ b/crates/ra_hir/src/code_model_impl/module.rs
@@ -95,7 +95,7 @@ impl Module {
95 } 95 }
96 96
97 /// Finds a child module with the specified name. 97 /// Finds a child module with the specified name.
98 pub fn child_impl(&self, db: &impl HirDatabase, name: &Name) -> Option<Module> { 98 pub(crate) fn child_impl(&self, db: &impl HirDatabase, name: &Name) -> Option<Module> {
99 let loc = self.def_id.loc(db); 99 let loc = self.def_id.loc(db);
100 let module_tree = db.module_tree(loc.source_root_id); 100 let module_tree = db.module_tree(loc.source_root_id);
101 let child_id = loc.module_id.child(&module_tree, name)?; 101 let child_id = loc.module_id.child(&module_tree, name)?;
@@ -103,7 +103,7 @@ impl Module {
103 } 103 }
104 104
105 /// Iterates over all child modules. 105 /// Iterates over all child modules.
106 pub fn children_impl(&self, db: &impl HirDatabase) -> impl Iterator<Item = Module> { 106 pub(crate) fn children_impl(&self, db: &impl HirDatabase) -> impl Iterator<Item = Module> {
107 // FIXME this should be implementable without collecting into a vec, but 107 // FIXME this should be implementable without collecting into a vec, but
108 // it's kind of hard since the iterator needs to keep a reference to the 108 // it's kind of hard since the iterator needs to keep a reference to the
109 // module tree. 109 // module tree.
@@ -117,7 +117,7 @@ impl Module {
117 children.into_iter() 117 children.into_iter()
118 } 118 }
119 119
120 pub fn parent_impl(&self, db: &impl HirDatabase) -> Option<Module> { 120 pub(crate) fn parent_impl(&self, db: &impl HirDatabase) -> Option<Module> {
121 let loc = self.def_id.loc(db); 121 let loc = self.def_id.loc(db);
122 let module_tree = db.module_tree(loc.source_root_id); 122 let module_tree = db.module_tree(loc.source_root_id);
123 let parent_id = loc.module_id.parent(&module_tree)?; 123 let parent_id = loc.module_id.parent(&module_tree)?;
@@ -125,13 +125,13 @@ impl Module {
125 } 125 }
126 126
127 /// Returns a `ModuleScope`: a set of items, visible in this module. 127 /// Returns a `ModuleScope`: a set of items, visible in this module.
128 pub fn scope_impl(&self, db: &impl HirDatabase) -> ModuleScope { 128 pub(crate) fn scope_impl(&self, db: &impl HirDatabase) -> ModuleScope {
129 let loc = self.def_id.loc(db); 129 let loc = self.def_id.loc(db);
130 let item_map = db.item_map(loc.source_root_id); 130 let item_map = db.item_map(loc.source_root_id);
131 item_map.per_module[&loc.module_id].clone() 131 item_map.per_module[&loc.module_id].clone()
132 } 132 }
133 133
134 pub fn resolve_path_impl(&self, db: &impl HirDatabase, path: &Path) -> PerNs<DefId> { 134 pub(crate) fn resolve_path_impl(&self, db: &impl HirDatabase, path: &Path) -> PerNs<DefId> {
135 let mut curr_per_ns = PerNs::types( 135 let mut curr_per_ns = PerNs::types(
136 match path.kind { 136 match path.kind {
137 PathKind::Crate => self.crate_root(db), 137 PathKind::Crate => self.crate_root(db),
@@ -191,7 +191,10 @@ impl Module {
191 curr_per_ns 191 curr_per_ns
192 } 192 }
193 193
194 pub fn problems_impl(&self, db: &impl HirDatabase) -> Vec<(TreeArc<SyntaxNode>, Problem)> { 194 pub(crate) fn problems_impl(
195 &self,
196 db: &impl HirDatabase,
197 ) -> Vec<(TreeArc<SyntaxNode>, Problem)> {
195 let loc = self.def_id.loc(db); 198 let loc = self.def_id.loc(db);
196 let module_tree = db.module_tree(loc.source_root_id); 199 let module_tree = db.module_tree(loc.source_root_id);
197 loc.module_id.problems(&module_tree, db) 200 loc.module_id.problems(&module_tree, db)
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
index 0d8e67547..c5408e277 100644
--- a/crates/ra_hir/src/ids.rs
+++ b/crates/ra_hir/src/ids.rs
@@ -151,6 +151,15 @@ pub(crate) enum DefKind {
151 Type, 151 Type,
152 Item, 152 Item,
153 153
154 /// The constructor of a struct. E.g. if we have `struct Foo(usize)`, the
155 /// name `Foo` needs to resolve to different types depending on whether we
156 /// are in the types or values namespace: As a type, `Foo` of course refers
157 /// to the struct `Foo`; as a value, `Foo` is a callable type with signature
158 /// `(usize) -> Foo`. The cleanest approach to handle this seems to be to
159 /// have different defs in the two namespaces.
160 ///
161 /// rustc does the same; note that it even creates a struct constructor if
162 /// the struct isn't a tuple struct (see `CtorKind::Fictive` in rustc).
154 StructCtor, 163 StructCtor,
155} 164}
156 165
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index b9a48929d..8e93a4457 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -242,7 +242,8 @@ pub enum Ty {
242 // Opaque(DefId, Substs), 242 // Opaque(DefId, Substs),
243 /// A type parameter; for example, `T` in `fn f<T>(x: T) {} 243 /// A type parameter; for example, `T` in `fn f<T>(x: T) {}
244 Param { 244 Param {
245 /// The index of the parameter. 245 /// The index of the parameter (starting with parameters from the
246 /// surrounding impl, then the current function).
246 idx: u32, 247 idx: u32,
247 /// The name of the parameter, for displaying. 248 /// The name of the parameter, for displaying.
248 name: Name, 249 name: Name,
@@ -440,7 +441,9 @@ impl Ty {
440 if (idx as usize) < substs.0.len() { 441 if (idx as usize) < substs.0.len() {
441 substs.0[idx as usize].clone() 442 substs.0[idx as usize].clone()
442 } else { 443 } else {
443 // TODO it's yet unclear to me whether we need to shift the indices here 444 // TODO: does this indicate a bug? i.e. should we always
445 // have substs for all type params? (they might contain the
446 // params themselves again...)
444 Ty::Param { idx, name } 447 Ty::Param { idx, name }
445 } 448 }
446 } 449 }