about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2020-07-16 21:02:34 +0200
committerMara Bos <m-ou.se@m-ou.se>2020-07-17 17:56:55 +0200
commit0c51f53edfee0d3d4fd1969f95301dd562a73646 (patch)
tree15cac9373c8bfe94f7c6208dd75c7e00bff3920d /src/libcore
parente17c17a1af4cd7dee069088c7ae682480179e810 (diff)
downloadrust-0c51f53edfee0d3d4fd1969f95301dd562a73646.tar.gz
rust-0c51f53edfee0d3d4fd1969f95301dd562a73646.zip
Make fmt::Arguments::as_str() return a 'static str.
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/fmt/mod.rs8
-rw-r--r--src/libcore/macros/mod.rs5
-rw-r--r--src/libcore/panicking.rs2
3 files changed, 9 insertions, 6 deletions
diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs
index d16f8b5ac9a..6c2f321834a 100644
--- a/src/libcore/fmt/mod.rs
+++ b/src/libcore/fmt/mod.rs
@@ -324,7 +324,7 @@ impl<'a> Arguments<'a> {
     #[doc(hidden)]
     #[inline]
     #[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")]
-    pub fn new_v1(pieces: &'a [&'a str], args: &'a [ArgumentV1<'a>]) -> Arguments<'a> {
+    pub fn new_v1(pieces: &'a [&'static str], args: &'a [ArgumentV1<'a>]) -> Arguments<'a> {
         Arguments { pieces, fmt: None, args }
     }
 
@@ -338,7 +338,7 @@ impl<'a> Arguments<'a> {
     #[inline]
     #[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")]
     pub fn new_v1_formatted(
-        pieces: &'a [&'a str],
+        pieces: &'a [&'static str],
         args: &'a [ArgumentV1<'a>],
         fmt: &'a [rt::v1::Argument],
     ) -> Arguments<'a> {
@@ -399,7 +399,7 @@ impl<'a> Arguments<'a> {
 #[derive(Copy, Clone)]
 pub struct Arguments<'a> {
     // Format string pieces to print.
-    pieces: &'a [&'a str],
+    pieces: &'a [&'static str],
 
     // Placeholder specs, or `None` if all specs are default (as in "{}{}").
     fmt: Option<&'a [rt::v1::Argument]>,
@@ -441,7 +441,7 @@ impl<'a> Arguments<'a> {
     /// ```
     #[unstable(feature = "fmt_as_str", issue = "none")]
     #[inline]
-    pub fn as_str(&self) -> Option<&'a str> {
+    pub fn as_str(&self) -> Option<&'static str> {
         match (self.pieces, self.args) {
             ([], []) => Some(""),
             ([s], []) => Some(s),
diff --git a/src/libcore/macros/mod.rs b/src/libcore/macros/mod.rs
index 17f7349bac2..4ac366ab164 100644
--- a/src/libcore/macros/mod.rs
+++ b/src/libcore/macros/mod.rs
@@ -6,9 +6,12 @@ macro_rules! panic {
     () => (
         $crate::panic!("explicit panic")
     );
-    ($msg:expr) => (
+    ($msg:literal) => (
         $crate::panicking::panic($msg)
     );
+    ($msg:expr) => (
+        $crate::panic!("{}", $crate::convert::identity::<&str>($msg))
+    );
     ($msg:expr,) => (
         $crate::panic!($msg)
     );
diff --git a/src/libcore/panicking.rs b/src/libcore/panicking.rs
index 766c69a5f94..15fd638bef8 100644
--- a/src/libcore/panicking.rs
+++ b/src/libcore/panicking.rs
@@ -36,7 +36,7 @@ use crate::panic::{Location, PanicInfo};
 #[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
 #[track_caller]
 #[lang = "panic"] // needed by codegen for panic on overflow and other `Assert` MIR terminators
-pub fn panic(expr: &str) -> ! {
+pub fn panic(expr: &'static str) -> ! {
     if cfg!(feature = "panic_immediate_abort") {
         super::intrinsics::abort()
     }