From 9fbba7bc45ec6bea9468931d9d9fdd0141826f0a Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 6 Apr 2021 11:45:41 +0200 Subject: Add chalk_ir::Const to TyKind::Array --- crates/hir_ty/src/infer/expr.rs | 9 +++++---- crates/hir_ty/src/infer/pat.rs | 13 ++++++++----- crates/hir_ty/src/infer/unify.rs | 4 +++- 3 files changed, 16 insertions(+), 10 deletions(-) (limited to 'crates/hir_ty/src/infer') diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index 796487d02..53d94fd0d 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs @@ -15,7 +15,7 @@ use stdx::always; use syntax::ast::RangeOp; use crate::{ - autoderef, + autoderef, dummy_usize_const, lower::lower_to_chalk_mutability, method_resolution, op, primitive::{self, UintTy}, @@ -702,7 +702,7 @@ impl<'a> InferenceContext<'a> { } Expr::Array(array) => { let elem_ty = match expected.ty.kind(&Interner) { - TyKind::Array(st) | TyKind::Slice(st) => st.clone(), + TyKind::Array(st, _) | TyKind::Slice(st) => st.clone(), _ => self.table.new_type_var(), }; @@ -726,7 +726,7 @@ impl<'a> InferenceContext<'a> { } } - TyKind::Array(elem_ty).intern(&Interner) + TyKind::Array(elem_ty, dummy_usize_const()).intern(&Interner) } Expr::Literal(lit) => match lit { Literal::Bool(..) => TyKind::Scalar(Scalar::Bool).intern(&Interner), @@ -736,7 +736,8 @@ impl<'a> InferenceContext<'a> { } Literal::ByteString(..) => { let byte_type = TyKind::Scalar(Scalar::Uint(UintTy::U8)).intern(&Interner); - let array_type = TyKind::Array(byte_type).intern(&Interner); + let array_type = + TyKind::Array(byte_type, dummy_usize_const()).intern(&Interner); TyKind::Ref(Mutability::Not, static_lifetime(), array_type).intern(&Interner) } 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..c1d7a6b76 100644 --- a/crates/hir_ty/src/infer/pat.rs +++ b/crates/hir_ty/src/infer/pat.rs @@ -214,17 +214,20 @@ impl<'a> InferenceContext<'a> { return inner_ty; } Pat::Slice { prefix, slice, suffix } => { - let (container_ty, elem_ty): (fn(_) -> _, _) = match expected.kind(&Interner) { - TyKind::Array(st) => (TyKind::Array, st.clone()), - TyKind::Slice(st) => (TyKind::Slice, st.clone()), - _ => (TyKind::Slice, self.err_ty()), + let elem_ty = match expected.kind(&Interner) { + TyKind::Array(st, _) | TyKind::Slice(st) => st.clone(), + _ => self.err_ty(), }; for pat_id in prefix.iter().chain(suffix) { self.infer_pat(*pat_id, &elem_ty, default_bm); } - let pat_ty = container_ty(elem_ty).intern(&Interner); + let pat_ty = match expected.kind(&Interner) { + TyKind::Array(_, const_) => TyKind::Array(elem_ty, const_.clone()), + _ => TyKind::Slice(elem_ty), + } + .intern(&Interner); if let Some(slice_pat_id) = slice { self.infer_pat(*slice_pat_id, &pat_ty, default_bm); } 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 { | (TyKind::Closure(.., substs1), TyKind::Closure(.., substs2)) => { self.unify_substs(substs1, substs2, depth + 1) } + (TyKind::Array(ty1, c1), TyKind::Array(ty2, c2)) if c1 == c2 => { + self.unify_inner(ty1, ty2, depth + 1) + } (TyKind::Ref(_, _, ty1), TyKind::Ref(_, _, ty2)) | (TyKind::Raw(_, ty1), TyKind::Raw(_, ty2)) - | (TyKind::Array(ty1), TyKind::Array(ty2)) | (TyKind::Slice(ty1), TyKind::Slice(ty2)) => self.unify_inner(ty1, ty2, depth + 1), _ => true, /* we checked equals_ctor already */ } -- cgit v1.2.3