about summary refs log tree commit diff
path: root/src/test/ui/consts
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2021-06-04 00:00:00 +0000
committerTomasz Miąsko <tomasz.miasko@gmail.com>2021-06-05 18:28:25 +0200
commit894b42c8616f352eacf54bc830c01e33b406fb8f (patch)
tree937279ff8f96f227aa801c725236843318055eca /src/test/ui/consts
parent5ea19239d9d6f49fdd76513a36386d7e83708e3f (diff)
downloadrust-894b42c8616f352eacf54bc830c01e33b406fb8f.tar.gz
rust-894b42c8616f352eacf54bc830c01e33b406fb8f.zip
Disallow non-monomorphic calls to `needs_drop` in interpreter
otherwise evaluation could change after further substitutions.
Diffstat (limited to 'src/test/ui/consts')
-rw-r--r--src/test/ui/consts/const-needs_drop-monomorphic.rs17
-rw-r--r--src/test/ui/consts/const-needs_drop-monomorphic.stderr20
2 files changed, 37 insertions, 0 deletions
diff --git a/src/test/ui/consts/const-needs_drop-monomorphic.rs b/src/test/ui/consts/const-needs_drop-monomorphic.rs
new file mode 100644
index 00000000000..9f66e3cfa23
--- /dev/null
+++ b/src/test/ui/consts/const-needs_drop-monomorphic.rs
@@ -0,0 +1,17 @@
+// Check that evaluation of needs_drop<T> fails when T is not monomorphic.
+#![feature(const_generics)]
+#![allow(const_evaluatable_unchecked)]
+#![allow(incomplete_features)]
+
+struct Bool<const B: bool> {}
+impl Bool<true> {
+    fn assert() {}
+}
+fn f<T>() {
+    Bool::<{ std::mem::needs_drop::<T>() }>::assert();
+    //~^ ERROR no function or associated item named `assert` found
+    //~| ERROR constant expression depends on a generic parameter
+}
+fn main() {
+    f::<u32>();
+}
diff --git a/src/test/ui/consts/const-needs_drop-monomorphic.stderr b/src/test/ui/consts/const-needs_drop-monomorphic.stderr
new file mode 100644
index 00000000000..0770d06e15b
--- /dev/null
+++ b/src/test/ui/consts/const-needs_drop-monomorphic.stderr
@@ -0,0 +1,20 @@
+error[E0599]: no function or associated item named `assert` found for struct `Bool<{ std::mem::needs_drop::<T>() }>` in the current scope
+  --> $DIR/const-needs_drop-monomorphic.rs:11:46
+   |
+LL | struct Bool<const B: bool> {}
+   | -------------------------- function or associated item `assert` not found for this
+...
+LL |     Bool::<{ std::mem::needs_drop::<T>() }>::assert();
+   |                                              ^^^^^^ function or associated item cannot be called on `Bool<{ std::mem::needs_drop::<T>() }>` due to unsatisfied trait bounds
+
+error: constant expression depends on a generic parameter
+  --> $DIR/const-needs_drop-monomorphic.rs:11:5
+   |
+LL |     Bool::<{ std::mem::needs_drop::<T>() }>::assert();
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: this may fail depending on what value the parameter takes
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0599`.