aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/lib.rs')
-rw-r--r--crates/hir_ty/src/lib.rs62
1 files changed, 14 insertions, 48 deletions
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index 84645c435..87f10e9d5 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -41,7 +41,7 @@ use crate::{db::HirDatabase, display::HirDisplay, utils::generics};
41 41
42pub use autoderef::autoderef; 42pub use autoderef::autoderef;
43pub use builder::TyBuilder; 43pub use builder::TyBuilder;
44pub use chalk_ext::{ProjectionTyExt, TyExt}; 44pub use chalk_ext::*;
45pub use infer::{could_unify, InferenceResult}; 45pub use infer::{could_unify, InferenceResult};
46pub use lower::{ 46pub use lower::{
47 associated_type_shorthand_candidates, callable_item_sig, CallableDefId, ImplTraitLoweringMode, 47 associated_type_shorthand_candidates, callable_item_sig, CallableDefId, ImplTraitLoweringMode,
@@ -107,22 +107,18 @@ pub fn make_only_type_binders<T>(num_vars: usize, value: T) -> Binders<T> {
107 ) 107 )
108} 108}
109 109
110impl TraitRef { 110// FIXME: get rid of this
111 pub fn hir_trait_id(&self) -> TraitId { 111pub fn make_canonical<T>(
112 from_chalk_trait_id(self.trait_id) 112 value: T,
113 } 113 kinds: impl IntoIterator<Item = TyVariableKind>,
114} 114) -> Canonical<T> {
115 115 let kinds = kinds.into_iter().map(|tk| {
116impl<T> Canonical<T> { 116 chalk_ir::CanonicalVarKind::new(
117 pub fn new(value: T, kinds: impl IntoIterator<Item = TyVariableKind>) -> Self { 117 chalk_ir::VariableKind::Ty(tk),
118 let kinds = kinds.into_iter().map(|tk| { 118 chalk_ir::UniverseIndex::ROOT,
119 chalk_ir::CanonicalVarKind::new( 119 )
120 chalk_ir::VariableKind::Ty(tk), 120 });
121 chalk_ir::UniverseIndex::ROOT, 121 Canonical { value, binders: chalk_ir::CanonicalVarKinds::from_iter(&Interner, kinds) }
122 )
123 });
124 Self { value, binders: chalk_ir::CanonicalVarKinds::from_iter(&Interner, kinds) }
125 }
126} 122}
127 123
128/// A function signature as seen by type inference: Several parameter types and 124/// A function signature as seen by type inference: Several parameter types and
@@ -168,37 +164,7 @@ impl CallableSig {
168 } 164 }
169} 165}
170 166
171impl Ty { 167impl Ty {}
172 pub fn equals_ctor(&self, other: &Ty) -> bool {
173 match (self.kind(&Interner), other.kind(&Interner)) {
174 (TyKind::Adt(adt, ..), TyKind::Adt(adt2, ..)) => adt == adt2,
175 (TyKind::Slice(_), TyKind::Slice(_)) | (TyKind::Array(_, _), TyKind::Array(_, _)) => {
176 true
177 }
178 (TyKind::FnDef(def_id, ..), TyKind::FnDef(def_id2, ..)) => def_id == def_id2,
179 (TyKind::OpaqueType(ty_id, ..), TyKind::OpaqueType(ty_id2, ..)) => ty_id == ty_id2,
180 (TyKind::AssociatedType(ty_id, ..), TyKind::AssociatedType(ty_id2, ..)) => {
181 ty_id == ty_id2
182 }
183 (TyKind::Foreign(ty_id, ..), TyKind::Foreign(ty_id2, ..)) => ty_id == ty_id2,
184 (TyKind::Closure(id1, _), TyKind::Closure(id2, _)) => id1 == id2,
185 (TyKind::Ref(mutability, ..), TyKind::Ref(mutability2, ..))
186 | (TyKind::Raw(mutability, ..), TyKind::Raw(mutability2, ..)) => {
187 mutability == mutability2
188 }
189 (
190 TyKind::Function(FnPointer { num_binders, sig, .. }),
191 TyKind::Function(FnPointer { num_binders: num_binders2, sig: sig2, .. }),
192 ) => num_binders == num_binders2 && sig == sig2,
193 (TyKind::Tuple(cardinality, _), TyKind::Tuple(cardinality2, _)) => {
194 cardinality == cardinality2
195 }
196 (TyKind::Str, TyKind::Str) | (TyKind::Never, TyKind::Never) => true,
197 (TyKind::Scalar(scalar), TyKind::Scalar(scalar2)) => scalar == scalar2,
198 _ => false,
199 }
200 }
201}
202 168
203#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)] 169#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
204pub enum ImplTraitId { 170pub enum ImplTraitId {