about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-11-30 12:29:01 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-11-30 12:29:01 +0000
commitbb6755859c3cd84092cf0361614b1cf255e8da11 (patch)
tree5920487d6664925f384a2a168d92eb5d52cf991a
parent8de4b138455add55bde6de5553a933a2ab79b71f (diff)
downloadrust-bb6755859c3cd84092cf0361614b1cf255e8da11.tar.gz
rust-bb6755859c3cd84092cf0361614b1cf255e8da11.zip
Add reproduction tests
-rw-r--r--src/test/ui/consts/promoted_const_call.rs13
-rw-r--r--src/test/ui/consts/promoted_const_call2.rs10
-rw-r--r--src/test/ui/consts/promoted_const_call3.rs14
-rw-r--r--src/test/ui/consts/promoted_const_call3.stderr32
4 files changed, 69 insertions, 0 deletions
diff --git a/src/test/ui/consts/promoted_const_call.rs b/src/test/ui/consts/promoted_const_call.rs
new file mode 100644
index 00000000000..465d8e1f402
--- /dev/null
+++ b/src/test/ui/consts/promoted_const_call.rs
@@ -0,0 +1,13 @@
+// check-pass
+// known-bug: #91009
+
+#![feature(const_mut_refs)]
+#![feature(const_trait_impl)]
+struct Panic;
+impl const Drop for Panic { fn drop(&mut self) { panic!(); } }
+pub const fn id<T>(x: T) -> T { x }
+pub const C: () = {
+    let _: &'static _ = &id(&Panic);
+};
+
+fn main() {}
diff --git a/src/test/ui/consts/promoted_const_call2.rs b/src/test/ui/consts/promoted_const_call2.rs
new file mode 100644
index 00000000000..82bde2b58d5
--- /dev/null
+++ b/src/test/ui/consts/promoted_const_call2.rs
@@ -0,0 +1,10 @@
+// check-pass
+// known-bug: #91009
+
+#![feature(const_precise_live_drops)]
+pub const fn id<T>(x: T) -> T { x }
+pub const C: () = {
+    let _: &'static _ = &id(&String::new());
+};
+
+fn main() {}
diff --git a/src/test/ui/consts/promoted_const_call3.rs b/src/test/ui/consts/promoted_const_call3.rs
new file mode 100644
index 00000000000..3b55a6f247e
--- /dev/null
+++ b/src/test/ui/consts/promoted_const_call3.rs
@@ -0,0 +1,14 @@
+pub const fn id<T>(x: T) -> T { x }
+pub const C: () = {
+    let _: &'static _ = &String::new();
+    //~^ ERROR: destructor of `String` cannot be evaluated at compile-time
+    //~| ERROR: temporary value dropped while borrowed
+
+    let _: &'static _ = &id(&String::new());
+    //~^ ERROR: destructor of `String` cannot be evaluated at compile-time
+
+    let _: &'static _ = &std::mem::ManuallyDrop::new(String::new());
+    // Promoted. bug!
+};
+
+fn main() {}
diff --git a/src/test/ui/consts/promoted_const_call3.stderr b/src/test/ui/consts/promoted_const_call3.stderr
new file mode 100644
index 00000000000..e436b7c23d4
--- /dev/null
+++ b/src/test/ui/consts/promoted_const_call3.stderr
@@ -0,0 +1,32 @@
+error[E0493]: destructor of `String` cannot be evaluated at compile-time
+  --> $DIR/promoted_const_call3.rs:7:30
+   |
+LL |     let _: &'static _ = &id(&String::new());
+   |                              ^^^^^^^^^^^^^ - value is dropped here
+   |                              |
+   |                              the destructor for this type cannot be evaluated in constants
+
+error[E0493]: destructor of `String` cannot be evaluated at compile-time
+  --> $DIR/promoted_const_call3.rs:3:26
+   |
+LL |     let _: &'static _ = &String::new();
+   |                          ^^^^^^^^^^^^^ the destructor for this type cannot be evaluated in constants
+...
+LL | };
+   | - value is dropped here
+
+error[E0716]: temporary value dropped while borrowed
+  --> $DIR/promoted_const_call3.rs:3:26
+   |
+LL |     let _: &'static _ = &String::new();
+   |            ----------    ^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
+   |            |
+   |            type annotation requires that borrow lasts for `'static`
+...
+LL | };
+   | - temporary value is freed at the end of this statement
+
+error: aborting due to 3 previous errors
+
+Some errors have detailed explanations: E0493, E0716.
+For more information about an error, try `rustc --explain E0493`.