diff options
author | Florian Diebold <[email protected]> | 2021-04-03 16:49:29 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2021-04-08 13:08:55 +0100 |
commit | 7e541e69b1eaab3c242c864a0930cb263d2cbaf5 (patch) | |
tree | 88fb29aa7e0b782efc9f91ec5676d93e4db4ffd7 /crates/hir_ty | |
parent | 926bfef0efc5caca2a04a50beaba9127338e21e0 (diff) |
Add HasInterner bounds
Diffstat (limited to 'crates/hir_ty')
-rw-r--r-- | crates/hir_ty/src/chalk_cast.rs | 8 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/unify.rs | 16 | ||||
-rw-r--r-- | crates/hir_ty/src/lib.rs | 15 | ||||
-rw-r--r-- | crates/hir_ty/src/lower.rs | 4 | ||||
-rw-r--r-- | crates/hir_ty/src/traits/chalk.rs | 2 | ||||
-rw-r--r-- | crates/hir_ty/src/walk.rs | 4 |
6 files changed, 35 insertions, 14 deletions
diff --git a/crates/hir_ty/src/chalk_cast.rs b/crates/hir_ty/src/chalk_cast.rs index 1c3feabca..8bdd32ad6 100644 --- a/crates/hir_ty/src/chalk_cast.rs +++ b/crates/hir_ty/src/chalk_cast.rs | |||
@@ -5,7 +5,10 @@ use chalk_ir::{ | |||
5 | interner::HasInterner, | 5 | interner::HasInterner, |
6 | }; | 6 | }; |
7 | 7 | ||
8 | use crate::{AliasEq, DomainGoal, GenericArg, GenericArgData, Interner, TraitRef, Ty, WhereClause}; | 8 | use crate::{ |
9 | AliasEq, CallableSig, DomainGoal, GenericArg, GenericArgData, Interner, PolyFnSig, | ||
10 | ReturnTypeImplTraits, TraitRef, Ty, WhereClause, | ||
11 | }; | ||
9 | 12 | ||
10 | macro_rules! has_interner { | 13 | macro_rules! has_interner { |
11 | ($t:ty) => { | 14 | ($t:ty) => { |
@@ -24,3 +27,6 @@ macro_rules! transitive_impl { | |||
24 | } | 27 | } |
25 | }; | 28 | }; |
26 | } | 29 | } |
30 | |||
31 | has_interner!(CallableSig); | ||
32 | has_interner!(ReturnTypeImplTraits); | ||
diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs index 2ea9dd920..3732d8ebd 100644 --- a/crates/hir_ty/src/infer/unify.rs +++ b/crates/hir_ty/src/infer/unify.rs | |||
@@ -2,7 +2,9 @@ | |||
2 | 2 | ||
3 | use std::borrow::Cow; | 3 | use std::borrow::Cow; |
4 | 4 | ||
5 | use chalk_ir::{FloatTy, IntTy, TyVariableKind, UniverseIndex, VariableKind}; | 5 | use chalk_ir::{ |
6 | interner::HasInterner, FloatTy, IntTy, TyVariableKind, UniverseIndex, VariableKind, | ||
7 | }; | ||
6 | use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue}; | 8 | use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue}; |
7 | 9 | ||
8 | use super::{DomainGoal, InferenceContext}; | 10 | use super::{DomainGoal, InferenceContext}; |
@@ -34,7 +36,10 @@ where | |||
34 | } | 36 | } |
35 | 37 | ||
36 | #[derive(Debug)] | 38 | #[derive(Debug)] |
37 | pub(super) struct Canonicalized<T> { | 39 | pub(super) struct Canonicalized<T> |
40 | where | ||
41 | T: HasInterner<Interner = Interner>, | ||
42 | { | ||
38 | pub(super) value: Canonical<T>, | 43 | pub(super) value: Canonical<T>, |
39 | free_vars: Vec<(InferenceVar, TyVariableKind)>, | 44 | free_vars: Vec<(InferenceVar, TyVariableKind)>, |
40 | } | 45 | } |
@@ -76,7 +81,10 @@ impl<'a, 'b> Canonicalizer<'a, 'b> { | |||
76 | ) | 81 | ) |
77 | } | 82 | } |
78 | 83 | ||
79 | fn into_canonicalized<T>(self, result: T) -> Canonicalized<T> { | 84 | fn into_canonicalized<T: HasInterner<Interner = Interner>>( |
85 | self, | ||
86 | result: T, | ||
87 | ) -> Canonicalized<T> { | ||
80 | let kinds = self | 88 | let kinds = self |
81 | .free_vars | 89 | .free_vars |
82 | .iter() | 90 | .iter() |
@@ -108,7 +116,7 @@ impl<'a, 'b> Canonicalizer<'a, 'b> { | |||
108 | } | 116 | } |
109 | } | 117 | } |
110 | 118 | ||
111 | impl<T> Canonicalized<T> { | 119 | impl<T: HasInterner<Interner = Interner>> Canonicalized<T> { |
112 | pub(super) fn decanonicalize_ty(&self, ty: Ty) -> Ty { | 120 | pub(super) fn decanonicalize_ty(&self, ty: Ty) -> Ty { |
113 | ty.fold_binders( | 121 | ty.fold_binders( |
114 | &mut |ty, binders| { | 122 | &mut |ty, binders| { |
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index 5fa8b3296..23dec7040 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs | |||
@@ -33,7 +33,11 @@ mod test_db; | |||
33 | use std::sync::Arc; | 33 | use std::sync::Arc; |
34 | 34 | ||
35 | use base_db::salsa; | 35 | use base_db::salsa; |
36 | use chalk_ir::UintTy; | 36 | use chalk_ir::{ |
37 | cast::{CastTo, Caster}, | ||
38 | interner::HasInterner, | ||
39 | UintTy, | ||
40 | }; | ||
37 | use hir_def::{ | 41 | use hir_def::{ |
38 | expr::ExprId, type_ref::Rawness, ConstParamId, LifetimeParamId, TraitId, TypeAliasId, | 42 | expr::ExprId, type_ref::Rawness, ConstParamId, LifetimeParamId, TraitId, TypeAliasId, |
39 | TypeParamId, | 43 | TypeParamId, |
@@ -115,12 +119,15 @@ pub fn param_idx(db: &dyn HirDatabase, id: TypeParamId) -> Option<usize> { | |||
115 | 119 | ||
116 | pub fn wrap_empty_binders<T>(value: T) -> Binders<T> | 120 | pub fn wrap_empty_binders<T>(value: T) -> Binders<T> |
117 | where | 121 | where |
118 | T: TypeWalk, | 122 | T: TypeWalk + HasInterner<Interner = Interner>, |
119 | { | 123 | { |
120 | Binders::empty(&Interner, value.shifted_in_from(DebruijnIndex::ONE)) | 124 | Binders::empty(&Interner, value.shifted_in_from(DebruijnIndex::ONE)) |
121 | } | 125 | } |
122 | 126 | ||
123 | pub fn make_only_type_binders<T>(num_vars: usize, value: T) -> Binders<T> { | 127 | pub fn make_only_type_binders<T: HasInterner<Interner = Interner>>( |
128 | num_vars: usize, | ||
129 | value: T, | ||
130 | ) -> Binders<T> { | ||
124 | Binders::new( | 131 | Binders::new( |
125 | VariableKinds::from_iter( | 132 | VariableKinds::from_iter( |
126 | &Interner, | 133 | &Interner, |
@@ -132,7 +139,7 @@ pub fn make_only_type_binders<T>(num_vars: usize, value: T) -> Binders<T> { | |||
132 | } | 139 | } |
133 | 140 | ||
134 | // FIXME: get rid of this | 141 | // FIXME: get rid of this |
135 | pub fn make_canonical<T>( | 142 | pub fn make_canonical<T: HasInterner<Interner = Interner>>( |
136 | value: T, | 143 | value: T, |
137 | kinds: impl IntoIterator<Item = TyVariableKind>, | 144 | kinds: impl IntoIterator<Item = TyVariableKind>, |
138 | ) -> Canonical<T> { | 145 | ) -> Canonical<T> { |
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index e6903e189..d4ba707b4 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs | |||
@@ -8,7 +8,7 @@ | |||
8 | use std::{iter, sync::Arc}; | 8 | use std::{iter, sync::Arc}; |
9 | 9 | ||
10 | use base_db::CrateId; | 10 | use base_db::CrateId; |
11 | use chalk_ir::{cast::Cast, Mutability, Safety}; | 11 | use chalk_ir::{cast::Cast, interner::HasInterner, Mutability, Safety}; |
12 | use hir_def::{ | 12 | use hir_def::{ |
13 | adt::StructKind, | 13 | adt::StructKind, |
14 | builtin_type::BuiltinType, | 14 | builtin_type::BuiltinType, |
@@ -1307,6 +1307,6 @@ pub(crate) fn lower_to_chalk_mutability(m: hir_def::type_ref::Mutability) -> Mut | |||
1307 | } | 1307 | } |
1308 | } | 1308 | } |
1309 | 1309 | ||
1310 | fn make_binders<T>(generics: &Generics, value: T) -> Binders<T> { | 1310 | fn make_binders<T: HasInterner<Interner = Interner>>(generics: &Generics, value: T) -> Binders<T> { |
1311 | crate::make_only_type_binders(generics.len(), value) | 1311 | crate::make_only_type_binders(generics.len(), value) |
1312 | } | 1312 | } |
diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs index 090f6492b..a5aa40c10 100644 --- a/crates/hir_ty/src/traits/chalk.rs +++ b/crates/hir_ty/src/traits/chalk.rs | |||
@@ -3,7 +3,7 @@ use std::sync::Arc; | |||
3 | 3 | ||
4 | use log::debug; | 4 | use log::debug; |
5 | 5 | ||
6 | use chalk_ir::{fold::shift::Shift, CanonicalVarKinds}; | 6 | use chalk_ir::{fold::shift::Shift, interner::HasInterner, CanonicalVarKinds}; |
7 | use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait}; | 7 | use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait}; |
8 | 8 | ||
9 | use base_db::{salsa::InternKey, CrateId}; | 9 | use base_db::{salsa::InternKey, CrateId}; |
diff --git a/crates/hir_ty/src/walk.rs b/crates/hir_ty/src/walk.rs index 873d563c0..c1aecdafc 100644 --- a/crates/hir_ty/src/walk.rs +++ b/crates/hir_ty/src/walk.rs | |||
@@ -3,7 +3,7 @@ | |||
3 | 3 | ||
4 | use std::mem; | 4 | use std::mem; |
5 | 5 | ||
6 | use chalk_ir::DebruijnIndex; | 6 | use chalk_ir::{interner::HasInterner, DebruijnIndex}; |
7 | 7 | ||
8 | use crate::{ | 8 | use crate::{ |
9 | utils::make_mut_slice, AliasEq, AliasTy, Binders, CallableSig, FnSubst, GenericArg, | 9 | utils::make_mut_slice, AliasEq, AliasTy, Binders, CallableSig, FnSubst, GenericArg, |
@@ -320,7 +320,7 @@ impl TypeWalk for Substitution { | |||
320 | } | 320 | } |
321 | } | 321 | } |
322 | 322 | ||
323 | impl<T: TypeWalk> TypeWalk for Binders<T> { | 323 | impl<T: TypeWalk + HasInterner<Interner = Interner>> TypeWalk for Binders<T> { |
324 | fn walk(&self, f: &mut impl FnMut(&Ty)) { | 324 | fn walk(&self, f: &mut impl FnMut(&Ty)) { |
325 | self.skip_binders().walk(f); | 325 | self.skip_binders().walk(f); |
326 | } | 326 | } |