diff options
| author | bors <bors@rust-lang.org> | 2013-06-06 20:34:32 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-06-06 20:34:32 -0700 |
| commit | 4abd83b18d5dffc8c2f3d827c333447c028998a0 (patch) | |
| tree | 897223458ed3a38377b11c0c71c6682ee7ceade3 | |
| parent | 74d9de7abdceb2cb11a5e8a79eaec6ea2c70ea35 (diff) | |
| parent | de27064d84e684926184ff680115d487d742f36a (diff) | |
| download | rust-4abd83b18d5dffc8c2f3d827c333447c028998a0.tar.gz rust-4abd83b18d5dffc8c2f3d827c333447c028998a0.zip | |
auto merge of #6985 : Aatch/rust/fixed-vec-6977, r=thestinger
This fixes #6977. Negative counts don't make sense anyway.
| -rw-r--r-- | src/librustc/middle/ty.rs | 15 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-6977.rs | 7 |
2 files changed, 18 insertions, 4 deletions
diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 597063d8fc3..8e2691c8a27 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -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; } diff --git a/src/test/compile-fail/issue-6977.rs b/src/test/compile-fail/issue-6977.rs new file mode 100644 index 00000000000..bfaa148ea6c --- /dev/null +++ b/src/test/compile-fail/issue-6977.rs @@ -0,0 +1,7 @@ +//xfail-test + +// Trying to create a fixed-length vector with a negative size + +fn main() { + let _x = [0,..-1]; +} |
