aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ty.rs')
-rw-r--r--crates/ra_hir/src/ty.rs28
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;
16use std::ops::Deref; 16use std::ops::Deref;
17use std::{fmt, mem}; 17use std::{fmt, mem};
18 18
19use crate::{Name, AdtDef, type_ref::Mutability, db::HirDatabase, Trait, GenericParams}; 19use crate::{Name, AdtDef, type_ref::Mutability, db::HirDatabase, Trait, GenericParams, TypeAlias};
20use display::{HirDisplay, HirFormatter}; 20use display::{HirDisplay, HirFormatter};
21 21
22pub(crate) use lower::{TypableDef, type_for_def, type_for_field, callable_item_sig, generic_predicates, generic_defaults}; 22pub(crate) use lower::{TypableDef, type_for_def, type_for_field, callable_item_sig, generic_predicates, generic_defaults};
23pub(crate) use infer::{infer_query, InferenceResult, InferTy}; 23pub(crate) use infer::{infer_query, InferenceResult, InferTy};
24pub use lower::CallableDef; 24pub use lower::CallableDef;
25pub(crate) use autoderef::autoderef;
26pub(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)]
109pub 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)]
217pub struct TraitRef { 228pub 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
223impl TraitRef { 234impl 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
469impl HirDisplay for &Ty { 491impl HirDisplay for &Ty {