diff options
author | Marco Groppo <[email protected]> | 2019-04-14 23:03:54 +0100 |
---|---|---|
committer | Marco Groppo <[email protected]> | 2019-04-19 23:10:19 +0100 |
commit | e85ee60c42db57368e24ad9ac24840c2494d383c (patch) | |
tree | a94bb45556b404452e2ef282e6d11887f93601ca /crates/ra_hir/src/ty/infer.rs | |
parent | d55f1136d6444b1f50b9092c36a976d0e1c26202 (diff) |
Initial support for lang items.
Diffstat (limited to 'crates/ra_hir/src/ty/infer.rs')
-rw-r--r-- | crates/ra_hir/src/ty/infer.rs | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 7ca1ff595..2275ac151 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs | |||
@@ -462,6 +462,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
462 | let remaining_index = remaining_index.unwrap_or(path.segments.len()); | 462 | let remaining_index = remaining_index.unwrap_or(path.segments.len()); |
463 | let mut actual_def_ty: Option<Ty> = None; | 463 | let mut actual_def_ty: Option<Ty> = None; |
464 | 464 | ||
465 | let krate = resolver.module().map(|t| t.0.krate()); | ||
465 | // resolve intermediate segments | 466 | // resolve intermediate segments |
466 | for (i, segment) in path.segments[remaining_index..].iter().enumerate() { | 467 | for (i, segment) in path.segments[remaining_index..].iter().enumerate() { |
467 | let ty = match resolved { | 468 | let ty = match resolved { |
@@ -500,38 +501,41 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
500 | // Attempt to find an impl_item for the type which has a name matching | 501 | // Attempt to find an impl_item for the type which has a name matching |
501 | // the current segment | 502 | // the current segment |
502 | log::debug!("looking for path segment: {:?}", segment); | 503 | log::debug!("looking for path segment: {:?}", segment); |
504 | |||
503 | actual_def_ty = Some(ty.clone()); | 505 | actual_def_ty = Some(ty.clone()); |
504 | 506 | ||
505 | let item: crate::ModuleDef = ty.iterate_impl_items(self.db, |item| { | 507 | let item: crate::ModuleDef = krate.and_then(|k| { |
506 | let matching_def: Option<crate::ModuleDef> = match item { | 508 | ty.iterate_impl_items(self.db, k, |item| { |
507 | crate::ImplItem::Method(func) => { | 509 | let matching_def: Option<crate::ModuleDef> = match item { |
508 | let sig = func.signature(self.db); | 510 | crate::ImplItem::Method(func) => { |
509 | if segment.name == *sig.name() { | 511 | let sig = func.signature(self.db); |
510 | Some(func.into()) | 512 | if segment.name == *sig.name() { |
511 | } else { | 513 | Some(func.into()) |
512 | None | 514 | } else { |
515 | None | ||
516 | } | ||
513 | } | 517 | } |
514 | } | ||
515 | 518 | ||
516 | crate::ImplItem::Const(konst) => { | 519 | crate::ImplItem::Const(konst) => { |
517 | let sig = konst.signature(self.db); | 520 | let sig = konst.signature(self.db); |
518 | if segment.name == *sig.name() { | 521 | if segment.name == *sig.name() { |
519 | Some(konst.into()) | 522 | Some(konst.into()) |
520 | } else { | 523 | } else { |
521 | None | 524 | None |
525 | } | ||
522 | } | 526 | } |
523 | } | ||
524 | 527 | ||
525 | // FIXME: Resolve associated types | 528 | // FIXME: Resolve associated types |
526 | crate::ImplItem::TypeAlias(_) => None, | 529 | crate::ImplItem::TypeAlias(_) => None, |
527 | }; | 530 | }; |
528 | match matching_def { | 531 | match matching_def { |
529 | Some(_) => { | 532 | Some(_) => { |
530 | self.write_assoc_resolution(id, item); | 533 | self.write_assoc_resolution(id, item); |
531 | return matching_def; | 534 | return matching_def; |
535 | } | ||
536 | None => None, | ||
532 | } | 537 | } |
533 | None => None, | 538 | }) |
534 | } | ||
535 | })?; | 539 | })?; |
536 | 540 | ||
537 | resolved = Resolution::Def(item.into()); | 541 | resolved = Resolution::Def(item.into()); |