From bb6755859c3cd84092cf0361614b1cf255e8da11 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 30 Nov 2022 12:29:01 +0000 Subject: [PATCH] Add reproduction tests --- src/test/ui/consts/promoted_const_call.rs | 13 ++++++++ src/test/ui/consts/promoted_const_call2.rs | 10 ++++++ src/test/ui/consts/promoted_const_call3.rs | 14 ++++++++ .../ui/consts/promoted_const_call3.stderr | 32 +++++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 src/test/ui/consts/promoted_const_call.rs create mode 100644 src/test/ui/consts/promoted_const_call2.rs create mode 100644 src/test/ui/consts/promoted_const_call3.rs create mode 100644 src/test/ui/consts/promoted_const_call3.stderr 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 000000000000..465d8e1f4026 --- /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(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 000000000000..82bde2b58d54 --- /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(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 000000000000..3b55a6f247e9 --- /dev/null +++ b/src/test/ui/consts/promoted_const_call3.rs @@ -0,0 +1,14 @@ +pub const fn id(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 000000000000..e436b7c23d49 --- /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`.