summaryrefslogtreecommitdiffstats
path: root/tests/ui/consts/min_const_fn
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/consts/min_const_fn')
-rw-r--r--tests/ui/consts/min_const_fn/address_of.rs17
-rw-r--r--tests/ui/consts/min_const_fn/address_of.stderr21
-rw-r--r--tests/ui/consts/min_const_fn/address_of_const.rs19
-rw-r--r--tests/ui/consts/min_const_fn/allow_const_fn_ptr_run_pass.rs19
-rw-r--r--tests/ui/consts/min_const_fn/allow_raw_ptr_dereference_const_fn.rs9
-rw-r--r--tests/ui/consts/min_const_fn/bad_const_fn_body_ice.rs7
-rw-r--r--tests/ui/consts/min_const_fn/bad_const_fn_body_ice.stderr21
-rw-r--r--tests/ui/consts/min_const_fn/cast_fn.rs11
-rw-r--r--tests/ui/consts/min_const_fn/cmp_fn_pointers.rs6
-rw-r--r--tests/ui/consts/min_const_fn/cmp_fn_pointers.stderr16
-rw-r--r--tests/ui/consts/min_const_fn/min_const_fn.rs134
-rw-r--r--tests/ui/consts/min_const_fn/min_const_fn.stderr213
-rw-r--r--tests/ui/consts/min_const_fn/min_const_fn_dyn.rs15
-rw-r--r--tests/ui/consts/min_const_fn/min_const_fn_libstd.rs26
-rw-r--r--tests/ui/consts/min_const_fn/min_const_fn_libstd_stability.rs41
-rw-r--r--tests/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr41
-rw-r--r--tests/ui/consts/min_const_fn/min_const_fn_unsafe_bad.rs10
-rw-r--r--tests/ui/consts/min_const_fn/min_const_fn_unsafe_bad.stderr30
-rw-r--r--tests/ui/consts/min_const_fn/min_const_fn_unsafe_ok.rs44
-rw-r--r--tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.rs42
-rw-r--r--tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr41
-rw-r--r--tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.rs35
-rw-r--r--tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.stderr26
-rw-r--r--tests/ui/consts/min_const_fn/mutable_borrow.rs17
-rw-r--r--tests/ui/consts/min_const_fn/mutable_borrow.stderr21
-rw-r--r--tests/ui/consts/min_const_fn/promotion.rs17
-rw-r--r--tests/ui/consts/min_const_fn/promotion.stderr68
27 files changed, 967 insertions, 0 deletions
diff --git a/tests/ui/consts/min_const_fn/address_of.rs b/tests/ui/consts/min_const_fn/address_of.rs
new file mode 100644
index 000000000..40d1882d7
--- /dev/null
+++ b/tests/ui/consts/min_const_fn/address_of.rs
@@ -0,0 +1,17 @@
+#![feature(raw_ref_op)]
+
+const fn mutable_address_of_in_const() {
+ let mut a = 0;
+ let b = &raw mut a; //~ ERROR mutable reference
+}
+
+struct X;
+
+impl X {
+ const fn inherent_mutable_address_of_in_const() {
+ let mut a = 0;
+ let b = &raw mut a; //~ ERROR mutable reference
+ }
+}
+
+fn main() {}
diff --git a/tests/ui/consts/min_const_fn/address_of.stderr b/tests/ui/consts/min_const_fn/address_of.stderr
new file mode 100644
index 000000000..facc56651
--- /dev/null
+++ b/tests/ui/consts/min_const_fn/address_of.stderr
@@ -0,0 +1,21 @@
+error[E0658]: raw mutable references are not allowed in constant functions
+ --> $DIR/address_of.rs:5:13
+ |
+LL | let b = &raw mut a;
+ | ^^^^^^^^^^
+ |
+ = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
+ = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
+
+error[E0658]: raw mutable references are not allowed in constant functions
+ --> $DIR/address_of.rs:13:17
+ |
+LL | let b = &raw mut a;
+ | ^^^^^^^^^^
+ |
+ = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
+ = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0658`.
diff --git a/tests/ui/consts/min_const_fn/address_of_const.rs b/tests/ui/consts/min_const_fn/address_of_const.rs
new file mode 100644
index 000000000..3db19e9cd
--- /dev/null
+++ b/tests/ui/consts/min_const_fn/address_of_const.rs
@@ -0,0 +1,19 @@
+// check-pass
+
+#![feature(raw_ref_op)]
+
+const fn const_address_of_in_const() {
+ let mut a = 0;
+ let b = &raw const a;
+}
+
+struct X;
+
+impl X {
+ const fn inherent_const_address_of_in_const() {
+ let mut a = 0;
+ let b = &raw const a;
+ }
+}
+
+fn main() {}
diff --git a/tests/ui/consts/min_const_fn/allow_const_fn_ptr_run_pass.rs b/tests/ui/consts/min_const_fn/allow_const_fn_ptr_run_pass.rs
new file mode 100644
index 000000000..2dbc424d3
--- /dev/null
+++ b/tests/ui/consts/min_const_fn/allow_const_fn_ptr_run_pass.rs
@@ -0,0 +1,19 @@
+// run-pass
+#![feature(rustc_allow_const_fn_unstable)]
+
+#![feature(rustc_attrs, staged_api)]
+#![stable(feature = "rust1", since = "1.0.0")]
+
+#[stable(feature = "rust1", since = "1.0.0")]
+#[rustc_const_stable(since="1.0.0", feature = "mep")]
+const fn takes_fn_ptr(_: fn()) {}
+
+const FN: fn() = || ();
+
+const fn gives_fn_ptr() {
+ takes_fn_ptr(FN)
+}
+
+fn main() {
+ gives_fn_ptr();
+}
diff --git a/tests/ui/consts/min_const_fn/allow_raw_ptr_dereference_const_fn.rs b/tests/ui/consts/min_const_fn/allow_raw_ptr_dereference_const_fn.rs
new file mode 100644
index 000000000..d22115755
--- /dev/null
+++ b/tests/ui/consts/min_const_fn/allow_raw_ptr_dereference_const_fn.rs
@@ -0,0 +1,9 @@
+// check-pass
+
+use std::ptr;
+
+const fn test_fn(x: *const i32) {
+ let x2 = unsafe { ptr::addr_of!(*x) };
+}
+
+fn main() {}
diff --git a/tests/ui/consts/min_const_fn/bad_const_fn_body_ice.rs b/tests/ui/consts/min_const_fn/bad_const_fn_body_ice.rs
new file mode 100644
index 000000000..258997597
--- /dev/null
+++ b/tests/ui/consts/min_const_fn/bad_const_fn_body_ice.rs
@@ -0,0 +1,7 @@
+const fn foo(a: i32) -> Vec<i32> {
+ vec![1, 2, 3]
+ //~^ ERROR allocations are not allowed
+ //~| ERROR cannot call non-const fn
+}
+
+fn main() {}
diff --git a/tests/ui/consts/min_const_fn/bad_const_fn_body_ice.stderr b/tests/ui/consts/min_const_fn/bad_const_fn_body_ice.stderr
new file mode 100644
index 000000000..742341089
--- /dev/null
+++ b/tests/ui/consts/min_const_fn/bad_const_fn_body_ice.stderr
@@ -0,0 +1,21 @@
+error[E0010]: allocations are not allowed in constant functions
+ --> $DIR/bad_const_fn_body_ice.rs:2:5
+ |
+LL | vec![1, 2, 3]
+ | ^^^^^^^^^^^^^ allocation not allowed in constant functions
+ |
+ = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0015]: cannot call non-const fn `slice::<impl [i32]>::into_vec::<std::alloc::Global>` in constant functions
+ --> $DIR/bad_const_fn_body_ice.rs:2:5
+ |
+LL | vec![1, 2, 3]
+ | ^^^^^^^^^^^^^
+ |
+ = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
+ = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0010, E0015.
+For more information about an error, try `rustc --explain E0010`.
diff --git a/tests/ui/consts/min_const_fn/cast_fn.rs b/tests/ui/consts/min_const_fn/cast_fn.rs
new file mode 100644
index 000000000..85802a514
--- /dev/null
+++ b/tests/ui/consts/min_const_fn/cast_fn.rs
@@ -0,0 +1,11 @@
+// check-pass
+
+fn main() {}
+
+const fn unsize(x: &[u8; 3]) -> &[u8] { x }
+const fn closure() -> fn() { || {} }
+const fn closure2() {
+ (|| {}) as fn();
+}
+const fn reify(f: fn()) -> unsafe fn() { f }
+const fn reify2() { main as unsafe fn(); }
diff --git a/tests/ui/consts/min_const_fn/cmp_fn_pointers.rs b/tests/ui/consts/min_const_fn/cmp_fn_pointers.rs
new file mode 100644
index 000000000..9a2775688
--- /dev/null
+++ b/tests/ui/consts/min_const_fn/cmp_fn_pointers.rs
@@ -0,0 +1,6 @@
+const fn cmp(x: fn(), y: fn()) -> bool {
+ unsafe { x == y }
+ //~^ ERROR can't compare
+}
+
+fn main() {}
diff --git a/tests/ui/consts/min_const_fn/cmp_fn_pointers.stderr b/tests/ui/consts/min_const_fn/cmp_fn_pointers.stderr
new file mode 100644
index 000000000..8a1b20a33
--- /dev/null
+++ b/tests/ui/consts/min_const_fn/cmp_fn_pointers.stderr
@@ -0,0 +1,16 @@
+error[E0277]: can't compare `fn()` with `_` in const contexts
+ --> $DIR/cmp_fn_pointers.rs:2:16
+ |
+LL | unsafe { x == y }
+ | ^^ no implementation for `fn() == _`
+ |
+ = help: the trait `~const PartialEq<_>` is not implemented for `fn()`
+note: the trait `PartialEq<_>` is implemented for `fn()`, but that implementation is not `const`
+ --> $DIR/cmp_fn_pointers.rs:2:16
+ |
+LL | unsafe { x == y }
+ | ^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/consts/min_const_fn/min_const_fn.rs b/tests/ui/consts/min_const_fn/min_const_fn.rs
new file mode 100644
index 000000000..c2891488c
--- /dev/null
+++ b/tests/ui/consts/min_const_fn/min_const_fn.rs
@@ -0,0 +1,134 @@
+// ok
+const fn foo1() {}
+const fn foo2(x: i32) -> i32 { x }
+const fn foo3<T>(x: T) -> T { x }
+const fn foo7() {
+ (
+ foo1(),
+ foo2(420),
+ foo3(69),
+ ).0
+}
+const fn foo12<T: Sized>(t: T) -> T { t }
+const fn foo13<T: ?Sized>(t: &T) -> &T { t }
+const fn foo14<'a, T: 'a>(t: &'a T) -> &'a T { t }
+const fn foo15<T>(t: T) -> T where T: Sized { t }
+const fn foo15_2<T>(t: &T) -> &T where T: ?Sized { t }
+const fn foo16(f: f32) -> f32 { f }
+const fn foo17(f: f32) -> u32 { f as u32 }
+const fn foo18(i: i32) -> i32 { i * 3 }
+const fn foo20(b: bool) -> bool { !b }
+const fn foo21<T, U>(t: T, u: U) -> (T, U) { (t, u) }
+const fn foo22(s: &[u8], i: usize) -> u8 { s[i] }
+const FOO: u32 = 42;
+const fn foo23() -> u32 { FOO }
+const fn foo24() -> &'static u32 { &FOO }
+const fn foo27(x: &u32) -> u32 { *x }
+const fn foo28(x: u32) -> u32 { *&x }
+const fn foo29(x: u32) -> i32 { x as i32 }
+const fn foo31(a: bool, b: bool) -> bool { a & b }
+const fn foo32(a: bool, b: bool) -> bool { a | b }
+const fn foo33(a: bool, b: bool) -> bool { a & b }
+const fn foo34(a: bool, b: bool) -> bool { a | b }
+const fn foo35(a: bool, b: bool) -> bool { a ^ b }
+struct Foo<T: ?Sized>(T);
+impl<T> Foo<T> {
+ const fn new(t: T) -> Self { Foo(t) }
+ const fn into_inner(self) -> T { self.0 } //~ destructor of
+ const fn get(&self) -> &T { &self.0 }
+ const fn get_mut(&mut self) -> &mut T { &mut self.0 }
+ //~^ mutable references
+ //~| mutable references
+ //~| mutable references
+}
+impl<'a, T> Foo<T> {
+ const fn new_lt(t: T) -> Self { Foo(t) }
+ const fn into_inner_lt(self) -> T { self.0 } //~ destructor of
+ const fn get_lt(&'a self) -> &T { &self.0 }
+ const fn get_mut_lt(&'a mut self) -> &mut T { &mut self.0 }
+ //~^ mutable references
+ //~| mutable references
+ //~| mutable references
+}
+impl<T: Sized> Foo<T> {
+ const fn new_s(t: T) -> Self { Foo(t) }
+ const fn into_inner_s(self) -> T { self.0 } //~ ERROR destructor
+ const fn get_s(&self) -> &T { &self.0 }
+ const fn get_mut_s(&mut self) -> &mut T { &mut self.0 }
+ //~^ mutable references
+ //~| mutable references
+ //~| mutable references
+}
+impl<T: ?Sized> Foo<T> {
+ const fn get_sq(&self) -> &T { &self.0 }
+ const fn get_mut_sq(&mut self) -> &mut T { &mut self.0 }
+ //~^ mutable references
+ //~| mutable references
+ //~| mutable references
+}
+
+
+const fn char_ops(c: char, d: char) -> bool { c == d }
+const fn char_ops2(c: char, d: char) -> bool { c < d }
+const fn char_ops3(c: char, d: char) -> bool { c != d }
+const fn i32_ops(c: i32, d: i32) -> bool { c == d }
+const fn i32_ops2(c: i32, d: i32) -> bool { c < d }
+const fn i32_ops3(c: i32, d: i32) -> bool { c != d }
+const fn i32_ops4(c: i32, d: i32) -> i32 { c + d }
+const fn char_cast(u: u8) -> char { u as char }
+const unsafe fn ret_i32_no_unsafe() -> i32 { 42 }
+const unsafe fn ret_null_ptr_no_unsafe<T>() -> *const T { core::ptr::null() }
+const unsafe fn ret_null_mut_ptr_no_unsafe<T>() -> *mut T { core::ptr::null_mut() }
+
+const fn foo11<T: std::fmt::Display>(t: T) -> T { t }
+const fn foo11_2<T: Send>(t: T) -> T { t }
+
+// not ok
+
+static BAR: u32 = 42;
+const fn foo25() -> u32 { BAR } //~ ERROR cannot refer to statics
+const fn foo26() -> &'static u32 { &BAR } //~ ERROR cannot refer to statics
+const fn foo30(x: *const u32) -> usize { x as usize }
+//~^ ERROR pointers cannot be cast to integers
+const fn foo30_with_unsafe(x: *const u32) -> usize { unsafe { x as usize } }
+//~^ ERROR pointers cannot be cast to integers
+const fn foo30_2(x: *mut u32) -> usize { x as usize }
+//~^ ERROR pointers cannot be cast to integers
+const fn foo30_2_with_unsafe(x: *mut u32) -> usize { unsafe { x as usize } }
+//~^ ERROR pointers cannot be cast to integers
+const fn foo30_6() -> bool { let x = true; x }
+const fn inc(x: &mut i32) { *x += 1 }
+//~^ ERROR mutable references
+
+// ok
+const fn foo36(a: bool, b: bool) -> bool { a && b }
+const fn foo37(a: bool, b: bool) -> bool { a || b }
+
+fn main() {}
+
+impl<T: std::fmt::Debug> Foo<T> {
+ const fn foo(&self) {}
+}
+
+impl<T: std::fmt::Debug + Sized> Foo<T> {
+ const fn foo2(&self) {}
+}
+
+impl<T: Sync + Sized> Foo<T> {
+ const fn foo3(&self) {}
+}
+
+struct AlanTuring<T>(T);
+const fn no_apit2(_x: AlanTuring<impl std::fmt::Debug>) {}
+//~^ ERROR destructor
+const fn no_apit(_x: impl std::fmt::Debug) {}
+//~^ ERROR destructor
+const fn no_dyn_trait(_x: &dyn std::fmt::Debug) {}
+const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() }
+
+const fn no_unsafe() { unsafe {} }
+
+const fn traits_are_ok_i_mean_it() { (&() as &dyn std::fmt::Debug, ()).1 }
+
+const fn fn_ptrs(_x: fn()) {}
+const fn fn_ptrs2() -> fn() { fn foo() {} foo }
diff --git a/tests/ui/consts/min_const_fn/min_const_fn.stderr b/tests/ui/consts/min_const_fn/min_const_fn.stderr
new file mode 100644
index 000000000..11c79e8e2
--- /dev/null
+++ b/tests/ui/consts/min_const_fn/min_const_fn.stderr
@@ -0,0 +1,213 @@
+error[E0493]: destructor of `Foo<T>` cannot be evaluated at compile-time
+ --> $DIR/min_const_fn.rs:37:25
+ |
+LL | const fn into_inner(self) -> T { self.0 }
+ | ^^^^ - value is dropped here
+ | |
+ | the destructor for this type cannot be evaluated in constant functions
+
+error[E0658]: mutable references are not allowed in constant functions
+ --> $DIR/min_const_fn.rs:39:22
+ |
+LL | const fn get_mut(&mut self) -> &mut T { &mut self.0 }
+ | ^^^^^^^^^
+ |
+ = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
+ = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
+
+error[E0658]: mutable references are not allowed in constant functions
+ --> $DIR/min_const_fn.rs:39:36
+ |
+LL | const fn get_mut(&mut self) -> &mut T { &mut self.0 }
+ | ^^^^^^
+ |
+ = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
+ = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
+
+error[E0658]: mutable references are not allowed in constant functions
+ --> $DIR/min_const_fn.rs:39:45
+ |
+LL | const fn get_mut(&mut self) -> &mut T { &mut self.0 }
+ | ^^^^^^^^^^^
+ |
+ = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
+ = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
+
+error[E0493]: destructor of `Foo<T>` cannot be evaluated at compile-time
+ --> $DIR/min_const_fn.rs:46:28
+ |
+LL | const fn into_inner_lt(self) -> T { self.0 }
+ | ^^^^ - value is dropped here
+ | |
+ | the destructor for this type cannot be evaluated in constant functions
+
+error[E0658]: mutable references are not allowed in constant functions
+ --> $DIR/min_const_fn.rs:48:25
+ |
+LL | const fn get_mut_lt(&'a mut self) -> &mut T { &mut self.0 }
+ | ^^^^^^^^^^^^
+ |
+ = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
+ = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
+
+error[E0658]: mutable references are not allowed in constant functions
+ --> $DIR/min_const_fn.rs:48:42
+ |
+LL | const fn get_mut_lt(&'a mut self) -> &mut T { &mut self.0 }
+ | ^^^^^^
+ |
+ = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
+ = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
+
+error[E0658]: mutable references are not allowed in constant functions
+ --> $DIR/min_const_fn.rs:48:51
+ |
+LL | const fn get_mut_lt(&'a mut self) -> &mut T { &mut self.0 }
+ | ^^^^^^^^^^^
+ |
+ = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
+ = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
+
+error[E0493]: destructor of `Foo<T>` cannot be evaluated at compile-time
+ --> $DIR/min_const_fn.rs:55:27
+ |
+LL | const fn into_inner_s(self) -> T { self.0 }
+ | ^^^^ - value is dropped here
+ | |
+ | the destructor for this type cannot be evaluated in constant functions
+
+error[E0658]: mutable references are not allowed in constant functions
+ --> $DIR/min_const_fn.rs:57:24
+ |
+LL | const fn get_mut_s(&mut self) -> &mut T { &mut self.0 }
+ | ^^^^^^^^^
+ |
+ = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
+ = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
+
+error[E0658]: mutable references are not allowed in constant functions
+ --> $DIR/min_const_fn.rs:57:38
+ |
+LL | const fn get_mut_s(&mut self) -> &mut T { &mut self.0 }
+ | ^^^^^^
+ |
+ = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
+ = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
+
+error[E0658]: mutable references are not allowed in constant functions
+ --> $DIR/min_const_fn.rs:57:47
+ |
+LL | const fn get_mut_s(&mut self) -> &mut T { &mut self.0 }
+ | ^^^^^^^^^^^
+ |
+ = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
+ = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
+
+error[E0658]: mutable references are not allowed in constant functions
+ --> $DIR/min_const_fn.rs:64:25
+ |
+LL | const fn get_mut_sq(&mut self) -> &mut T { &mut self.0 }
+ | ^^^^^^^^^
+ |
+ = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
+ = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
+
+error[E0658]: mutable references are not allowed in constant functions
+ --> $DIR/min_const_fn.rs:64:39
+ |
+LL | const fn get_mut_sq(&mut self) -> &mut T { &mut self.0 }
+ | ^^^^^^
+ |
+ = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
+ = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
+
+error[E0658]: mutable references are not allowed in constant functions
+ --> $DIR/min_const_fn.rs:64:48
+ |
+LL | const fn get_mut_sq(&mut self) -> &mut T { &mut self.0 }
+ | ^^^^^^^^^^^
+ |
+ = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
+ = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
+
+error[E0013]: constant functions cannot refer to statics
+ --> $DIR/min_const_fn.rs:89:27
+ |
+LL | const fn foo25() -> u32 { BAR }
+ | ^^^
+ |
+ = help: consider extracting the value of the `static` to a `const`, and referring to that
+
+error[E0013]: constant functions cannot refer to statics
+ --> $DIR/min_const_fn.rs:90:37
+ |
+LL | const fn foo26() -> &'static u32 { &BAR }
+ | ^^^
+ |
+ = help: consider extracting the value of the `static` to a `const`, and referring to that
+
+error: pointers cannot be cast to integers during const eval
+ --> $DIR/min_const_fn.rs:91:42
+ |
+LL | const fn foo30(x: *const u32) -> usize { x as usize }
+ | ^^^^^^^^^^
+ |
+ = note: at compile-time, pointers do not have an integer value
+ = note: avoiding this restriction via `transmute`, `union`, or raw pointers leads to compile-time undefined behavior
+
+error: pointers cannot be cast to integers during const eval
+ --> $DIR/min_const_fn.rs:93:63
+ |
+LL | const fn foo30_with_unsafe(x: *const u32) -> usize { unsafe { x as usize } }
+ | ^^^^^^^^^^
+ |
+ = note: at compile-time, pointers do not have an integer value
+ = note: avoiding this restriction via `transmute`, `union`, or raw pointers leads to compile-time undefined behavior
+
+error: pointers cannot be cast to integers during const eval
+ --> $DIR/min_const_fn.rs:95:42
+ |
+LL | const fn foo30_2(x: *mut u32) -> usize { x as usize }
+ | ^^^^^^^^^^
+ |
+ = note: at compile-time, pointers do not have an integer value
+ = note: avoiding this restriction via `transmute`, `union`, or raw pointers leads to compile-time undefined behavior
+
+error: pointers cannot be cast to integers during const eval
+ --> $DIR/min_const_fn.rs:97:63
+ |
+LL | const fn foo30_2_with_unsafe(x: *mut u32) -> usize { unsafe { x as usize } }
+ | ^^^^^^^^^^
+ |
+ = note: at compile-time, pointers do not have an integer value
+ = note: avoiding this restriction via `transmute`, `union`, or raw pointers leads to compile-time undefined behavior
+
+error[E0658]: mutable references are not allowed in constant functions
+ --> $DIR/min_const_fn.rs:100:14
+ |
+LL | const fn inc(x: &mut i32) { *x += 1 }
+ | ^
+ |
+ = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
+ = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
+
+error[E0493]: destructor of `AlanTuring<impl std::fmt::Debug>` cannot be evaluated at compile-time
+ --> $DIR/min_const_fn.rs:122:19
+ |
+LL | const fn no_apit2(_x: AlanTuring<impl std::fmt::Debug>) {}
+ | ^^ - value is dropped here
+ | |
+ | the destructor for this type cannot be evaluated in constant functions
+
+error[E0493]: destructor of `impl std::fmt::Debug` cannot be evaluated at compile-time
+ --> $DIR/min_const_fn.rs:124:18
+ |
+LL | const fn no_apit(_x: impl std::fmt::Debug) {}
+ | ^^ - value is dropped here
+ | |
+ | the destructor for this type cannot be evaluated in constant functions
+
+error: aborting due to 24 previous errors
+
+Some errors have detailed explanations: E0013, E0493, E0658.
+For more information about an error, try `rustc --explain E0013`.
diff --git a/tests/ui/consts/min_const_fn/min_const_fn_dyn.rs b/tests/ui/consts/min_const_fn/min_const_fn_dyn.rs
new file mode 100644
index 000000000..36c888009
--- /dev/null
+++ b/tests/ui/consts/min_const_fn/min_const_fn_dyn.rs
@@ -0,0 +1,15 @@
+// check-pass
+
+struct HasDyn {
+ field: &'static dyn std::fmt::Debug,
+}
+
+struct Hide(HasDyn);
+
+const fn no_inner_dyn_trait(_x: Hide) {}
+const fn no_inner_dyn_trait2(x: Hide) {
+ x.0.field;
+}
+const fn no_inner_dyn_trait_ret() -> Hide { Hide(HasDyn { field: &0 }) }
+
+fn main() {}
diff --git a/tests/ui/consts/min_const_fn/min_const_fn_libstd.rs b/tests/ui/consts/min_const_fn/min_const_fn_libstd.rs
new file mode 100644
index 000000000..cb8f74186
--- /dev/null
+++ b/tests/ui/consts/min_const_fn/min_const_fn_libstd.rs
@@ -0,0 +1,26 @@
+// build-pass (FIXME(62277): could be check-pass?)
+
+use std::cell::UnsafeCell;
+use std::sync::atomic::AtomicU32;
+pub struct Condvar {
+ condvar: UnsafeCell<AtomicU32>,
+}
+
+unsafe impl Send for Condvar {}
+unsafe impl Sync for Condvar {}
+
+#[repr(C)]
+#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
+struct NoWait(u32);
+
+const CONDVAR_HAS_NO_WAITERS: NoWait = NoWait(42);
+
+impl Condvar {
+ pub const fn new() -> Condvar {
+ Condvar {
+ condvar: UnsafeCell::new(AtomicU32::new(CONDVAR_HAS_NO_WAITERS.0)),
+ }
+ }
+}
+
+fn main() {}
diff --git a/tests/ui/consts/min_const_fn/min_const_fn_libstd_stability.rs b/tests/ui/consts/min_const_fn/min_const_fn_libstd_stability.rs
new file mode 100644
index 000000000..bb240fb4a
--- /dev/null
+++ b/tests/ui/consts/min_const_fn/min_const_fn_libstd_stability.rs
@@ -0,0 +1,41 @@
+#![unstable(feature = "humans",
+ reason = "who ever let humans program computers,
+ we're apparently really bad at it",
+ issue = "none")]
+
+#![feature(const_fn_floating_point_arithmetic, foo, foo2)]
+#![feature(staged_api)]
+
+#[stable(feature = "rust1", since = "1.0.0")]
+#[rustc_const_unstable(feature="foo", issue = "none")]
+const fn foo() -> u32 { 42 }
+
+#[stable(feature = "rust1", since = "1.0.0")]
+#[rustc_const_stable(feature = "rust1", since = "1.0.0")]
+// can't call non-min_const_fn
+const fn bar() -> u32 { foo() } //~ ERROR not yet stable as a const fn
+
+#[unstable(feature = "foo2", issue = "none")]
+const fn foo2() -> u32 { 42 }
+
+#[stable(feature = "rust1", since = "1.0.0")]
+#[rustc_const_stable(feature = "rust1", since = "1.0.0")]
+// can't call non-min_const_fn
+const fn bar2() -> u32 { foo2() } //~ ERROR not yet stable as a const fn
+
+#[stable(feature = "rust1", since = "1.0.0")]
+#[rustc_const_stable(feature = "rust1", since = "1.0.0")]
+// Const-stable functions cannot rely on unstable const-eval features.
+const fn bar3() -> u32 { (5f32 + 6f32) as u32 }
+//~^ ERROR const-stable function cannot use `#[feature(const_fn_floating_point_arithmetic)]`
+
+// check whether this function cannot be called even with the feature gate active
+#[unstable(feature = "foo2", issue = "none")]
+const fn foo2_gated() -> u32 { 42 }
+
+#[stable(feature = "rust1", since = "1.0.0")]
+#[rustc_const_stable(feature = "rust1", since = "1.0.0")]
+// can't call non-min_const_fn
+const fn bar2_gated() -> u32 { foo2_gated() } //~ ERROR not yet stable as a const fn
+
+fn main() {}
diff --git a/tests/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr b/tests/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr
new file mode 100644
index 000000000..778b0e55f
--- /dev/null
+++ b/tests/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr
@@ -0,0 +1,41 @@
+error: `foo` is not yet stable as a const fn
+ --> $DIR/min_const_fn_libstd_stability.rs:16:25
+ |
+LL | const fn bar() -> u32 { foo() }
+ | ^^^^^
+ |
+ = help: const-stable functions can only call other const-stable functions
+
+error: `foo2` is not yet stable as a const fn
+ --> $DIR/min_const_fn_libstd_stability.rs:24:26
+ |
+LL | const fn bar2() -> u32 { foo2() }
+ | ^^^^^^
+ |
+ = help: const-stable functions can only call other const-stable functions
+
+error: const-stable function cannot use `#[feature(const_fn_floating_point_arithmetic)]`
+ --> $DIR/min_const_fn_libstd_stability.rs:29:26
+ |
+LL | const fn bar3() -> u32 { (5f32 + 6f32) as u32 }
+ | ^^^^^^^^^^^^^
+ |
+help: if it is not part of the public API, make this function unstably const
+ |
+LL | #[rustc_const_unstable(feature = "...", issue = "...")]
+ |
+help: otherwise `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks
+ |
+LL | #[rustc_allow_const_fn_unstable(const_fn_floating_point_arithmetic)]
+ |
+
+error: `foo2_gated` is not yet stable as a const fn
+ --> $DIR/min_const_fn_libstd_stability.rs:39:32
+ |
+LL | const fn bar2_gated() -> u32 { foo2_gated() }
+ | ^^^^^^^^^^^^
+ |
+ = help: const-stable functions can only call other const-stable functions
+
+error: aborting due to 4 previous errors
+
diff --git a/tests/ui/consts/min_const_fn/min_const_fn_unsafe_bad.rs b/tests/ui/consts/min_const_fn/min_const_fn_unsafe_bad.rs
new file mode 100644
index 000000000..a6e1788bb
--- /dev/null
+++ b/tests/ui/consts/min_const_fn/min_const_fn_unsafe_bad.rs
@@ -0,0 +1,10 @@
+const fn bad_const_fn_deref_raw(x: *mut usize) -> &'static usize { unsafe { &*x } }
+//~^ dereferencing raw mutable pointers in constant functions
+
+const unsafe fn bad_const_unsafe_deref_raw(x: *mut usize) -> usize { *x }
+//~^ dereferencing raw mutable pointers in constant functions
+
+const unsafe fn bad_const_unsafe_deref_raw_ref(x: *mut usize) -> &'static usize { &*x }
+//~^ dereferencing raw mutable pointers in constant functions
+
+fn main() {}
diff --git a/tests/ui/consts/min_const_fn/min_const_fn_unsafe_bad.stderr b/tests/ui/consts/min_const_fn/min_const_fn_unsafe_bad.stderr
new file mode 100644
index 000000000..820b6433f
--- /dev/null
+++ b/tests/ui/consts/min_const_fn/min_const_fn_unsafe_bad.stderr
@@ -0,0 +1,30 @@
+error[E0658]: dereferencing raw mutable pointers in constant functions is unstable
+ --> $DIR/min_const_fn_unsafe_bad.rs:1:77
+ |
+LL | const fn bad_const_fn_deref_raw(x: *mut usize) -> &'static usize { unsafe { &*x } }
+ | ^^^
+ |
+ = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
+ = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
+
+error[E0658]: dereferencing raw mutable pointers in constant functions is unstable
+ --> $DIR/min_const_fn_unsafe_bad.rs:4:70
+ |
+LL | const unsafe fn bad_const_unsafe_deref_raw(x: *mut usize) -> usize { *x }
+ | ^^
+ |
+ = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
+ = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
+
+error[E0658]: dereferencing raw mutable pointers in constant functions is unstable
+ --> $DIR/min_const_fn_unsafe_bad.rs:7:83
+ |
+LL | const unsafe fn bad_const_unsafe_deref_raw_ref(x: *mut usize) -> &'static usize { &*x }
+ | ^^^
+ |
+ = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
+ = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0658`.
diff --git a/tests/ui/consts/min_const_fn/min_const_fn_unsafe_ok.rs b/tests/ui/consts/min_const_fn/min_const_fn_unsafe_ok.rs
new file mode 100644
index 000000000..02c7970de
--- /dev/null
+++ b/tests/ui/consts/min_const_fn/min_const_fn_unsafe_ok.rs
@@ -0,0 +1,44 @@
+// check-pass
+
+const unsafe fn ret_i32_no_unsafe() -> i32 { 42 }
+const unsafe fn ret_null_ptr_no_unsafe<T>() -> *const T { std::ptr::null() }
+const unsafe fn ret_null_mut_ptr_no_unsafe<T>() -> *mut T { std::ptr::null_mut() }
+const fn no_unsafe() { unsafe {} }
+
+const fn call_unsafe_const_fn() -> i32 {
+ unsafe { ret_i32_no_unsafe() }
+}
+const fn call_unsafe_generic_const_fn() -> *const String {
+ unsafe { ret_null_ptr_no_unsafe::<String>() }
+}
+const fn call_unsafe_generic_cell_const_fn()
+ -> *const Vec<std::cell::Cell<u32>>
+{
+ unsafe { ret_null_mut_ptr_no_unsafe::<Vec<std::cell::Cell<u32>>>() }
+}
+
+const unsafe fn call_unsafe_const_unsafe_fn() -> i32 {
+ unsafe { ret_i32_no_unsafe() }
+}
+const unsafe fn call_unsafe_generic_const_unsafe_fn() -> *const String {
+ unsafe { ret_null_ptr_no_unsafe::<String>() }
+}
+const unsafe fn call_unsafe_generic_cell_const_unsafe_fn()
+ -> *const Vec<std::cell::Cell<u32>>
+{
+ unsafe { ret_null_mut_ptr_no_unsafe::<Vec<std::cell::Cell<u32>>>() }
+}
+
+const unsafe fn call_unsafe_const_unsafe_fn_immediate() -> i32 {
+ ret_i32_no_unsafe()
+}
+const unsafe fn call_unsafe_generic_const_unsafe_fn_immediate() -> *const String {
+ ret_null_ptr_no_unsafe::<String>()
+}
+const unsafe fn call_unsafe_generic_cell_const_unsafe_fn_immediate()
+ -> *const Vec<std::cell::Cell<u32>>
+{
+ ret_null_mut_ptr_no_unsafe::<Vec<std::cell::Cell<u32>>>()
+}
+
+fn main() {}
diff --git a/tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.rs b/tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.rs
new file mode 100644
index 000000000..03084c867
--- /dev/null
+++ b/tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.rs
@@ -0,0 +1,42 @@
+#![unstable(feature = "humans",
+ reason = "who ever let humans program computers,
+ we're apparently really bad at it",
+ issue = "none")]
+
+#![feature(const_fn_floating_point_arithmetic, foo, foo2)]
+#![feature(staged_api)]
+
+#[stable(feature = "rust1", since = "1.0.0")]
+#[rustc_const_unstable(feature="foo", issue = "none")]
+const unsafe fn foo() -> u32 { 42 }
+
+#[stable(feature = "rust1", since = "1.0.0")]
+#[rustc_const_stable(feature = "rust1", since = "1.0.0")]
+// can't call non-min_const_fn
+const unsafe fn bar() -> u32 { unsafe { foo() } } //~ ERROR not yet stable as a const fn
+
+#[unstable(feature = "foo2", issue = "none")]
+const unsafe fn foo2() -> u32 { 42 }
+
+#[stable(feature = "rust1", since = "1.0.0")]
+#[rustc_const_stable(feature = "rust1", since = "1.0.0")]
+// can't call non-min_const_fn
+const unsafe fn bar2() -> u32 { unsafe { foo2() } } //~ ERROR not yet stable as a const fn
+
+#[stable(feature = "rust1", since = "1.0.0")]
+#[rustc_const_stable(feature = "rust1", since = "1.0.0")]
+// conformity is required
+const unsafe fn bar3() -> u32 { (5f32 + 6f32) as u32 }
+//~^ ERROR const-stable function cannot use `#[feature(const_fn_floating_point_arithmetic)]`
+
+// check whether this function cannot be called even with the feature gate active
+#[unstable(feature = "foo2", issue = "none")]
+const unsafe fn foo2_gated() -> u32 { 42 }
+
+#[stable(feature = "rust1", since = "1.0.0")]
+#[rustc_const_stable(feature = "rust1", since = "1.0.0")]
+// can't call non-min_const_fn
+const unsafe fn bar2_gated() -> u32 { unsafe { foo2_gated() } }
+//~^ ERROR not yet stable as a const fn
+
+fn main() {}
diff --git a/tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr b/tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr
new file mode 100644
index 000000000..0174cb77f
--- /dev/null
+++ b/tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr
@@ -0,0 +1,41 @@
+error: `foo` is not yet stable as a const fn
+ --> $DIR/min_const_unsafe_fn_libstd_stability.rs:16:41
+ |
+LL | const unsafe fn bar() -> u32 { unsafe { foo() } }
+ | ^^^^^
+ |
+ = help: const-stable functions can only call other const-stable functions
+
+error: `foo2` is not yet stable as a const fn
+ --> $DIR/min_const_unsafe_fn_libstd_stability.rs:24:42
+ |
+LL | const unsafe fn bar2() -> u32 { unsafe { foo2() } }
+ | ^^^^^^
+ |
+ = help: const-stable functions can only call other const-stable functions
+
+error: const-stable function cannot use `#[feature(const_fn_floating_point_arithmetic)]`
+ --> $DIR/min_const_unsafe_fn_libstd_stability.rs:29:33
+ |
+LL | const unsafe fn bar3() -> u32 { (5f32 + 6f32) as u32 }
+ | ^^^^^^^^^^^^^
+ |
+help: if it is not part of the public API, make this function unstably const
+ |
+LL | #[rustc_const_unstable(feature = "...", issue = "...")]
+ |
+help: otherwise `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks
+ |
+LL | #[rustc_allow_const_fn_unstable(const_fn_floating_point_arithmetic)]
+ |
+
+error: `foo2_gated` is not yet stable as a const fn
+ --> $DIR/min_const_unsafe_fn_libstd_stability.rs:39:48
+ |
+LL | const unsafe fn bar2_gated() -> u32 { unsafe { foo2_gated() } }
+ | ^^^^^^^^^^^^
+ |
+ = help: const-stable functions can only call other const-stable functions
+
+error: aborting due to 4 previous errors
+
diff --git a/tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.rs b/tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.rs
new file mode 100644
index 000000000..94b620713
--- /dev/null
+++ b/tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.rs
@@ -0,0 +1,35 @@
+#![unstable(feature = "humans",
+ reason = "who ever let humans program computers,
+ we're apparently really bad at it",
+ issue = "none")]
+
+#![feature(foo, foo2)]
+#![feature(staged_api)]
+
+#[stable(feature = "rust1", since = "1.0.0")]
+#[rustc_const_unstable(feature="foo", issue = "none")]
+const fn foo() -> u32 { 42 }
+
+#[stable(feature = "rust1", since = "1.0.0")]
+#[rustc_const_stable(feature = "rust1", since = "1.0.0")]
+// can't call non-min_const_fn
+const unsafe fn bar() -> u32 { foo() } //~ ERROR not yet stable as a const fn
+
+#[unstable(feature = "foo2", issue = "none")]
+const fn foo2() -> u32 { 42 }
+
+#[stable(feature = "rust1", since = "1.0.0")]
+#[rustc_const_stable(feature = "rust1", since = "1.0.0")]
+// can't call non-min_const_fn
+const unsafe fn bar2() -> u32 { foo2() } //~ ERROR not yet stable as a const fn
+
+// check whether this function cannot be called even with the feature gate active
+#[unstable(feature = "foo2", issue = "none")]
+const fn foo2_gated() -> u32 { 42 }
+
+#[stable(feature = "rust1", since = "1.0.0")]
+#[rustc_const_stable(feature = "rust1", since = "1.0.0")]
+// can't call non-min_const_fn
+const unsafe fn bar2_gated() -> u32 { foo2_gated() } //~ ERROR not yet stable as a const fn
+
+fn main() {}
diff --git a/tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.stderr b/tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.stderr
new file mode 100644
index 000000000..e90ba9b91
--- /dev/null
+++ b/tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.stderr
@@ -0,0 +1,26 @@
+error: `foo` is not yet stable as a const fn
+ --> $DIR/min_const_unsafe_fn_libstd_stability2.rs:16:32
+ |
+LL | const unsafe fn bar() -> u32 { foo() }
+ | ^^^^^
+ |
+ = help: const-stable functions can only call other const-stable functions
+
+error: `foo2` is not yet stable as a const fn
+ --> $DIR/min_const_unsafe_fn_libstd_stability2.rs:24:33
+ |
+LL | const unsafe fn bar2() -> u32 { foo2() }
+ | ^^^^^^
+ |
+ = help: const-stable functions can only call other const-stable functions
+
+error: `foo2_gated` is not yet stable as a const fn
+ --> $DIR/min_const_unsafe_fn_libstd_stability2.rs:33:39
+ |
+LL | const unsafe fn bar2_gated() -> u32 { foo2_gated() }
+ | ^^^^^^^^^^^^
+ |
+ = help: const-stable functions can only call other const-stable functions
+
+error: aborting due to 3 previous errors
+
diff --git a/tests/ui/consts/min_const_fn/mutable_borrow.rs b/tests/ui/consts/min_const_fn/mutable_borrow.rs
new file mode 100644
index 000000000..580b1d50f
--- /dev/null
+++ b/tests/ui/consts/min_const_fn/mutable_borrow.rs
@@ -0,0 +1,17 @@
+const fn mutable_ref_in_const() -> u8 {
+ let mut a = 0;
+ let b = &mut a; //~ ERROR mutable references
+ *b
+}
+
+struct X;
+
+impl X {
+ const fn inherent_mutable_ref_in_const() -> u8 {
+ let mut a = 0;
+ let b = &mut a; //~ ERROR mutable references
+ *b
+ }
+}
+
+fn main() {}
diff --git a/tests/ui/consts/min_const_fn/mutable_borrow.stderr b/tests/ui/consts/min_const_fn/mutable_borrow.stderr
new file mode 100644
index 000000000..8e95a4c68
--- /dev/null
+++ b/tests/ui/consts/min_const_fn/mutable_borrow.stderr
@@ -0,0 +1,21 @@
+error[E0658]: mutable references are not allowed in constant functions
+ --> $DIR/mutable_borrow.rs:3:13
+ |
+LL | let b = &mut a;
+ | ^^^^^^
+ |
+ = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
+ = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
+
+error[E0658]: mutable references are not allowed in constant functions
+ --> $DIR/mutable_borrow.rs:12:17
+ |
+LL | let b = &mut a;
+ | ^^^^^^
+ |
+ = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
+ = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0658`.
diff --git a/tests/ui/consts/min_const_fn/promotion.rs b/tests/ui/consts/min_const_fn/promotion.rs
new file mode 100644
index 000000000..fbe535c71
--- /dev/null
+++ b/tests/ui/consts/min_const_fn/promotion.rs
@@ -0,0 +1,17 @@
+use std::cell::Cell;
+
+const fn foo1() {}
+const fn foo2(x: i32) -> i32 { x }
+const fn foo3() -> i32 { 42 }
+const fn foo4() -> Cell<i32> { Cell::new(42) }
+const fn foo5() -> Option<Cell<i32>> { Some(Cell::new(42)) }
+const fn foo6() -> Option<Cell<i32>> { None }
+
+fn main() {
+ let x: &'static () = &foo1(); //~ ERROR temporary value dropped while borrowed
+ let y: &'static i32 = &foo2(42); //~ ERROR temporary value dropped while borrowed
+ let z: &'static i32 = &foo3(); //~ ERROR temporary value dropped while borrowed
+ let a: &'static Cell<i32> = &foo4(); //~ ERROR temporary value dropped while borrowed
+ let a: &'static Option<Cell<i32>> = &foo5(); //~ ERROR temporary value dropped while borrowed
+ let a: &'static Option<Cell<i32>> = &foo6(); //~ ERROR temporary value dropped while borrowed
+}
diff --git a/tests/ui/consts/min_const_fn/promotion.stderr b/tests/ui/consts/min_const_fn/promotion.stderr
new file mode 100644
index 000000000..0b8dc0ce0
--- /dev/null
+++ b/tests/ui/consts/min_const_fn/promotion.stderr
@@ -0,0 +1,68 @@
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/promotion.rs:11:27
+ |
+LL | let x: &'static () = &foo1();
+ | ----------- ^^^^^^ 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[E0716]: temporary value dropped while borrowed
+ --> $DIR/promotion.rs:12:28
+ |
+LL | let y: &'static i32 = &foo2(42);
+ | ------------ ^^^^^^^^ 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[E0716]: temporary value dropped while borrowed
+ --> $DIR/promotion.rs:13:28
+ |
+LL | let z: &'static i32 = &foo3();
+ | ------------ ^^^^^^ 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[E0716]: temporary value dropped while borrowed
+ --> $DIR/promotion.rs:14:34
+ |
+LL | let a: &'static Cell<i32> = &foo4();
+ | ------------------ ^^^^^^ 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[E0716]: temporary value dropped while borrowed
+ --> $DIR/promotion.rs:15:42
+ |
+LL | let a: &'static Option<Cell<i32>> = &foo5();
+ | -------------------------- ^^^^^^ creates a temporary value which is freed while still in use
+ | |
+ | type annotation requires that borrow lasts for `'static`
+LL | let a: &'static Option<Cell<i32>> = &foo6();
+LL | }
+ | - temporary value is freed at the end of this statement
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/promotion.rs:16:42
+ |
+LL | let a: &'static Option<Cell<i32>> = &foo6();
+ | -------------------------- ^^^^^^ 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 6 previous errors
+
+For more information about this error, try `rustc --explain E0716`.