diff options
Diffstat (limited to 'crates/hir_ty/src/infer')
-rw-r--r-- | crates/hir_ty/src/infer/coerce.rs | 2 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/expr.rs | 22 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/pat.rs | 19 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/path.rs | 4 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/unify.rs | 4 |
5 files changed, 33 insertions, 18 deletions
diff --git a/crates/hir_ty/src/infer/coerce.rs b/crates/hir_ty/src/infer/coerce.rs index d6c48870a..159a53a63 100644 --- a/crates/hir_ty/src/infer/coerce.rs +++ b/crates/hir_ty/src/infer/coerce.rs | |||
@@ -7,7 +7,7 @@ | |||
7 | use chalk_ir::{cast::Cast, Mutability, TyVariableKind}; | 7 | use chalk_ir::{cast::Cast, Mutability, TyVariableKind}; |
8 | use hir_def::lang_item::LangItemTarget; | 8 | use hir_def::lang_item::LangItemTarget; |
9 | 9 | ||
10 | use crate::{autoderef, Interner, Solution, Ty, TyBuilder, TyKind}; | 10 | use crate::{autoderef, Interner, Solution, Ty, TyBuilder, TyExt, TyKind}; |
11 | 11 | ||
12 | use super::{InEnvironment, InferenceContext}; | 12 | use super::{InEnvironment, InferenceContext}; |
13 | 13 | ||
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index 796487d02..5b3cdab4e 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs | |||
@@ -15,7 +15,7 @@ use stdx::always; | |||
15 | use syntax::ast::RangeOp; | 15 | use syntax::ast::RangeOp; |
16 | 16 | ||
17 | use crate::{ | 17 | use crate::{ |
18 | autoderef, | 18 | autoderef, dummy_usize_const, |
19 | lower::lower_to_chalk_mutability, | 19 | lower::lower_to_chalk_mutability, |
20 | method_resolution, op, | 20 | method_resolution, op, |
21 | primitive::{self, UintTy}, | 21 | primitive::{self, UintTy}, |
@@ -23,7 +23,8 @@ use crate::{ | |||
23 | traits::{chalk::from_chalk, FnTrait}, | 23 | traits::{chalk::from_chalk, FnTrait}, |
24 | utils::{generics, variant_data, Generics}, | 24 | utils::{generics, variant_data, Generics}, |
25 | AdtId, Binders, CallableDefId, FnPointer, FnSig, FnSubst, InEnvironment, Interner, | 25 | AdtId, Binders, CallableDefId, FnPointer, FnSig, FnSubst, InEnvironment, Interner, |
26 | ProjectionTyExt, Rawness, Scalar, Substitution, TraitRef, Ty, TyBuilder, TyKind, TypeWalk, | 26 | ProjectionTyExt, Rawness, Scalar, Substitution, TraitRef, Ty, TyBuilder, TyExt, TyKind, |
27 | TypeWalk, | ||
27 | }; | 28 | }; |
28 | 29 | ||
29 | use super::{ | 30 | use super::{ |
@@ -317,7 +318,13 @@ impl<'a> InferenceContext<'a> { | |||
317 | self.normalize_associated_types_in(ret_ty) | 318 | self.normalize_associated_types_in(ret_ty) |
318 | } | 319 | } |
319 | Expr::MethodCall { receiver, args, method_name, generic_args } => self | 320 | Expr::MethodCall { receiver, args, method_name, generic_args } => self |
320 | .infer_method_call(tgt_expr, *receiver, &args, &method_name, generic_args.as_ref()), | 321 | .infer_method_call( |
322 | tgt_expr, | ||
323 | *receiver, | ||
324 | &args, | ||
325 | &method_name, | ||
326 | generic_args.as_deref(), | ||
327 | ), | ||
321 | Expr::Match { expr, arms } => { | 328 | Expr::Match { expr, arms } => { |
322 | let input_ty = self.infer_expr(*expr, &Expectation::none()); | 329 | let input_ty = self.infer_expr(*expr, &Expectation::none()); |
323 | 330 | ||
@@ -398,7 +405,7 @@ impl<'a> InferenceContext<'a> { | |||
398 | TyKind::Never.intern(&Interner) | 405 | TyKind::Never.intern(&Interner) |
399 | } | 406 | } |
400 | Expr::RecordLit { path, fields, spread } => { | 407 | Expr::RecordLit { path, fields, spread } => { |
401 | let (ty, def_id) = self.resolve_variant(path.as_ref()); | 408 | let (ty, def_id) = self.resolve_variant(path.as_deref()); |
402 | if let Some(variant) = def_id { | 409 | if let Some(variant) = def_id { |
403 | self.write_variant_resolution(tgt_expr.into(), variant); | 410 | self.write_variant_resolution(tgt_expr.into(), variant); |
404 | } | 411 | } |
@@ -702,7 +709,7 @@ impl<'a> InferenceContext<'a> { | |||
702 | } | 709 | } |
703 | Expr::Array(array) => { | 710 | Expr::Array(array) => { |
704 | let elem_ty = match expected.ty.kind(&Interner) { | 711 | let elem_ty = match expected.ty.kind(&Interner) { |
705 | TyKind::Array(st) | TyKind::Slice(st) => st.clone(), | 712 | TyKind::Array(st, _) | TyKind::Slice(st) => st.clone(), |
706 | _ => self.table.new_type_var(), | 713 | _ => self.table.new_type_var(), |
707 | }; | 714 | }; |
708 | 715 | ||
@@ -726,7 +733,7 @@ impl<'a> InferenceContext<'a> { | |||
726 | } | 733 | } |
727 | } | 734 | } |
728 | 735 | ||
729 | TyKind::Array(elem_ty).intern(&Interner) | 736 | TyKind::Array(elem_ty, dummy_usize_const()).intern(&Interner) |
730 | } | 737 | } |
731 | Expr::Literal(lit) => match lit { | 738 | Expr::Literal(lit) => match lit { |
732 | Literal::Bool(..) => TyKind::Scalar(Scalar::Bool).intern(&Interner), | 739 | Literal::Bool(..) => TyKind::Scalar(Scalar::Bool).intern(&Interner), |
@@ -736,7 +743,8 @@ impl<'a> InferenceContext<'a> { | |||
736 | } | 743 | } |
737 | Literal::ByteString(..) => { | 744 | Literal::ByteString(..) => { |
738 | let byte_type = TyKind::Scalar(Scalar::Uint(UintTy::U8)).intern(&Interner); | 745 | let byte_type = TyKind::Scalar(Scalar::Uint(UintTy::U8)).intern(&Interner); |
739 | let array_type = TyKind::Array(byte_type).intern(&Interner); | 746 | let array_type = |
747 | TyKind::Array(byte_type, dummy_usize_const()).intern(&Interner); | ||
740 | TyKind::Ref(Mutability::Not, static_lifetime(), array_type).intern(&Interner) | 748 | TyKind::Ref(Mutability::Not, static_lifetime(), array_type).intern(&Interner) |
741 | } | 749 | } |
742 | Literal::Char(..) => TyKind::Scalar(Scalar::Char).intern(&Interner), | 750 | Literal::Char(..) => TyKind::Scalar(Scalar::Char).intern(&Interner), |
diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs index 2848a393c..12431ae07 100644 --- a/crates/hir_ty/src/infer/pat.rs +++ b/crates/hir_ty/src/infer/pat.rs | |||
@@ -14,7 +14,7 @@ use hir_expand::name::Name; | |||
14 | use super::{BindingMode, Expectation, InferenceContext}; | 14 | use super::{BindingMode, Expectation, InferenceContext}; |
15 | use crate::{ | 15 | use crate::{ |
16 | lower::lower_to_chalk_mutability, static_lifetime, utils::variant_data, Interner, Substitution, | 16 | lower::lower_to_chalk_mutability, static_lifetime, utils::variant_data, Interner, Substitution, |
17 | Ty, TyBuilder, TyKind, | 17 | Ty, TyBuilder, TyExt, TyKind, |
18 | }; | 18 | }; |
19 | 19 | ||
20 | impl<'a> InferenceContext<'a> { | 20 | impl<'a> InferenceContext<'a> { |
@@ -174,7 +174,7 @@ impl<'a> InferenceContext<'a> { | |||
174 | TyKind::Ref(mutability, static_lifetime(), subty).intern(&Interner) | 174 | TyKind::Ref(mutability, static_lifetime(), subty).intern(&Interner) |
175 | } | 175 | } |
176 | Pat::TupleStruct { path: p, args: subpats, ellipsis } => self.infer_tuple_struct_pat( | 176 | Pat::TupleStruct { path: p, args: subpats, ellipsis } => self.infer_tuple_struct_pat( |
177 | p.as_ref(), | 177 | p.as_deref(), |
178 | subpats, | 178 | subpats, |
179 | expected, | 179 | expected, |
180 | default_bm, | 180 | default_bm, |
@@ -182,7 +182,7 @@ impl<'a> InferenceContext<'a> { | |||
182 | *ellipsis, | 182 | *ellipsis, |
183 | ), | 183 | ), |
184 | Pat::Record { path: p, args: fields, ellipsis: _ } => { | 184 | Pat::Record { path: p, args: fields, ellipsis: _ } => { |
185 | self.infer_record_pat(p.as_ref(), fields, expected, default_bm, pat) | 185 | self.infer_record_pat(p.as_deref(), fields, expected, default_bm, pat) |
186 | } | 186 | } |
187 | Pat::Path(path) => { | 187 | Pat::Path(path) => { |
188 | // FIXME use correct resolver for the surrounding expression | 188 | // FIXME use correct resolver for the surrounding expression |
@@ -214,17 +214,20 @@ impl<'a> InferenceContext<'a> { | |||
214 | return inner_ty; | 214 | return inner_ty; |
215 | } | 215 | } |
216 | Pat::Slice { prefix, slice, suffix } => { | 216 | Pat::Slice { prefix, slice, suffix } => { |
217 | let (container_ty, elem_ty): (fn(_) -> _, _) = match expected.kind(&Interner) { | 217 | let elem_ty = match expected.kind(&Interner) { |
218 | TyKind::Array(st) => (TyKind::Array, st.clone()), | 218 | TyKind::Array(st, _) | TyKind::Slice(st) => st.clone(), |
219 | TyKind::Slice(st) => (TyKind::Slice, st.clone()), | 219 | _ => self.err_ty(), |
220 | _ => (TyKind::Slice, self.err_ty()), | ||
221 | }; | 220 | }; |
222 | 221 | ||
223 | for pat_id in prefix.iter().chain(suffix) { | 222 | for pat_id in prefix.iter().chain(suffix) { |
224 | self.infer_pat(*pat_id, &elem_ty, default_bm); | 223 | self.infer_pat(*pat_id, &elem_ty, default_bm); |
225 | } | 224 | } |
226 | 225 | ||
227 | let pat_ty = container_ty(elem_ty).intern(&Interner); | 226 | let pat_ty = match expected.kind(&Interner) { |
227 | TyKind::Array(_, const_) => TyKind::Array(elem_ty, const_.clone()), | ||
228 | _ => TyKind::Slice(elem_ty), | ||
229 | } | ||
230 | .intern(&Interner); | ||
228 | if let Some(slice_pat_id) = slice { | 231 | if let Some(slice_pat_id) = slice { |
229 | self.infer_pat(*slice_pat_id, &pat_ty, default_bm); | 232 | self.infer_pat(*slice_pat_id, &pat_ty, default_bm); |
230 | } | 233 | } |
diff --git a/crates/hir_ty/src/infer/path.rs b/crates/hir_ty/src/infer/path.rs index 14f705173..b19d67bb1 100644 --- a/crates/hir_ty/src/infer/path.rs +++ b/crates/hir_ty/src/infer/path.rs | |||
@@ -10,7 +10,9 @@ use hir_def::{ | |||
10 | }; | 10 | }; |
11 | use hir_expand::name::Name; | 11 | use hir_expand::name::Name; |
12 | 12 | ||
13 | use crate::{method_resolution, Interner, Substitution, Ty, TyBuilder, TyKind, ValueTyDefId}; | 13 | use crate::{ |
14 | method_resolution, Interner, Substitution, Ty, TyBuilder, TyExt, TyKind, ValueTyDefId, | ||
15 | }; | ||
14 | 16 | ||
15 | use super::{ExprOrPatId, InferenceContext, TraitRef}; | 17 | use super::{ExprOrPatId, InferenceContext, TraitRef}; |
16 | 18 | ||
diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs index c7878ebfd..7d76cda68 100644 --- a/crates/hir_ty/src/infer/unify.rs +++ b/crates/hir_ty/src/infer/unify.rs | |||
@@ -317,9 +317,11 @@ impl InferenceTable { | |||
317 | | (TyKind::Closure(.., substs1), TyKind::Closure(.., substs2)) => { | 317 | | (TyKind::Closure(.., substs1), TyKind::Closure(.., substs2)) => { |
318 | self.unify_substs(substs1, substs2, depth + 1) | 318 | self.unify_substs(substs1, substs2, depth + 1) |
319 | } | 319 | } |
320 | (TyKind::Array(ty1, c1), TyKind::Array(ty2, c2)) if c1 == c2 => { | ||
321 | self.unify_inner(ty1, ty2, depth + 1) | ||
322 | } | ||
320 | (TyKind::Ref(_, _, ty1), TyKind::Ref(_, _, ty2)) | 323 | (TyKind::Ref(_, _, ty1), TyKind::Ref(_, _, ty2)) |
321 | | (TyKind::Raw(_, ty1), TyKind::Raw(_, ty2)) | 324 | | (TyKind::Raw(_, ty1), TyKind::Raw(_, ty2)) |
322 | | (TyKind::Array(ty1), TyKind::Array(ty2)) | ||
323 | | (TyKind::Slice(ty1), TyKind::Slice(ty2)) => self.unify_inner(ty1, ty2, depth + 1), | 325 | | (TyKind::Slice(ty1), TyKind::Slice(ty2)) => self.unify_inner(ty1, ty2, depth + 1), |
324 | _ => true, /* we checked equals_ctor already */ | 326 | _ => true, /* we checked equals_ctor already */ |
325 | } | 327 | } |