auto merge of #5072 : youknowone/rust/repeat_count, r=brson

Fix issue #3645
This commit is contained in:
bors 2013-02-25 16:18:46 -08:00
commit 6e5705a877
2 changed files with 25 additions and 2 deletions

View File

@ -4290,7 +4290,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) => {
@ -4311,7 +4312,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
}