diff options
Diffstat (limited to 'crates/hir_ty/src/types.rs')
-rw-r--r-- | crates/hir_ty/src/types.rs | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/crates/hir_ty/src/types.rs b/crates/hir_ty/src/types.rs index 4a626d5e7..d4e07a6b8 100644 --- a/crates/hir_ty/src/types.rs +++ b/crates/hir_ty/src/types.rs | |||
@@ -11,7 +11,7 @@ use smallvec::SmallVec; | |||
11 | 11 | ||
12 | use crate::{ | 12 | use crate::{ |
13 | AssocTypeId, CanonicalVarKinds, ChalkTraitId, ClosureId, FnDefId, FnSig, ForeignDefId, | 13 | AssocTypeId, CanonicalVarKinds, ChalkTraitId, ClosureId, FnDefId, FnSig, ForeignDefId, |
14 | InferenceVar, Interner, OpaqueTyId, PlaceholderIndex, TypeWalk, VariableKinds, | 14 | InferenceVar, Interner, OpaqueTyId, PlaceholderIndex, TypeWalk, VariableKind, VariableKinds, |
15 | }; | 15 | }; |
16 | 16 | ||
17 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] | 17 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] |
@@ -43,9 +43,36 @@ pub struct DynTy { | |||
43 | 43 | ||
44 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] | 44 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] |
45 | pub struct FnPointer { | 45 | pub struct FnPointer { |
46 | pub num_args: usize, | 46 | pub num_binders: usize, |
47 | pub sig: FnSig, | 47 | pub sig: FnSig, |
48 | pub substs: Substitution, | 48 | pub substitution: FnSubst, |
49 | } | ||
50 | /// A wrapper for the substs on a Fn. | ||
51 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] | ||
52 | pub struct FnSubst(pub Substitution); | ||
53 | |||
54 | impl FnPointer { | ||
55 | /// Represent the current `Fn` as if it was wrapped in `Binders` | ||
56 | pub fn into_binders(self, interner: &Interner) -> Binders<FnSubst> { | ||
57 | Binders::new( | ||
58 | VariableKinds::from_iter( | ||
59 | interner, | ||
60 | (0..self.num_binders).map(|_| VariableKind::Lifetime), | ||
61 | ), | ||
62 | self.substitution, | ||
63 | ) | ||
64 | } | ||
65 | |||
66 | /// Represent the current `Fn` as if it was wrapped in `Binders` | ||
67 | pub fn as_binders(&self, interner: &Interner) -> Binders<&FnSubst> { | ||
68 | Binders::new( | ||
69 | VariableKinds::from_iter( | ||
70 | interner, | ||
71 | (0..self.num_binders).map(|_| VariableKind::Lifetime), | ||
72 | ), | ||
73 | &self.substitution, | ||
74 | ) | ||
75 | } | ||
49 | } | 76 | } |
50 | 77 | ||
51 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] | 78 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] |