diff options
author | Lenard Pratt <[email protected]> | 2019-04-03 23:23:58 +0100 |
---|---|---|
committer | Lenard Pratt <[email protected]> | 2019-04-07 13:23:12 +0100 |
commit | 2d73c909fe03c799b488aa0f97a588e13bbd7006 (patch) | |
tree | b96bf7ccc6cc6e0ebb86e52ffad104f44f53d556 /crates/ra_hir/src/ty/infer.rs | |
parent | 36f5d997565b6390a4b524e7e1d0d805f0f26bdb (diff) |
Added inference of array length
Diffstat (limited to 'crates/ra_hir/src/ty/infer.rs')
-rw-r--r-- | crates/ra_hir/src/ty/infer.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 887153484..d8f4ce9f8 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs | |||
@@ -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 } => { | 1077 | Expr::Array { exprs, repeat } => { |
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 => { |
@@ -1089,6 +1089,15 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1089 | self.infer_expr(*expr, &Expectation::has_type(elem_ty.clone())); | 1089 | self.infer_expr(*expr, &Expectation::has_type(elem_ty.clone())); |
1090 | } | 1090 | } |
1091 | 1091 | ||
1092 | if let Some(expr) = repeat { | ||
1093 | self.infer_expr( | ||
1094 | *expr, | ||
1095 | &Expectation::has_type(Ty::simple(TypeCtor::Int( | ||
1096 | primitive::UncertainIntTy::Known(primitive::IntTy::usize()), | ||
1097 | ))), | ||
1098 | ); | ||
1099 | } | ||
1100 | |||
1092 | Ty::apply_one(TypeCtor::Array, elem_ty) | 1101 | Ty::apply_one(TypeCtor::Array, elem_ty) |
1093 | } | 1102 | } |
1094 | Expr::Literal(lit) => match lit { | 1103 | Expr::Literal(lit) => match lit { |