Skip to content

Commit 6e5705a

Browse files
committed
auto merge of #5072 : youknowone/rust/repeat_count, r=brson
Fix issue #3645
2 parents 08d870e + f0d0b5c commit 6e5705a

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/librustc/middle/ty.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4290,7 +4290,8 @@ pub fn eval_repeat_count(tcx: ctxt,
42904290
count_expr: @ast::expr,
42914291
span: span)
42924292
-> uint {
4293-
match const_eval::eval_const_expr(tcx, count_expr) {
4293+
match const_eval::eval_const_expr_partial(tcx, count_expr) {
4294+
Ok(ref const_val) => match *const_val {
42944295
const_eval::const_int(count) => return count as uint,
42954296
const_eval::const_uint(count) => return count as uint,
42964297
const_eval::const_float(count) => {
@@ -4311,7 +4312,13 @@ pub fn eval_repeat_count(tcx: ctxt,
43114312
repeat count but found boolean");
43124313
return 0;
43134314
}
4314-
4315+
},
4316+
Err(*) => {
4317+
tcx.sess.span_err(span,
4318+
~"expected constant integer for repeat count \
4319+
but found variable");
4320+
return 0;
4321+
}
43154322
}
43164323
}
43174324

src/test/compile-fail/repeat_count.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Regression test for issue #3645
12+
13+
fn main() {
14+
let n = 1;
15+
let a = ~[0, ..n]; //~ ERROR expected constant integer for repeat count but found variable
16+
}

0 commit comments

Comments
 (0)