aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r--crates/ra_hir/src/ty/method_resolution.rs61
1 files changed, 25 insertions, 36 deletions
diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs
index 332bb14b2..43b485ec0 100644
--- a/crates/ra_hir/src/ty/method_resolution.rs
+++ b/crates/ra_hir/src/ty/method_resolution.rs
@@ -269,25 +269,9 @@ fn iterate_trait_method_candidates<T>(
269 // iteration 269 // iteration
270 let mut known_implemented = inherently_implemented; 270 let mut known_implemented = inherently_implemented;
271 for &item in data.items() { 271 for &item in data.items() {
272 // TODO unify with the impl case 272 if !is_valid_candidate(db, name, mode, item) {
273 match item { 273 continue;
274 AssocItem::Function(m) => { 274 }
275 let data = m.data(db);
276 if !name.map_or(true, |name| data.name() == name)
277 || (!data.has_self_param() && mode != LookupMode::Path)
278 {
279 continue;
280 }
281 }
282 AssocItem::Const(c) => {
283 if !name.map_or(true, |name| Some(name) == c.name(db).as_ref())
284 || (mode != LookupMode::Path)
285 {
286 continue;
287 }
288 }
289 _ => {}
290 };
291 if !known_implemented { 275 if !known_implemented {
292 let goal = generic_implements_goal(db, env.clone(), t, ty.clone()); 276 let goal = generic_implements_goal(db, env.clone(), t, ty.clone());
293 if db.trait_solve(krate, goal).is_none() { 277 if db.trait_solve(krate, goal).is_none() {
@@ -316,23 +300,8 @@ fn iterate_inherent_methods<T>(
316 300
317 for impl_block in impls.lookup_impl_blocks(&ty.value) { 301 for impl_block in impls.lookup_impl_blocks(&ty.value) {
318 for item in impl_block.items(db) { 302 for item in impl_block.items(db) {
319 match item { 303 if !is_valid_candidate(db, name, mode, item) {
320 AssocItem::Function(f) => { 304 continue;
321 let data = f.data(db);
322 if !name.map_or(true, |name| data.name() == name)
323 || (!data.has_self_param() && mode != LookupMode::Path)
324 {
325 continue;
326 }
327 }
328 AssocItem::Const(c) => {
329 if !name.map_or(true, |name| Some(name) == c.name(db).as_ref())
330 || (mode != LookupMode::Path)
331 {
332 continue;
333 }
334 }
335 _ => {}
336 } 305 }
337 if let Some(result) = callback(&ty.value, item) { 306 if let Some(result) = callback(&ty.value, item) {
338 return Some(result); 307 return Some(result);
@@ -343,6 +312,26 @@ fn iterate_inherent_methods<T>(
343 None 312 None
344} 313}
345 314
315fn is_valid_candidate(
316 db: &impl HirDatabase,
317 name: Option<&Name>,
318 mode: LookupMode,
319 item: AssocItem,
320) -> bool {
321 match item {
322 AssocItem::Function(m) => {
323 let data = m.data(db);
324 name.map_or(true, |name| data.name() == name)
325 && (data.has_self_param() || mode == LookupMode::Path)
326 }
327 AssocItem::Const(c) => {
328 name.map_or(true, |name| Some(name) == c.name(db).as_ref())
329 && (mode == LookupMode::Path)
330 }
331 _ => false,
332 }
333}
334
346pub(crate) fn implements_trait( 335pub(crate) fn implements_trait(
347 ty: &Canonical<Ty>, 336 ty: &Canonical<Ty>,
348 db: &impl HirDatabase, 337 db: &impl HirDatabase,