Add tests for const exprs in fixed vec length type and vec repeat.

This commit is contained in:
Luqman Aden 2013-03-06 13:34:44 -08:00
parent da64994f18
commit d7d17dc14e
4 changed files with 71 additions and 0 deletions

View File

@ -0,0 +1,17 @@
// Copyright 2012-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.
// Check that non-constant exprs do fail as count in fixed length vec type
fn main() {
fn bar(n: int) {
let _x: [int * n]; //~ ERROR expected constant expr for vector length: Non-constant path in constant expr
}
}

View File

@ -0,0 +1,17 @@
// Copyright 2012-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.
// Check that non constant exprs fail for vector repeat syntax
fn main() {
fn bar(n: int) {
let _x = [0, ..n]; //~ ERROR expected constant integer for repeat count but found variable
}
}

View File

@ -0,0 +1,19 @@
// Copyright 2012-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.
// Check that constant expressions can be used for declaring the
// type of a fixed length vector.
fn main() {
const FOO: int = 2;
let _v: [int * FOO*3];
}

View File

@ -0,0 +1,18 @@
// Copyright 2012-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.
// Check that constant expressions can be used in vec repeat syntax.
fn main() {
const FOO: int = 2;
let _v = [0, ..FOO*3*2/2];
}