aboutsummaryrefslogtreecommitdiff
path: root/crates/ssr/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-08-13 22:52:14 +0100
committerAleksey Kladov <[email protected]>2020-08-13 22:54:37 +0100
commit9664c57e60ec5662b3e8b063324d9ab7879d5570 (patch)
treea62d88ce37b64507b708f8cdc86c8ff3602a42bc /crates/ssr/src
parent9930ef253634465e2fe25b47b469e4c3bbcf6df1 (diff)
Make hygiene private to hir
Diffstat (limited to 'crates/ssr/src')
-rw-r--r--crates/ssr/src/resolving.rs24
1 files changed, 13 insertions, 11 deletions
diff --git a/crates/ssr/src/resolving.rs b/crates/ssr/src/resolving.rs
index 020fd7994..4441fb426 100644
--- a/crates/ssr/src/resolving.rs
+++ b/crates/ssr/src/resolving.rs
@@ -10,7 +10,6 @@ use test_utils::mark;
10 10
11pub(crate) struct ResolutionScope<'db> { 11pub(crate) struct ResolutionScope<'db> {
12 scope: hir::SemanticsScope<'db>, 12 scope: hir::SemanticsScope<'db>,
13 hygiene: hir::Hygiene,
14 node: SyntaxNode, 13 node: SyntaxNode,
15} 14}
16 15
@@ -201,11 +200,7 @@ impl<'db> ResolutionScope<'db> {
201 .unwrap_or_else(|| file.syntax().clone()); 200 .unwrap_or_else(|| file.syntax().clone());
202 let node = pick_node_for_resolution(node); 201 let node = pick_node_for_resolution(node);
203 let scope = sema.scope(&node); 202 let scope = sema.scope(&node);
204 ResolutionScope { 203 ResolutionScope { scope, node }
205 scope,
206 hygiene: hir::Hygiene::new(sema.db, resolve_context.file_id.into()),
207 node,
208 }
209 } 204 }
210 205
211 /// Returns the function in which SSR was invoked, if any. 206 /// Returns the function in which SSR was invoked, if any.
@@ -214,24 +209,31 @@ impl<'db> ResolutionScope<'db> {
214 } 209 }
215 210
216 fn resolve_path(&self, path: &ast::Path) -> Option<hir::PathResolution> { 211 fn resolve_path(&self, path: &ast::Path) -> Option<hir::PathResolution> {
217 let hir_path = hir::Path::from_src(path.clone(), &self.hygiene)?;
218 // First try resolving the whole path. This will work for things like 212 // First try resolving the whole path. This will work for things like
219 // `std::collections::HashMap`, but will fail for things like 213 // `std::collections::HashMap`, but will fail for things like
220 // `std::collections::HashMap::new`. 214 // `std::collections::HashMap::new`.
221 if let Some(resolution) = self.scope.resolve_hir_path(&hir_path) { 215 if let Some(resolution) = self.scope.resolve_hypothetical(&path) {
222 return Some(resolution); 216 return Some(resolution);
223 } 217 }
224 // Resolution failed, try resolving the qualifier (e.g. `std::collections::HashMap` and if 218 // Resolution failed, try resolving the qualifier (e.g. `std::collections::HashMap` and if
225 // that succeeds, then iterate through the candidates on the resolved type with the provided 219 // that succeeds, then iterate through the candidates on the resolved type with the provided
226 // name. 220 // name.
227 let resolved_qualifier = self.scope.resolve_hir_path_qualifier(&hir_path.qualifier()?)?; 221 let resolved_qualifier = self.scope.resolve_hypothetical(&path.qualifier()?)?;
228 if let hir::PathResolution::Def(hir::ModuleDef::Adt(adt)) = resolved_qualifier { 222 if let hir::PathResolution::Def(hir::ModuleDef::Adt(adt)) = resolved_qualifier {
223 let name = path.segment()?.name_ref()?;
229 adt.ty(self.scope.db).iterate_path_candidates( 224 adt.ty(self.scope.db).iterate_path_candidates(
230 self.scope.db, 225 self.scope.db,
231 self.scope.module()?.krate(), 226 self.scope.module()?.krate(),
232 &self.scope.traits_in_scope(), 227 &self.scope.traits_in_scope(),
233 Some(hir_path.segments().last()?.name), 228 None,
234 |_ty, assoc_item| Some(hir::PathResolution::AssocItem(assoc_item)), 229 |_ty, assoc_item| {
230 let item_name = assoc_item.name(self.scope.db)?;
231 if item_name.to_string().as_str() == name.text().as_str() {
232 Some(hir::PathResolution::AssocItem(assoc_item))
233 } else {
234 None
235 }
236 },
235 ) 237 )
236 } else { 238 } else {
237 None 239 None