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 or the MIT license +// , 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 or the MIT license +// , 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 or the MIT license +// , 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 or the MIT license +// , 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]; + +}