Skip to content

Commit 7dfa3d1

Browse files
committed
librustc: Typeck & record the count expr in TyFixedLengthVec.
1 parent 4461f03 commit 7dfa3d1

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/librustc/middle/typeck/astconv.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,7 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:RegionScope>(
877877
}
878878
}
879879
ast::TyFixedLengthVec(ty, e) => {
880+
typeck::write_ty_to_tcx(tcx, e.id, ty::mk_uint());
880881
match const_eval::eval_const_expr_partial(tcx, &*e) {
881882
Ok(ref r) => {
882883
match *r {

src/librustc/middle/typeck/check/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,18 @@ impl<'a> Visitor<()> for GatherLocalsVisitor<'a> {
429429
self.fcx.with_region_lb(b.id, || visit::walk_block(self, b, ()));
430430
}
431431

432+
// Since an expr occurs as part of the type fixed size arrays we
433+
// need to record the type for that node
434+
fn visit_ty(&mut self, t: &ast::Ty, _: ()) {
435+
match t.node {
436+
ast::TyFixedLengthVec(ref ty, ref count_expr) => {
437+
self.visit_ty(&**ty, ());
438+
check_expr_with_hint(self.fcx, &**count_expr, ty::mk_uint());
439+
}
440+
_ => visit::walk_ty(self, t, ())
441+
}
442+
}
443+
432444
// Don't descend into fns and items
433445
fn visit_fn(&mut self, _: &visit::FnKind, _: &ast::FnDecl,
434446
_: &ast::Block, _: Span, _: ast::NodeId, _: ()) { }
@@ -3353,6 +3365,12 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
33533365
}
33543366
}
33553367
ast::ExprCast(ref e, ref t) => {
3368+
match t.node {
3369+
ast::TyFixedLengthVec(_, ref count_expr) => {
3370+
check_expr_with_hint(fcx, &**count_expr, ty::mk_uint());
3371+
}
3372+
_ => {}
3373+
}
33563374
check_cast(fcx, &**e, &**t, id, expr.span);
33573375
}
33583376
ast::ExprVec(ref args) => {

src/librustc/middle/typeck/check/writeback.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,14 @@ impl<'cx> Visitor<()> for WritebackCx<'cx> {
181181
visit::walk_local(self, l, ());
182182
}
183183

184-
fn visit_ty(&mut self, _t: &ast::Ty, _: ()) {
185-
// ignore
184+
fn visit_ty(&mut self, t: &ast::Ty, _: ()) {
185+
match t.node {
186+
ast::TyFixedLengthVec(ref ty, ref count_expr) => {
187+
self.visit_ty(&**ty, ());
188+
write_ty_to_tcx(self.tcx(), count_expr.id, ty::mk_uint());
189+
}
190+
_ => visit::walk_ty(self, t, ())
191+
}
186192
}
187193
}
188194

0 commit comments

Comments
 (0)