Skip to content

Commit 2d73c90

Browse files
committed
Added inference of array length
1 parent 36f5d99 commit 2d73c90

File tree

6 files changed

+62
-5
lines changed

6 files changed

+62
-5
lines changed

crates/ra_hir/src/expr.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ pub enum Expr {
240240
},
241241
Array {
242242
exprs: Vec<ExprId>,
243+
repeat: Option<ExprId>,
243244
},
244245
Literal(Literal),
245246
}
@@ -348,11 +349,20 @@ impl Expr {
348349
| Expr::UnaryOp { expr, .. } => {
349350
f(*expr);
350351
}
351-
Expr::Tuple { exprs } | Expr::Array { exprs } => {
352+
Expr::Tuple { exprs } => {
352353
for expr in exprs {
353354
f(*expr);
354355
}
355356
}
357+
Expr::Array { exprs, repeat } => {
358+
for expr in exprs {
359+
f(*expr);
360+
}
361+
362+
if let Some(expr) = repeat {
363+
f(*expr)
364+
}
365+
}
356366
Expr::Literal(_) => {}
357367
}
358368
}
@@ -725,7 +735,8 @@ impl ExprCollector {
725735
}
726736
ast::ExprKind::ArrayExpr(e) => {
727737
let exprs = e.exprs().map(|expr| self.collect_expr(expr)).collect();
728-
self.alloc_expr(Expr::Array { exprs }, syntax_ptr)
738+
let repeat = e.repeat().map(|e| self.collect_expr(e));
739+
self.alloc_expr(Expr::Array { exprs, repeat }, syntax_ptr)
729740
}
730741
ast::ExprKind::Literal(e) => {
731742
let lit = match e.kind() {

crates/ra_hir/src/ty.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,14 @@ impl HirDisplay for ApplicationTy {
353353
TypeCtor::Int(t) => write!(f, "{}", t)?,
354354
TypeCtor::Float(t) => write!(f, "{}", t)?,
355355
TypeCtor::Str => write!(f, "str")?,
356-
TypeCtor::Slice | TypeCtor::Array => {
356+
TypeCtor::Slice => {
357357
let t = self.parameters.as_single();
358358
write!(f, "[{}]", t.display(f.db))?;
359359
}
360+
TypeCtor::Array => {
361+
let t = self.parameters.as_single();
362+
write!(f, "[{};usize]", t.display(f.db))?;
363+
}
360364
TypeCtor::RawPtr(m) => {
361365
let t = self.parameters.as_single();
362366
write!(f, "*{}{}", m.as_keyword_for_ptr(), t.display(f.db))?;

0 commit comments

Comments
 (0)