diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-09-12 19:35:06 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-09-12 19:35:06 +0100 |
commit | d8b621cf26b59ff5ae9379b50fc822590b6a3a4e (patch) | |
tree | 381f2d4a92db5cdfd35c9e76d5c6b11bcb247c41 /crates/ra_hir/src/resolve.rs | |
parent | 5c09c5949a94012b5ae95735dc8c086efd5039e4 (diff) | |
parent | 63e1e63a9160d28597a8d77fd83c43a2c90d3f6b (diff) |
Merge #1832
1832: start cleaning up the resolution r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/resolve.rs')
-rw-r--r-- | crates/ra_hir/src/resolve.rs | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index d9bdd0e22..1ed150f5a 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs | |||
@@ -15,7 +15,7 @@ use crate::{ | |||
15 | name::{Name, SELF_PARAM, SELF_TYPE}, | 15 | name::{Name, SELF_PARAM, SELF_TYPE}, |
16 | nameres::{CrateDefMap, CrateModuleId, PerNs}, | 16 | nameres::{CrateDefMap, CrateModuleId, PerNs}, |
17 | path::Path, | 17 | path::Path, |
18 | MacroDef, ModuleDef, Trait, | 18 | Enum, MacroDef, ModuleDef, Struct, Trait, |
19 | }; | 19 | }; |
20 | 20 | ||
21 | #[derive(Debug, Clone, Default)] | 21 | #[derive(Debug, Clone, Default)] |
@@ -39,6 +39,8 @@ pub(crate) struct ExprScope { | |||
39 | #[derive(Debug, Clone)] | 39 | #[derive(Debug, Clone)] |
40 | pub(crate) struct PathResult { | 40 | pub(crate) struct PathResult { |
41 | /// The actual path resolution | 41 | /// The actual path resolution |
42 | // FIXME: `PerNs<Resolution>` type doesn't make sense, as not every | ||
43 | // Resolution variant can appear in every namespace | ||
42 | resolution: PerNs<Resolution>, | 44 | resolution: PerNs<Resolution>, |
43 | /// The first index in the path that we | 45 | /// The first index in the path that we |
44 | /// were unable to resolve. | 46 | /// were unable to resolve. |
@@ -113,6 +115,9 @@ pub(crate) enum Scope { | |||
113 | pub enum Resolution { | 115 | pub enum Resolution { |
114 | /// An item | 116 | /// An item |
115 | Def(ModuleDef), | 117 | Def(ModuleDef), |
118 | |||
119 | // FIXME: there's no way we can syntactically confuse a local with generic | ||
120 | // param, so these two should not be members of the single enum | ||
116 | /// A local binding (only value namespace) | 121 | /// A local binding (only value namespace) |
117 | LocalBinding(PatId), | 122 | LocalBinding(PatId), |
118 | /// A generic parameter | 123 | /// A generic parameter |
@@ -121,6 +126,37 @@ pub enum Resolution { | |||
121 | } | 126 | } |
122 | 127 | ||
123 | impl Resolver { | 128 | impl Resolver { |
129 | /// Resolve known trait from std, like `std::futures::Future` | ||
130 | pub(crate) fn resolve_known_trait(&self, db: &impl HirDatabase, path: &Path) -> Option<Trait> { | ||
131 | let res = self.resolve_path_segments(db, path).into_fully_resolved().take_types()?; | ||
132 | match res { | ||
133 | Resolution::Def(ModuleDef::Trait(it)) => Some(it), | ||
134 | _ => None, | ||
135 | } | ||
136 | } | ||
137 | |||
138 | /// Resolve known struct from std, like `std::boxed::Box` | ||
139 | pub(crate) fn resolve_known_struct( | ||
140 | &self, | ||
141 | db: &impl HirDatabase, | ||
142 | path: &Path, | ||
143 | ) -> Option<Struct> { | ||
144 | let res = self.resolve_path_segments(db, path).into_fully_resolved().take_types()?; | ||
145 | match res { | ||
146 | Resolution::Def(ModuleDef::Struct(it)) => Some(it), | ||
147 | _ => None, | ||
148 | } | ||
149 | } | ||
150 | |||
151 | /// Resolve known enum from std, like `std::result::Result` | ||
152 | pub(crate) fn resolve_known_enum(&self, db: &impl HirDatabase, path: &Path) -> Option<Enum> { | ||
153 | let res = self.resolve_path_segments(db, path).into_fully_resolved().take_types()?; | ||
154 | match res { | ||
155 | Resolution::Def(ModuleDef::Enum(it)) => Some(it), | ||
156 | _ => None, | ||
157 | } | ||
158 | } | ||
159 | |||
124 | pub(crate) fn resolve_name(&self, db: &impl HirDatabase, name: &Name) -> PerNs<Resolution> { | 160 | pub(crate) fn resolve_name(&self, db: &impl HirDatabase, name: &Name) -> PerNs<Resolution> { |
125 | let mut resolution = PerNs::none(); | 161 | let mut resolution = PerNs::none(); |
126 | for scope in self.scopes.iter().rev() { | 162 | for scope in self.scopes.iter().rev() { |