diff options
Diffstat (limited to 'crates/ra_ssr/src/resolving.rs')
-rw-r--r-- | crates/ra_ssr/src/resolving.rs | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/crates/ra_ssr/src/resolving.rs b/crates/ra_ssr/src/resolving.rs index 6f62000f4..d5b65eaac 100644 --- a/crates/ra_ssr/src/resolving.rs +++ b/crates/ra_ssr/src/resolving.rs | |||
@@ -5,7 +5,7 @@ use crate::{parsing, SsrError}; | |||
5 | use parsing::Placeholder; | 5 | use parsing::Placeholder; |
6 | use ra_db::FilePosition; | 6 | use ra_db::FilePosition; |
7 | use ra_syntax::{ast, SmolStr, SyntaxKind, SyntaxNode, SyntaxToken}; | 7 | use ra_syntax::{ast, SmolStr, SyntaxKind, SyntaxNode, SyntaxToken}; |
8 | use rustc_hash::{FxHashMap, FxHashSet}; | 8 | use rustc_hash::FxHashMap; |
9 | use test_utils::mark; | 9 | use test_utils::mark; |
10 | 10 | ||
11 | pub(crate) struct ResolutionScope<'db> { | 11 | pub(crate) struct ResolutionScope<'db> { |
@@ -111,8 +111,10 @@ impl Resolver<'_, '_> { | |||
111 | .resolution_scope | 111 | .resolution_scope |
112 | .resolve_path(&path) | 112 | .resolve_path(&path) |
113 | .ok_or_else(|| error!("Failed to resolve path `{}`", node.text()))?; | 113 | .ok_or_else(|| error!("Failed to resolve path `{}`", node.text()))?; |
114 | resolved_paths.insert(node, ResolvedPath { resolution, depth }); | 114 | if self.ok_to_use_path_resolution(&resolution) { |
115 | return Ok(()); | 115 | resolved_paths.insert(node, ResolvedPath { resolution, depth }); |
116 | return Ok(()); | ||
117 | } | ||
116 | } | 118 | } |
117 | } | 119 | } |
118 | for node in node.children() { | 120 | for node in node.children() { |
@@ -136,6 +138,27 @@ impl Resolver<'_, '_> { | |||
136 | } | 138 | } |
137 | false | 139 | false |
138 | } | 140 | } |
141 | |||
142 | fn ok_to_use_path_resolution(&self, resolution: &hir::PathResolution) -> bool { | ||
143 | match resolution { | ||
144 | hir::PathResolution::AssocItem(hir::AssocItem::Function(function)) => { | ||
145 | if function.has_self_param(self.resolution_scope.scope.db) { | ||
146 | // If we don't use this path resolution, then we won't be able to match method | ||
147 | // calls. e.g. `Foo::bar($s)` should match `x.bar()`. | ||
148 | true | ||
149 | } else { | ||
150 | mark::hit!(replace_associated_trait_default_function_call); | ||
151 | false | ||
152 | } | ||
153 | } | ||
154 | hir::PathResolution::AssocItem(_) => { | ||
155 | // Not a function. Could be a constant or an associated type. | ||
156 | mark::hit!(replace_associated_trait_constant); | ||
157 | false | ||
158 | } | ||
159 | _ => true, | ||
160 | } | ||
161 | } | ||
139 | } | 162 | } |
140 | 163 | ||
141 | impl<'db> ResolutionScope<'db> { | 164 | impl<'db> ResolutionScope<'db> { |
@@ -176,7 +199,7 @@ impl<'db> ResolutionScope<'db> { | |||
176 | adt.ty(self.scope.db).iterate_path_candidates( | 199 | adt.ty(self.scope.db).iterate_path_candidates( |
177 | self.scope.db, | 200 | self.scope.db, |
178 | self.scope.module()?.krate(), | 201 | self.scope.module()?.krate(), |
179 | &FxHashSet::default(), | 202 | &self.scope.traits_in_scope(), |
180 | Some(hir_path.segments().last()?.name), | 203 | Some(hir_path.segments().last()?.name), |
181 | |_ty, assoc_item| Some(hir::PathResolution::AssocItem(assoc_item)), | 204 | |_ty, assoc_item| Some(hir::PathResolution::AssocItem(assoc_item)), |
182 | ) | 205 | ) |