Skip to content

Commit

Permalink
auto merge of #6985 : Aatch/rust/fixed-vec-6977, r=thestinger
Browse files Browse the repository at this point in the history
This fixes #6977. Negative counts don't make sense anyway.
  • Loading branch information
bors committed Jun 7, 2013
2 parents 74d9de7 + de27064 commit 4abd83b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4316,23 +4316,30 @@ pub fn normalize_ty(cx: ctxt, t: t) -> t {
pub fn eval_repeat_count(tcx: ctxt, count_expr: @ast::expr) -> uint {
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_int(count) => if count < 0 {
tcx.sess.span_err(count_expr.span,
"expected positive integer for \
repeat count but found negative integer");
return 0;
} else {
return count as uint
},
const_eval::const_uint(count) => return count as uint,
const_eval::const_float(count) => {
tcx.sess.span_err(count_expr.span,
"expected signed or unsigned integer for \
"expected positive integer for \
repeat count but found float");
return count as uint;
}
const_eval::const_str(_) => {
tcx.sess.span_err(count_expr.span,
"expected signed or unsigned integer for \
"expected positive integer for \
repeat count but found string");
return 0;
}
const_eval::const_bool(_) => {
tcx.sess.span_err(count_expr.span,
"expected signed or unsigned integer for \
"expected positive integer for \
repeat count but found boolean");
return 0;
}
Expand Down
7 changes: 7 additions & 0 deletions src/test/compile-fail/issue-6977.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//xfail-test

// Trying to create a fixed-length vector with a negative size

fn main() {
let _x = [0,..-1];
}

0 comments on commit 4abd83b

Please sign in to comment.