From e175921932615cb97eaa5cfd11d940cbd1473cac Mon Sep 17 00:00:00 2001 From: Lenard Pratt Date: Thu, 4 Apr 2019 23:29:21 +0100 Subject: Added ArrayExprKind, changed the display for fixed array types, Added Array Enum to ra_hir/expr --- crates/ra_hir/src/ty/infer.rs | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'crates/ra_hir/src/ty') diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index d8f4ce9f8..9ace6b13a 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -32,7 +32,7 @@ use crate::{ DefWithBody, ImplItem, type_ref::{TypeRef, Mutability}, - expr::{Body, Expr, BindingAnnotation, Literal, ExprId, Pat, PatId, UnaryOp, BinaryOp, Statement, FieldPat, self}, + expr::{Body, Expr, BindingAnnotation, Literal, ExprId, Pat, PatId, UnaryOp, BinaryOp, Statement, FieldPat,Array, self}, generics::GenericParams, path::{GenericArgs, GenericArg}, adt::VariantDef, @@ -1074,7 +1074,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { Ty::apply(TypeCtor::Tuple, Substs(ty_vec.into())) } - Expr::Array { exprs, repeat } => { + Expr::Array(array) => { let elem_ty = match &expected.ty { Ty::Apply(a_ty) => match a_ty.ctor { TypeCtor::Slice | TypeCtor::Array => { @@ -1085,17 +1085,21 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { _ => self.new_type_var(), }; - for expr in exprs.iter() { - self.infer_expr(*expr, &Expectation::has_type(elem_ty.clone())); - } - - if let Some(expr) = repeat { - self.infer_expr( - *expr, - &Expectation::has_type(Ty::simple(TypeCtor::Int( - primitive::UncertainIntTy::Known(primitive::IntTy::usize()), - ))), - ); + match array { + Array::ElementList(items) => { + for expr in items.iter() { + self.infer_expr(*expr, &Expectation::has_type(elem_ty.clone())); + } + } + Array::Repeat { initializer, repeat } => { + self.infer_expr(*initializer, &Expectation::has_type(elem_ty.clone())); + self.infer_expr( + *repeat, + &Expectation::has_type(Ty::simple(TypeCtor::Int( + primitive::UncertainIntTy::Known(primitive::IntTy::usize()), + ))), + ); + } } Ty::apply_one(TypeCtor::Array, elem_ty) -- cgit v1.2.3