Skip to content

Commit 4abd83b

Browse files
committed
auto merge of #6985 : Aatch/rust/fixed-vec-6977, r=thestinger
This fixes #6977. Negative counts don't make sense anyway.
2 parents 74d9de7 + de27064 commit 4abd83b

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/librustc/middle/ty.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -4316,23 +4316,30 @@ pub fn normalize_ty(cx: ctxt, t: t) -> t {
43164316
pub fn eval_repeat_count(tcx: ctxt, count_expr: @ast::expr) -> uint {
43174317
match const_eval::eval_const_expr_partial(tcx, count_expr) {
43184318
Ok(ref const_val) => match *const_val {
4319-
const_eval::const_int(count) => return count as uint,
4319+
const_eval::const_int(count) => if count < 0 {
4320+
tcx.sess.span_err(count_expr.span,
4321+
"expected positive integer for \
4322+
repeat count but found negative integer");
4323+
return 0;
4324+
} else {
4325+
return count as uint
4326+
},
43204327
const_eval::const_uint(count) => return count as uint,
43214328
const_eval::const_float(count) => {
43224329
tcx.sess.span_err(count_expr.span,
4323-
"expected signed or unsigned integer for \
4330+
"expected positive integer for \
43244331
repeat count but found float");
43254332
return count as uint;
43264333
}
43274334
const_eval::const_str(_) => {
43284335
tcx.sess.span_err(count_expr.span,
4329-
"expected signed or unsigned integer for \
4336+
"expected positive integer for \
43304337
repeat count but found string");
43314338
return 0;
43324339
}
43334340
const_eval::const_bool(_) => {
43344341
tcx.sess.span_err(count_expr.span,
4335-
"expected signed or unsigned integer for \
4342+
"expected positive integer for \
43364343
repeat count but found boolean");
43374344
return 0;
43384345
}

src/test/compile-fail/issue-6977.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//xfail-test
2+
3+
// Trying to create a fixed-length vector with a negative size
4+
5+
fn main() {
6+
let _x = [0,..-1];
7+
}

0 commit comments

Comments
 (0)