about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBastian Kauschke <bastian_kauschke@hotmail.de>2020-08-06 22:32:12 +0200
committerBastian Kauschke <bastian_kauschke@hotmail.de>2020-09-08 16:39:12 +0200
commit78046448638c8db12db51b8f7bbbe29860d79c4e (patch)
treec4d142e0683e719dba1ad7ffb1faaad768963423
parentc10ad0d888df19e7185e15f811fdb011278f3c20 (diff)
downloadrust-78046448638c8db12db51b8f7bbbe29860d79c4e.tar.gz
rust-78046448638c8db12db51b8f7bbbe29860d79c4e.zip
add tests
-rw-r--r--src/test/ui/const_evaluatable/associated-const.rs (renamed from src/test/ui/const_evaluatable/associated_const.rs)0
-rw-r--r--src/test/ui/const_evaluatable/function-call.rs17
-rw-r--r--src/test/ui/const_evaluatable/function-call.stderr12
3 files changed, 29 insertions, 0 deletions
diff --git a/src/test/ui/const_evaluatable/associated_const.rs b/src/test/ui/const_evaluatable/associated-const.rs
index a6777632254..a6777632254 100644
--- a/src/test/ui/const_evaluatable/associated_const.rs
+++ b/src/test/ui/const_evaluatable/associated-const.rs
diff --git a/src/test/ui/const_evaluatable/function-call.rs b/src/test/ui/const_evaluatable/function-call.rs
new file mode 100644
index 00000000000..b13a0369a00
--- /dev/null
+++ b/src/test/ui/const_evaluatable/function-call.rs
@@ -0,0 +1,17 @@
+// check-pass
+
+const fn foo<T>() -> usize {
+    if std::mem::size_of::<*mut T>() < 8 { // size of *mut T does not depend on T
+        std::mem::size_of::<T>()
+    } else {
+        8
+    }
+}
+
+fn test<T>() {
+    let _ = [0; foo::<T>()];
+    //~^ WARN cannot use constants which depend on generic parameters in types
+    //~| WARN this was previously accepted by the compiler but is being phased out
+}
+
+fn main() {}
diff --git a/src/test/ui/const_evaluatable/function-call.stderr b/src/test/ui/const_evaluatable/function-call.stderr
new file mode 100644
index 00000000000..5240015c37a
--- /dev/null
+++ b/src/test/ui/const_evaluatable/function-call.stderr
@@ -0,0 +1,12 @@
+warning: cannot use constants which depend on generic parameters in types
+  --> $DIR/function-call.rs:12:17
+   |
+LL |     let _ = [0; foo::<T>()];
+   |                 ^^^^^^^^^^
+   |
+   = note: `#[warn(const_evaluatable_unchecked)]` on by default
+   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+   = note: for more information, see TODO
+
+warning: 1 warning emitted
+