aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty.rs
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-08-22 12:23:50 +0100
committerFlorian Diebold <[email protected]>2019-08-22 20:55:11 +0100
commitb1a40042e8f595af0486cf1cc70b63be1ff302b3 (patch)
treec3f58127c4a330275d2dd635bb5fb11ca7957ddc /crates/ra_hir/src/ty.rs
parent16a7d8cc850002b427fdc8d21ccde81caaed7902 (diff)
Handle impl/dyn Trait in method resolution
When we have one of these, the `Trait` doesn't need to be in scope to call its methods. So we need to consider this when looking for method candidates. (Actually I think the same is true when we have a bound `T: some::Trait`, but we don't handle that yet). At the same time, since Chalk doesn't handle these types yet, add a small hack to skip Chalk in method resolution and just consider `impl Trait: Trait` always true. This is enough to e.g. get completions for `impl Trait`, but since we don't do any unification we won't infer the return type of e.g. `impl Into<i64>::into()`.
Diffstat (limited to 'crates/ra_hir/src/ty.rs')
-rw-r--r--crates/ra_hir/src/ty.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index 4e5bdbae4..b54c80318 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -583,6 +583,19 @@ impl Ty {
583 ty => ty, 583 ty => ty,
584 }) 584 })
585 } 585 }
586
587 /// If this is an `impl Trait` or `dyn Trait`, returns that trait.
588 pub fn inherent_trait(&self) -> Option<Trait> {
589 match self {
590 Ty::Dyn(predicates) | Ty::Opaque(predicates) => {
591 predicates.iter().find_map(|pred| match pred {
592 GenericPredicate::Implemented(tr) => Some(tr.trait_),
593 _ => None,
594 })
595 }
596 _ => None,
597 }
598 }
586} 599}
587 600
588impl HirDisplay for &Ty { 601impl HirDisplay for &Ty {