Report error for non constant vector repeat count

Fix issue #3645
This commit is contained in:
Jeong YunWon 2013-02-21 22:48:05 +09:00
parent f9f942bb14
commit f0d0b5c116
2 changed files with 25 additions and 2 deletions

View File

@ -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;
}
}
}

View File

@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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
}