about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-02-25 16:18:46 -0800
committerbors <bors@rust-lang.org>2013-02-25 16:18:46 -0800
commit6e5705a87743503232ec927efebd00861f1ce717 (patch)
tree10a89e8ac91c7171fc7798c8c2278680d389b391
parent08d870e566b04fcc672c8a35996b40ce9e22ed06 (diff)
parentf0d0b5c116eb464544bd48cec116c1ec8908d04d (diff)
downloadrust-6e5705a87743503232ec927efebd00861f1ce717.tar.gz
rust-6e5705a87743503232ec927efebd00861f1ce717.zip
auto merge of #5072 : youknowone/rust/repeat_count, r=brson
Fix issue #3645
-rw-r--r--src/librustc/middle/ty.rs11
-rw-r--r--src/test/compile-fail/repeat_count.rs16
2 files changed, 25 insertions, 2 deletions
diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs
index 2fa397e9196..dafc3b6718e 100644
--- a/src/librustc/middle/ty.rs
+++ b/src/librustc/middle/ty.rs
@@ -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;
+      }
     }
 }
 
diff --git a/src/test/compile-fail/repeat_count.rs b/src/test/compile-fail/repeat_count.rs
new file mode 100644
index 00000000000..579575e2008
--- /dev/null
+++ b/src/test/compile-fail/repeat_count.rs
@@ -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
+}