aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/expr.rs49
-rw-r--r--crates/ra_hir/src/ty.rs2
-rw-r--r--crates/ra_hir/src/ty/infer.rs30
3 files changed, 52 insertions, 29 deletions
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs
index 3e6578651..589a9b2db 100644
--- a/crates/ra_hir/src/expr.rs
+++ b/crates/ra_hir/src/expr.rs
@@ -6,7 +6,7 @@ use rustc_hash::FxHashMap;
6use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap}; 6use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap};
7use ra_syntax::{ 7use ra_syntax::{
8 SyntaxNodePtr, AstPtr, AstNode, 8 SyntaxNodePtr, AstPtr, AstNode,
9 ast::{self, LoopBodyOwner, ArgListOwner, NameOwner, LiteralKind, TypeAscriptionOwner} 9 ast::{self, LoopBodyOwner, ArgListOwner, NameOwner, LiteralKind,ArrayExprKind, TypeAscriptionOwner}
10}; 10};
11 11
12use crate::{ 12use crate::{
@@ -238,15 +238,17 @@ pub enum Expr {
238 Tuple { 238 Tuple {
239 exprs: Vec<ExprId>, 239 exprs: Vec<ExprId>,
240 }, 240 },
241 Array { 241 Array(Array),
242 exprs: Vec<ExprId>,
243 repeat: Option<ExprId>,
244 },
245 Literal(Literal), 242 Literal(Literal),
246} 243}
247 244
248pub use ra_syntax::ast::PrefixOp as UnaryOp; 245pub use ra_syntax::ast::PrefixOp as UnaryOp;
249pub use ra_syntax::ast::BinOp as BinaryOp; 246pub use ra_syntax::ast::BinOp as BinaryOp;
247#[derive(Debug, Clone, Eq, PartialEq)]
248pub enum Array {
249 ElementList(Vec<ExprId>),
250 Repeat { initializer: ExprId, repeat: ExprId },
251}
250 252
251#[derive(Debug, Clone, Eq, PartialEq)] 253#[derive(Debug, Clone, Eq, PartialEq)]
252pub struct MatchArm { 254pub struct MatchArm {
@@ -354,15 +356,17 @@ impl Expr {
354 f(*expr); 356 f(*expr);
355 } 357 }
356 } 358 }
357 Expr::Array { exprs, repeat } => { 359 Expr::Array(a) => match a {
358 for expr in exprs { 360 Array::ElementList(exprs) => {
359 f(*expr); 361 for expr in exprs {
362 f(*expr);
363 }
360 } 364 }
361 365 Array::Repeat { initializer, repeat } => {
362 if let Some(expr) = repeat { 366 f(*initializer);
363 f(*expr) 367 f(*repeat)
364 } 368 }
365 } 369 },
366 Expr::Literal(_) => {} 370 Expr::Literal(_) => {}
367 } 371 }
368 } 372 }
@@ -733,11 +737,26 @@ impl ExprCollector {
733 let exprs = e.exprs().map(|expr| self.collect_expr(expr)).collect(); 737 let exprs = e.exprs().map(|expr| self.collect_expr(expr)).collect();
734 self.alloc_expr(Expr::Tuple { exprs }, syntax_ptr) 738 self.alloc_expr(Expr::Tuple { exprs }, syntax_ptr)
735 } 739 }
740
736 ast::ExprKind::ArrayExpr(e) => { 741 ast::ExprKind::ArrayExpr(e) => {
737 let exprs = e.exprs().map(|expr| self.collect_expr(expr)).collect(); 742 let kind = e.kind();
738 let repeat = e.repeat().map(|e| self.collect_expr(e)); 743
739 self.alloc_expr(Expr::Array { exprs, repeat }, syntax_ptr) 744 match kind {
745 ArrayExprKind::ElementList(e) => {
746 let exprs = e.map(|expr| self.collect_expr(expr)).collect();
747 self.alloc_expr(Expr::Array(Array::ElementList(exprs)), syntax_ptr)
748 }
749 ArrayExprKind::Repeat { initializer, repeat } => {
750 let initializer = self.collect_expr_opt(initializer);
751 let repeat = self.collect_expr_opt(repeat);
752 self.alloc_expr(
753 Expr::Array(Array::Repeat { initializer, repeat }),
754 syntax_ptr,
755 )
756 }
757 }
740 } 758 }
759
741 ast::ExprKind::Literal(e) => { 760 ast::ExprKind::Literal(e) => {
742 let lit = match e.kind() { 761 let lit = match e.kind() {
743 LiteralKind::IntNumber { suffix } => { 762 LiteralKind::IntNumber { suffix } => {
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index 77690309a..20e55d92d 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -359,7 +359,7 @@ impl HirDisplay for ApplicationTy {
359 } 359 }
360 TypeCtor::Array => { 360 TypeCtor::Array => {
361 let t = self.parameters.as_single(); 361 let t = self.parameters.as_single();
362 write!(f, "[{};usize]", t.display(f.db))?; 362 write!(f, "[{};_]", t.display(f.db))?;
363 } 363 }
364 TypeCtor::RawPtr(m) => { 364 TypeCtor::RawPtr(m) => {
365 let t = self.parameters.as_single(); 365 let t = self.parameters.as_single();
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::{
32 DefWithBody, 32 DefWithBody,
33 ImplItem, 33 ImplItem,
34 type_ref::{TypeRef, Mutability}, 34 type_ref::{TypeRef, Mutability},
35 expr::{Body, Expr, BindingAnnotation, Literal, ExprId, Pat, PatId, UnaryOp, BinaryOp, Statement, FieldPat, self}, 35 expr::{Body, Expr, BindingAnnotation, Literal, ExprId, Pat, PatId, UnaryOp, BinaryOp, Statement, FieldPat,Array, self},
36 generics::GenericParams, 36 generics::GenericParams,
37 path::{GenericArgs, GenericArg}, 37 path::{GenericArgs, GenericArg},
38 adt::VariantDef, 38 adt::VariantDef,
@@ -1074,7 +1074,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1074 1074
1075 Ty::apply(TypeCtor::Tuple, Substs(ty_vec.into())) 1075 Ty::apply(TypeCtor::Tuple, Substs(ty_vec.into()))
1076 } 1076 }
1077 Expr::Array { exprs, repeat } => { 1077 Expr::Array(array) => {
1078 let elem_ty = match &expected.ty { 1078 let elem_ty = match &expected.ty {
1079 Ty::Apply(a_ty) => match a_ty.ctor { 1079 Ty::Apply(a_ty) => match a_ty.ctor {
1080 TypeCtor::Slice | TypeCtor::Array => { 1080 TypeCtor::Slice | TypeCtor::Array => {
@@ -1085,17 +1085,21 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1085 _ => self.new_type_var(), 1085 _ => self.new_type_var(),
1086 }; 1086 };
1087 1087
1088 for expr in exprs.iter() { 1088 match array {
1089 self.infer_expr(*expr, &Expectation::has_type(elem_ty.clone())); 1089 Array::ElementList(items) => {
1090 } 1090 for expr in items.iter() {
1091 1091 self.infer_expr(*expr, &Expectation::has_type(elem_ty.clone()));
1092 if let Some(expr) = repeat { 1092 }
1093 self.infer_expr( 1093 }
1094 *expr, 1094 Array::Repeat { initializer, repeat } => {
1095 &Expectation::has_type(Ty::simple(TypeCtor::Int( 1095 self.infer_expr(*initializer, &Expectation::has_type(elem_ty.clone()));
1096 primitive::UncertainIntTy::Known(primitive::IntTy::usize()), 1096 self.infer_expr(
1097 ))), 1097 *repeat,
1098 ); 1098 &Expectation::has_type(Ty::simple(TypeCtor::Int(
1099 primitive::UncertainIntTy::Known(primitive::IntTy::usize()),
1100 ))),
1101 );
1102 }
1099 } 1103 }
1100 1104
1101 Ty::apply_one(TypeCtor::Array, elem_ty) 1105 Ty::apply_one(TypeCtor::Array, elem_ty)