From f0d0b5c116eb464544bd48cec116c1ec8908d04d Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Thu, 21 Feb 2013 22:48:05 +0900 Subject: [PATCH] Report error for non constant vector repeat count Fix issue #3645 --- src/librustc/middle/ty.rs | 11 +++++++++-- src/test/compile-fail/repeat_count.rs | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/test/compile-fail/repeat_count.rs diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 239e86623ca..298c2c95f46 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -4289,7 +4289,8 @@ pub fn eval_repeat_count(tcx: ctxt, count_expr: @ast::expr, span: span) -> uint { - match const_eval::eval_const_expr(tcx, count_expr) { + match const_eval::eval_const_expr_partial(tcx, count_expr) { + Ok(ref const_val) => match *const_val { const_eval::const_int(count) => return count as uint, const_eval::const_uint(count) => return count as uint, const_eval::const_float(count) => { @@ -4310,7 +4311,13 @@ pub fn eval_repeat_count(tcx: ctxt, repeat count but found boolean"); return 0; } - + }, + Err(*) => { + tcx.sess.span_err(span, + ~"expected constant integer for repeat count \ + but found variable"); + return 0; + } } } diff --git a/src/test/compile-fail/repeat_count.rs b/src/test/compile-fail/repeat_count.rs new file mode 100644 index 00000000000..579575e2008 --- /dev/null +++ b/src/test/compile-fail/repeat_count.rs @@ -0,0 +1,16 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Regression test for issue #3645 + +fn main() { + let n = 1; + let a = ~[0, ..n]; //~ ERROR expected constant integer for repeat count but found variable +}