Skip to content

Commit

Permalink
Report error for non constant vector repeat count
Browse files Browse the repository at this point in the history
Fix issue #3645
  • Loading branch information
youknowone committed Feb 24, 2013
1 parent f9f942b commit f0d0b5c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/librustc/middle/ty.rs
Expand Up @@ -4289,7 +4289,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) => {
Expand All @@ -4310,7 +4311,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;
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions 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
}

5 comments on commit f0d0b5c

@bors
Copy link
Contributor

@bors bors commented on f0d0b5c Feb 26, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from brson
at youknowone@f0d0b5c

@bors
Copy link
Contributor

@bors bors commented on f0d0b5c Feb 26, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging youknowone/rust/repeat_count = f0d0b5c into auto

@bors
Copy link
Contributor

@bors bors commented on f0d0b5c Feb 26, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

youknowone/rust/repeat_count = f0d0b5c merged ok, testing candidate = 6e5705a

@bors
Copy link
Contributor

@bors bors commented on f0d0b5c Feb 26, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on f0d0b5c Feb 26, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding incoming to auto = 6e5705a

Please sign in to comment.