diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2015-05-29 09:57:36 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2015-05-29 11:52:59 -0400 |
| commit | 808b4112444932f97b997ea0c9baedf4c5edb7c5 (patch) | |
| tree | 2bc4c4a854c003a2d64c1f5ebf91dedcf2a21041 | |
| parent | 2c5e784d6f39965e78bc5fa54fe042ecc944e671 (diff) | |
| download | rust-808b4112444932f97b997ea0c9baedf4c5edb7c5.tar.gz rust-808b4112444932f97b997ea0c9baedf4c5edb7c5.zip | |
New tests for cross-crate usages of const fn and so forth
| -rw-r--r-- | src/test/auxiliary/const_fn_lib.rs | 16 | ||||
| -rw-r--r-- | src/test/compile-fail/const-fn-stability-calls-2.rs | 21 | ||||
| -rw-r--r-- | src/test/compile-fail/const-fn-stability-calls-3.rs | 25 | ||||
| -rw-r--r-- | src/test/compile-fail/const-fn-stability-calls.rs | 34 | ||||
| -rw-r--r-- | src/test/compile-fail/const-fn-stability.rs | 10 | ||||
| -rw-r--r-- | src/test/run-pass/const-fn-cross-crate.rs | 25 |
6 files changed, 131 insertions, 0 deletions
diff --git a/src/test/auxiliary/const_fn_lib.rs b/src/test/auxiliary/const_fn_lib.rs new file mode 100644 index 00000000000..b0d5a6b1272 --- /dev/null +++ b/src/test/auxiliary/const_fn_lib.rs @@ -0,0 +1,16 @@ +// Copyright 2015 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. + +// Crate that exports a const fn. Used for testing cross-crate. + +#![crate_type="rlib"] +#![feature(const_fn)] + +pub const fn foo() -> usize { 22 } //~ ERROR const fn is unstable diff --git a/src/test/compile-fail/const-fn-stability-calls-2.rs b/src/test/compile-fail/const-fn-stability-calls-2.rs new file mode 100644 index 00000000000..dd9a415311e --- /dev/null +++ b/src/test/compile-fail/const-fn-stability-calls-2.rs @@ -0,0 +1,21 @@ +// Copyright 2015 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. + +// Test use of const fn from another crate without a feature gate. + +// aux-build:const_fn_lib.rs + +extern crate const_fn_lib; + +use const_fn_lib::foo; + +fn main() { + let x: [usize; foo()] = []; //~ ERROR unsupported constant expr +} diff --git a/src/test/compile-fail/const-fn-stability-calls-3.rs b/src/test/compile-fail/const-fn-stability-calls-3.rs new file mode 100644 index 00000000000..0f413b0bbc1 --- /dev/null +++ b/src/test/compile-fail/const-fn-stability-calls-3.rs @@ -0,0 +1,25 @@ +// Copyright 2015 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. + +// Test use of const fn from another crate without a feature gate. + +#![feature(rustc_attrs)] +#![allow(unused_variables)] + +// aux-build:const_fn_lib.rs + +extern crate const_fn_lib; + +use const_fn_lib::foo; + +#[rustc_error] +fn main() { //~ ERROR compilation successful + let x = foo(); // use outside a constant is ok +} diff --git a/src/test/compile-fail/const-fn-stability-calls.rs b/src/test/compile-fail/const-fn-stability-calls.rs new file mode 100644 index 00000000000..609077663ef --- /dev/null +++ b/src/test/compile-fail/const-fn-stability-calls.rs @@ -0,0 +1,34 @@ +// Copyright 2015 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. + +// Test use of const fn from another crate without a feature gate. + +// aux-build:const_fn_lib.rs + +extern crate const_fn_lib; + +use const_fn_lib::foo; + +static FOO: usize = foo(); //~ ERROR const fns are an unstable feature +const BAR: usize = foo(); //~ ERROR const fns are an unstable feature + +macro_rules! constant { + ($n:ident: $t:ty = $v:expr) => { + const $n: $t = $v; + } +} + +constant! { + BAZ: usize = foo() //~ ERROR const fns are an unstable feature +} + +fn main() { +// let x: [usize; foo()] = []; +} diff --git a/src/test/compile-fail/const-fn-stability.rs b/src/test/compile-fail/const-fn-stability.rs index fda2930c4a9..9913c2fa12c 100644 --- a/src/test/compile-fail/const-fn-stability.rs +++ b/src/test/compile-fail/const-fn-stability.rs @@ -28,6 +28,16 @@ impl Foo for u32 { static FOO: usize = foo(); const BAR: usize = foo(); +macro_rules! constant { + ($n:ident: $t:ty = $v:expr) => { + const $n: $t = $v; + } +} + +constant! { + BAZ: usize = foo() +} + fn main() { let x: [usize; foo()] = []; } diff --git a/src/test/run-pass/const-fn-cross-crate.rs b/src/test/run-pass/const-fn-cross-crate.rs new file mode 100644 index 00000000000..5d0c17af717 --- /dev/null +++ b/src/test/run-pass/const-fn-cross-crate.rs @@ -0,0 +1,25 @@ +// Copyright 2015 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. + +// aux-build:const_fn_lib.rs + +// A very basic test of const fn functionality. + +#![feature(const_fn)] + +extern crate const_fn_lib; + +use const_fn_lib::foo; + +const FOO: usize = foo(); + +fn main() { + assert_eq!(FOO, 22); +} |
