aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src')
-rw-r--r--crates/hir_ty/src/builder.rs6
-rw-r--r--crates/hir_ty/src/infer/coerce.rs11
-rw-r--r--crates/hir_ty/src/infer/unify.rs14
3 files changed, 11 insertions, 20 deletions
diff --git a/crates/hir_ty/src/builder.rs b/crates/hir_ty/src/builder.rs
index 49d069541..893e727c2 100644
--- a/crates/hir_ty/src/builder.rs
+++ b/crates/hir_ty/src/builder.rs
@@ -6,15 +6,15 @@ use chalk_ir::{
6 cast::{Cast, CastTo, Caster}, 6 cast::{Cast, CastTo, Caster},
7 fold::Fold, 7 fold::Fold,
8 interner::HasInterner, 8 interner::HasInterner,
9 AdtId, BoundVar, DebruijnIndex, Safety, Scalar, 9 AdtId, BoundVar, DebruijnIndex, Scalar,
10}; 10};
11use hir_def::{builtin_type::BuiltinType, GenericDefId, TraitId, TypeAliasId}; 11use hir_def::{builtin_type::BuiltinType, GenericDefId, TraitId, TypeAliasId};
12use smallvec::SmallVec; 12use smallvec::SmallVec;
13 13
14use crate::{ 14use crate::{
15 db::HirDatabase, primitive, to_assoc_type_id, to_chalk_trait_id, utils::generics, Binders, 15 db::HirDatabase, primitive, to_assoc_type_id, to_chalk_trait_id, utils::generics, Binders,
16 CallableSig, FnPointer, FnSig, FnSubst, GenericArg, Interner, ProjectionTy, Substitution, 16 CallableSig, GenericArg, Interner, ProjectionTy, Substitution, TraitRef, Ty, TyDefId, TyExt,
17 TraitRef, Ty, TyDefId, TyExt, TyKind, ValueTyDefId, 17 TyKind, ValueTyDefId,
18}; 18};
19 19
20/// This is a builder for `Ty` or anything that needs a `Substitution`. 20/// This is a builder for `Ty` or anything that needs a `Substitution`.
diff --git a/crates/hir_ty/src/infer/coerce.rs b/crates/hir_ty/src/infer/coerce.rs
index 86a7cd4c2..c82bda70f 100644
--- a/crates/hir_ty/src/infer/coerce.rs
+++ b/crates/hir_ty/src/infer/coerce.rs
@@ -65,7 +65,7 @@ impl<'a> InferenceContext<'a> {
65 } 65 }
66 } 66 }
67 67
68 fn coerce_inner(&mut self, mut from_ty: Ty, to_ty: &Ty) -> InferResult { 68 fn coerce_inner(&mut self, from_ty: Ty, to_ty: &Ty) -> InferResult {
69 if from_ty.is_never() { 69 if from_ty.is_never() {
70 // Subtle: If we are coercing from `!` to `?T`, where `?T` is an unbound 70 // Subtle: If we are coercing from `!` to `?T`, where `?T` is an unbound
71 // type variable, we want `?T` to fallback to `!` if not 71 // type variable, we want `?T` to fallback to `!` if not
@@ -145,10 +145,9 @@ impl<'a> InferenceContext<'a> {
145 /// To match `A` with `B`, autoderef will be performed, 145 /// To match `A` with `B`, autoderef will be performed,
146 /// calling `deref`/`deref_mut` where necessary. 146 /// calling `deref`/`deref_mut` where necessary.
147 fn coerce_ref(&mut self, from_ty: Ty, to_ty: &Ty, to_mt: Mutability) -> InferResult { 147 fn coerce_ref(&mut self, from_ty: Ty, to_ty: &Ty, to_mt: Mutability) -> InferResult {
148 let (from_mt, from_inner) = match from_ty.kind(&Interner) { 148 match from_ty.kind(&Interner) {
149 TyKind::Ref(mt, _, ty) => { 149 TyKind::Ref(mt, _, _) => {
150 coerce_mutabilities(*mt, to_mt)?; 150 coerce_mutabilities(*mt, to_mt)?;
151 (*mt, ty.clone())
152 } 151 }
153 _ => return self.unify_inner(&from_ty, to_ty), 152 _ => return self.unify_inner(&from_ty, to_ty),
154 }; 153 };
@@ -160,7 +159,7 @@ impl<'a> InferenceContext<'a> {
160 // the structure like it is. 159 // the structure like it is.
161 160
162 let canonicalized = self.canonicalize(from_ty.clone()); 161 let canonicalized = self.canonicalize(from_ty.clone());
163 let mut autoderef = autoderef::autoderef( 162 let autoderef = autoderef::autoderef(
164 self.db, 163 self.db,
165 self.resolver.krate(), 164 self.resolver.krate(),
166 InEnvironment { 165 InEnvironment {
@@ -237,7 +236,7 @@ impl<'a> InferenceContext<'a> {
237 /// or a function pointer. 236 /// or a function pointer.
238 fn coerce_from_fn_item(&mut self, from_ty: Ty, to_ty: &Ty) -> InferResult { 237 fn coerce_from_fn_item(&mut self, from_ty: Ty, to_ty: &Ty) -> InferResult {
239 match to_ty.kind(&Interner) { 238 match to_ty.kind(&Interner) {
240 TyKind::Function(b_sig) => { 239 TyKind::Function(_) => {
241 let from_sig = from_ty.callable_sig(self.db).expect("FnDef had no sig"); 240 let from_sig = from_ty.callable_sig(self.db).expect("FnDef had no sig");
242 241
243 // FIXME check ABI: Intrinsics are not coercible to function pointers 242 // FIXME check ABI: Intrinsics are not coercible to function pointers
diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs
index 3a4258e86..a635501b5 100644
--- a/crates/hir_ty/src/infer/unify.rs
+++ b/crates/hir_ty/src/infer/unify.rs
@@ -134,18 +134,10 @@ pub(super) struct TypeVariableTable {
134} 134}
135 135
136impl TypeVariableTable { 136impl TypeVariableTable {
137 fn push(&mut self, data: TypeVariableData) {
138 self.inner.push(data);
139 }
140
141 pub(super) fn set_diverging(&mut self, iv: InferenceVar, diverging: bool) { 137 pub(super) fn set_diverging(&mut self, iv: InferenceVar, diverging: bool) {
142 self.inner[iv.index() as usize].diverging = diverging; 138 self.inner[iv.index() as usize].diverging = diverging;
143 } 139 }
144 140
145 fn is_diverging(&mut self, iv: InferenceVar) -> bool {
146 self.inner[iv.index() as usize].diverging
147 }
148
149 fn fallback_value(&self, iv: InferenceVar, kind: TyVariableKind) -> Ty { 141 fn fallback_value(&self, iv: InferenceVar, kind: TyVariableKind) -> Ty {
150 match kind { 142 match kind {
151 _ if self.inner[iv.index() as usize].diverging => TyKind::Never, 143 _ if self.inner[iv.index() as usize].diverging => TyKind::Never,
@@ -221,7 +213,7 @@ impl<'a> InferenceTable<'a> {
221 /// Unify two types and register new trait goals that arise from that. 213 /// Unify two types and register new trait goals that arise from that.
222 // TODO give these two functions better names 214 // TODO give these two functions better names
223 pub(crate) fn unify(&mut self, ty1: &Ty, ty2: &Ty) -> bool { 215 pub(crate) fn unify(&mut self, ty1: &Ty, ty2: &Ty) -> bool {
224 let result = if let Ok(r) = self.unify_inner(ty1, ty2) { 216 let _result = if let Ok(r) = self.unify_inner(ty1, ty2) {
225 r 217 r
226 } else { 218 } else {
227 return false; 219 return false;
@@ -241,11 +233,11 @@ impl<'a> InferenceTable<'a> {
241 ty1, 233 ty1,
242 ty2, 234 ty2,
243 ) { 235 ) {
244 Ok(result) => { 236 Ok(_result) => {
245 // TODO deal with new goals 237 // TODO deal with new goals
246 Ok(InferOk {}) 238 Ok(InferOk {})
247 } 239 }
248 Err(NoSolution) => Err(TypeError), 240 Err(chalk_ir::NoSolution) => Err(TypeError),
249 } 241 }
250 } 242 }
251 243