diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-06-16 13:00:41 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-06-16 13:00:41 +0100 |
commit | b81caed43f1886024ededad41a1baa8a03f1d2f4 (patch) | |
tree | 0a0289899ec59b425eae6369929a01e97065ce43 /crates/ra_hir/src/ty.rs | |
parent | e6fbff3246cdd3278ff1c376d5abfc1d579f86c2 (diff) | |
parent | ad3673d8d86a9b8f1a8dba858abd7cabaa1d5776 (diff) |
Merge #1408
1408: Associated type basics & Deref support r=matklad a=flodiebold
This adds the necessary Chalk integration to handle associated types and uses it to implement support for `Deref` in the `*` operator and autoderef; so e.g. dot completions through an `Arc` work now.
It doesn't yet implement resolution of associated types in paths, though. Also, there's a big FIXME about handling variables in the solution we get from Chalk correctly.
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/ty.rs')
-rw-r--r-- | crates/ra_hir/src/ty.rs | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 4a37e0268..842d49e1f 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -16,12 +16,14 @@ use std::sync::Arc; | |||
16 | use std::ops::Deref; | 16 | use std::ops::Deref; |
17 | use std::{fmt, mem}; | 17 | use std::{fmt, mem}; |
18 | 18 | ||
19 | use crate::{Name, AdtDef, type_ref::Mutability, db::HirDatabase, Trait, GenericParams}; | 19 | use crate::{Name, AdtDef, type_ref::Mutability, db::HirDatabase, Trait, GenericParams, TypeAlias}; |
20 | use display::{HirDisplay, HirFormatter}; | 20 | use display::{HirDisplay, HirFormatter}; |
21 | 21 | ||
22 | pub(crate) use lower::{TypableDef, type_for_def, type_for_field, callable_item_sig, generic_predicates, generic_defaults}; | 22 | pub(crate) use lower::{TypableDef, type_for_def, type_for_field, callable_item_sig, generic_predicates, generic_defaults}; |
23 | pub(crate) use infer::{infer_query, InferenceResult, InferTy}; | 23 | pub(crate) use infer::{infer_query, InferenceResult, InferTy}; |
24 | pub use lower::CallableDef; | 24 | pub use lower::CallableDef; |
25 | pub(crate) use autoderef::autoderef; | ||
26 | pub(crate) use traits::ProjectionPredicate; | ||
25 | 27 | ||
26 | /// A type constructor or type name: this might be something like the primitive | 28 | /// A type constructor or type name: this might be something like the primitive |
27 | /// type `bool`, a struct like `Vec`, or things like function pointers or | 29 | /// type `bool`, a struct like `Vec`, or things like function pointers or |
@@ -100,6 +102,15 @@ pub struct ApplicationTy { | |||
100 | pub parameters: Substs, | 102 | pub parameters: Substs, |
101 | } | 103 | } |
102 | 104 | ||
105 | /// A "projection" type corresponds to an (unnormalized) | ||
106 | /// projection like `<P0 as Trait<P1..Pn>>::Foo`. Note that the | ||
107 | /// trait and all its parameters are fully known. | ||
108 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] | ||
109 | pub struct ProjectionTy { | ||
110 | pub associated_ty: TypeAlias, | ||
111 | pub parameters: Substs, | ||
112 | } | ||
113 | |||
103 | /// A type. | 114 | /// A type. |
104 | /// | 115 | /// |
105 | /// See also the `TyKind` enum in rustc (librustc/ty/sty.rs), which represents | 116 | /// See also the `TyKind` enum in rustc (librustc/ty/sty.rs), which represents |
@@ -216,8 +227,8 @@ impl Deref for Substs { | |||
216 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] | 227 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] |
217 | pub struct TraitRef { | 228 | pub struct TraitRef { |
218 | /// FIXME name? | 229 | /// FIXME name? |
219 | trait_: Trait, | 230 | pub trait_: Trait, |
220 | substs: Substs, | 231 | pub substs: Substs, |
221 | } | 232 | } |
222 | 233 | ||
223 | impl TraitRef { | 234 | impl TraitRef { |
@@ -464,6 +475,17 @@ impl Ty { | |||
464 | _ => None, | 475 | _ => None, |
465 | } | 476 | } |
466 | } | 477 | } |
478 | |||
479 | /// Shifts up `Ty::Bound` vars by `n`. | ||
480 | pub fn shift_bound_vars(self, n: i32) -> Ty { | ||
481 | self.fold(&mut |ty| match ty { | ||
482 | Ty::Bound(idx) => { | ||
483 | assert!(idx as i32 >= -n); | ||
484 | Ty::Bound((idx as i32 + n) as u32) | ||
485 | } | ||
486 | ty => ty, | ||
487 | }) | ||
488 | } | ||
467 | } | 489 | } |
468 | 490 | ||
469 | impl HirDisplay for &Ty { | 491 | impl HirDisplay for &Ty { |