about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--library/core/src/panicking.rs1
-rw-r--r--library/core/src/time.rs4
-rw-r--r--src/test/ui/consts/const-eval/const_panic_stability.e2018.stderr16
-rw-r--r--src/test/ui/consts/const-eval/const_panic_stability.e2021.stderr13
-rw-r--r--src/test/ui/consts/const-eval/const_panic_stability.rs17
5 files changed, 49 insertions, 2 deletions
diff --git a/library/core/src/panicking.rs b/library/core/src/panicking.rs
index 29124c87e1b..eedea6562bd 100644
--- a/library/core/src/panicking.rs
+++ b/library/core/src/panicking.rs
@@ -36,6 +36,7 @@ use crate::panic::{Location, PanicInfo};
 #[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
 #[cfg_attr(feature = "panic_immediate_abort", inline)]
 #[track_caller]
+#[rustc_const_unstable(feature = "core_panic", issue = "none")]
 #[lang = "panic"] // needed by codegen for panic on overflow and other `Assert` MIR terminators
 pub const fn panic(expr: &'static str) -> ! {
     // Use Arguments::new_v1 instead of format_args!("{}", expr) to potentially
diff --git a/library/core/src/time.rs b/library/core/src/time.rs
index a054d72a880..7330c86a11a 100644
--- a/library/core/src/time.rs
+++ b/library/core/src/time.rs
@@ -727,7 +727,7 @@ impl Duration {
     pub const fn from_secs_f64(secs: f64) -> Duration {
         match Duration::try_from_secs_f64(secs) {
             Ok(v) => v,
-            Err(e) => crate::panicking::panic(e.description()),
+            Err(e) => panic!("{}", e.description()),
         }
     }
 
@@ -788,7 +788,7 @@ impl Duration {
     pub const fn from_secs_f32(secs: f32) -> Duration {
         match Duration::try_from_secs_f32(secs) {
             Ok(v) => v,
-            Err(e) => crate::panicking::panic(e.description()),
+            Err(e) => panic!("{}", e.description()),
         }
     }
 
diff --git a/src/test/ui/consts/const-eval/const_panic_stability.e2018.stderr b/src/test/ui/consts/const-eval/const_panic_stability.e2018.stderr
new file mode 100644
index 00000000000..94cf64fff19
--- /dev/null
+++ b/src/test/ui/consts/const-eval/const_panic_stability.e2018.stderr
@@ -0,0 +1,16 @@
+warning: panic message is not a string literal
+  --> $DIR/const_panic_stability.rs:14:12
+   |
+LL |     panic!({ "foo" });
+   |            ^^^^^^^^^
+   |
+   = note: `#[warn(non_fmt_panics)]` on by default
+   = note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
+   = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
+help: add a "{}" format string to Display the message
+   |
+LL |     panic!("{}", { "foo" });
+   |            +++++
+
+warning: 1 warning emitted
+
diff --git a/src/test/ui/consts/const-eval/const_panic_stability.e2021.stderr b/src/test/ui/consts/const-eval/const_panic_stability.e2021.stderr
new file mode 100644
index 00000000000..9e8179181fd
--- /dev/null
+++ b/src/test/ui/consts/const-eval/const_panic_stability.e2021.stderr
@@ -0,0 +1,13 @@
+error: format argument must be a string literal
+  --> $DIR/const_panic_stability.rs:14:12
+   |
+LL |     panic!({ "foo" });
+   |            ^^^^^^^^^
+   |
+help: you might be missing a string literal to format with
+   |
+LL |     panic!("{}", { "foo" });
+   |            +++++
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/consts/const-eval/const_panic_stability.rs b/src/test/ui/consts/const-eval/const_panic_stability.rs
new file mode 100644
index 00000000000..1aee6f27e27
--- /dev/null
+++ b/src/test/ui/consts/const-eval/const_panic_stability.rs
@@ -0,0 +1,17 @@
+// revisions: e2018 e2021
+//[e2018] edition:2018
+//[e2021] edition:2021
+//[e2018] check-pass
+#![crate_type = "lib"]
+#![stable(feature = "foo", since = "1.0.0")]
+#![feature(staged_api)]
+
+#[stable(feature = "foo", since = "1.0.0")]
+#[rustc_const_stable(feature = "foo", since = "1.0.0")]
+const fn foo() {
+    assert!(false);
+    assert!(false, "foo");
+    panic!({ "foo" });
+    //[e2018]~^ WARNING panic message is not a string literal
+    //[e2021]~^^ ERROR format argument must be a string literal
+}