about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>2015-10-14 12:30:10 +0200
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>2015-10-19 13:13:02 +0200
commitb4e30bd2a3946c1f0a24ef52a130e0b8fddc00a8 (patch)
tree94912d182f780b4b76030f53ed5c9b7938f73853 /src/test
parent9ed32bba778a38af942775b1a1013149e29dc822 (diff)
downloadrust-b4e30bd2a3946c1f0a24ef52a130e0b8fddc00a8.tar.gz
rust-b4e30bd2a3946c1f0a24ef52a130e0b8fddc00a8.zip
allow constant evaluation of function calls
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/const-eval-span.rs2
-rw-r--r--src/test/compile-fail/const-fn-destructuring-arg.rs18
-rw-r--r--src/test/compile-fail/const-fn-stability-calls-2.rs2
-rw-r--r--src/test/run-pass/const-fn-const-eval.rs19
-rw-r--r--src/test/run-pass/shift-near-oflo.rs43
5 files changed, 59 insertions, 25 deletions
diff --git a/src/test/compile-fail/const-eval-span.rs b/src/test/compile-fail/const-eval-span.rs
index 8e9209916f3..3e75afcda6d 100644
--- a/src/test/compile-fail/const-eval-span.rs
+++ b/src/test/compile-fail/const-eval-span.rs
@@ -14,7 +14,7 @@
 struct S(i32);
 
 const CONSTANT: S = S(0);
-//~^ ERROR: constant evaluation error: unsupported constant expr
+//~^ ERROR: constant evaluation error: non-constant path in constant expression [E0080]
 
 enum E {
     V = CONSTANT,
diff --git a/src/test/compile-fail/const-fn-destructuring-arg.rs b/src/test/compile-fail/const-fn-destructuring-arg.rs
new file mode 100644
index 00000000000..1642c041067
--- /dev/null
+++ b/src/test/compile-fail/const-fn-destructuring-arg.rs
@@ -0,0 +1,18 @@
+// 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 that certain things are disallowed in const fn signatures
+
+#![feature(const_fn)]
+
+// no destructuring
+const fn i((a, b): (u32, u32)) -> u32 { a + b } //~ ERROR: E0022
+
+fn main() {}
diff --git a/src/test/compile-fail/const-fn-stability-calls-2.rs b/src/test/compile-fail/const-fn-stability-calls-2.rs
index dd9a415311e..59e0db7b355 100644
--- a/src/test/compile-fail/const-fn-stability-calls-2.rs
+++ b/src/test/compile-fail/const-fn-stability-calls-2.rs
@@ -17,5 +17,5 @@ extern crate const_fn_lib;
 use const_fn_lib::foo;
 
 fn main() {
-    let x: [usize; foo()] = []; //~ ERROR unsupported constant expr
+    let x: [usize; foo()] = []; //~ ERROR non-constant path in constant expr
 }
diff --git a/src/test/run-pass/const-fn-const-eval.rs b/src/test/run-pass/const-fn-const-eval.rs
new file mode 100644
index 00000000000..77c70fe7f63
--- /dev/null
+++ b/src/test/run-pass/const-fn-const-eval.rs
@@ -0,0 +1,19 @@
+// Copyright 2012-2014 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.
+
+#![feature(const_fn)]
+
+const fn add(x: usize, y: usize) -> usize {
+    x + y
+}
+
+const ARR: [i32; add(1, 2)] = [5, 6, 7];
+
+pub fn main() {}
diff --git a/src/test/run-pass/shift-near-oflo.rs b/src/test/run-pass/shift-near-oflo.rs
index 4ff058f3366..542e8de9e53 100644
--- a/src/test/run-pass/shift-near-oflo.rs
+++ b/src/test/run-pass/shift-near-oflo.rs
@@ -13,9 +13,6 @@
 // Check that we do *not* overflow on a number of edge cases.
 // (compare with test/run-fail/overflowing-{lsh,rsh}*.rs)
 
-// (Work around constant-evaluation)
-fn id<T>(x: T) -> T { x }
-
 fn main() {
     test_left_shift();
     test_right_shift();
@@ -26,34 +23,34 @@ fn test_left_shift() {
 
     macro_rules! tests {
         ($iN:ty, $uN:ty, $max_rhs:expr, $expect_i:expr, $expect_u:expr) => { {
-            let x = (1 as $iN) << id(0);
+            let x = (1 as $iN) << 0;
             assert_eq!(x, 1);
-            let x = (1 as $uN) << id(0);
+            let x = (1 as $uN) << 0;
             assert_eq!(x, 1);
-            let x = (1 as $iN) << id($max_rhs);
+            let x = (1 as $iN) << $max_rhs;
             assert_eq!(x, $expect_i);
-            let x = (1 as $uN) << id($max_rhs);
+            let x = (1 as $uN) << $max_rhs;
             assert_eq!(x, $expect_u);
             // high-order bits on LHS are silently discarded without panic.
-            let x = (3 as $iN) << id($max_rhs);
+            let x = (3 as $iN) << $max_rhs;
             assert_eq!(x, $expect_i);
-            let x = (3 as $uN) << id($max_rhs);
+            let x = (3 as $uN) << $max_rhs;
             assert_eq!(x, $expect_u);
         } }
     }
 
-    let x = 1_i8 << id(0);
+    let x = 1_i8 << 0;
     assert_eq!(x, 1);
-    let x = 1_u8 << id(0);
+    let x = 1_u8 << 0;
     assert_eq!(x, 1);
-    let x = 1_i8 << id(7);
+    let x = 1_i8 << 7;
     assert_eq!(x, std::i8::MIN);
-    let x = 1_u8 << id(7);
+    let x = 1_u8 << 7;
     assert_eq!(x, 0x80);
     // high-order bits on LHS are silently discarded without panic.
-    let x = 3_i8 << id(7);
+    let x = 3_i8 << 7;
     assert_eq!(x, std::i8::MIN);
-    let x = 3_u8 << id(7);
+    let x = 3_u8 << 7;
     assert_eq!(x, 0x80);
 
     // above is (approximately) expanded from:
@@ -71,23 +68,23 @@ fn test_right_shift() {
         ($iN:ty, $uN:ty, $max_rhs:expr,
          $signbit_i:expr, $highbit_i:expr, $highbit_u:expr) =>
         { {
-            let x = (1 as $iN) >> id(0);
+            let x = (1 as $iN) >> 0;
             assert_eq!(x, 1);
-            let x = (1 as $uN) >> id(0);
+            let x = (1 as $uN) >> 0;
             assert_eq!(x, 1);
-            let x = ($highbit_i) >> id($max_rhs-1);
+            let x = ($highbit_i) >> $max_rhs-1;
             assert_eq!(x, 1);
-            let x = ($highbit_u) >> id($max_rhs);
+            let x = ($highbit_u) >> $max_rhs;
             assert_eq!(x, 1);
             // sign-bit is carried by arithmetic right shift
-            let x = ($signbit_i) >> id($max_rhs);
+            let x = ($signbit_i) >> $max_rhs;
             assert_eq!(x, -1);
             // low-order bits on LHS are silently discarded without panic.
-            let x = ($highbit_i + 1) >> id($max_rhs-1);
+            let x = ($highbit_i + 1) >> $max_rhs-1;
             assert_eq!(x, 1);
-            let x = ($highbit_u + 1) >> id($max_rhs);
+            let x = ($highbit_u + 1) >> $max_rhs;
             assert_eq!(x, 1);
-            let x = ($signbit_i + 1) >> id($max_rhs);
+            let x = ($signbit_i + 1) >> $max_rhs;
             assert_eq!(x, -1);
         } }
     }