diff options
| author | Luqman Aden <me@luqman.ca> | 2013-03-06 13:34:44 -0800 |
|---|---|---|
| committer | Luqman Aden <me@luqman.ca> | 2013-03-18 17:31:42 -0700 |
| commit | d7d17dc14e653332848f7f6f994b34eb7fc923ec (patch) | |
| tree | 30290aecec90bcffd91a5d905256cd755e583bbe | |
| parent | da64994f18cbeae9f0fd1527fa46347a0bcea7c5 (diff) | |
| download | rust-d7d17dc14e653332848f7f6f994b34eb7fc923ec.tar.gz rust-d7d17dc14e653332848f7f6f994b34eb7fc923ec.zip | |
Add tests for const exprs in fixed vec length type and vec repeat.
4 files changed, 71 insertions, 0 deletions
diff --git a/src/test/compile-fail/non-constant-expr-for-fixed-len-vec.rs b/src/test/compile-fail/non-constant-expr-for-fixed-len-vec.rs new file mode 100644 index 00000000000..86262008ff9 --- /dev/null +++ b/src/test/compile-fail/non-constant-expr-for-fixed-len-vec.rs @@ -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 + } +} diff --git a/src/test/compile-fail/non-constant-expr-for-vec-repeat.rs b/src/test/compile-fail/non-constant-expr-for-vec-repeat.rs new file mode 100644 index 00000000000..2727db9d042 --- /dev/null +++ b/src/test/compile-fail/non-constant-expr-for-vec-repeat.rs @@ -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 + } +} diff --git a/src/test/run-pass/const-expr-in-fixed-length-vec.rs b/src/test/run-pass/const-expr-in-fixed-length-vec.rs new file mode 100644 index 00000000000..aa5c4cbbc1d --- /dev/null +++ b/src/test/run-pass/const-expr-in-fixed-length-vec.rs @@ -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]; + +} diff --git a/src/test/run-pass/const-expr-in-vec-repeat.rs b/src/test/run-pass/const-expr-in-vec-repeat.rs new file mode 100644 index 00000000000..76952ef730f --- /dev/null +++ b/src/test/run-pass/const-expr-in-vec-repeat.rs @@ -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]; + +} |
