Skip to content

Commit 0c51f53

Browse files
committed
Make fmt::Arguments::as_str() return a 'static str.
1 parent e17c17a commit 0c51f53

File tree

6 files changed

+282
-291
lines changed

6 files changed

+282
-291
lines changed

src/libcore/fmt/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ impl<'a> Arguments<'a> {
324324
#[doc(hidden)]
325325
#[inline]
326326
#[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")]
327-
pub fn new_v1(pieces: &'a [&'a str], args: &'a [ArgumentV1<'a>]) -> Arguments<'a> {
327+
pub fn new_v1(pieces: &'a [&'static str], args: &'a [ArgumentV1<'a>]) -> Arguments<'a> {
328328
Arguments { pieces, fmt: None, args }
329329
}
330330

@@ -338,7 +338,7 @@ impl<'a> Arguments<'a> {
338338
#[inline]
339339
#[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")]
340340
pub fn new_v1_formatted(
341-
pieces: &'a [&'a str],
341+
pieces: &'a [&'static str],
342342
args: &'a [ArgumentV1<'a>],
343343
fmt: &'a [rt::v1::Argument],
344344
) -> Arguments<'a> {
@@ -399,7 +399,7 @@ impl<'a> Arguments<'a> {
399399
#[derive(Copy, Clone)]
400400
pub struct Arguments<'a> {
401401
// Format string pieces to print.
402-
pieces: &'a [&'a str],
402+
pieces: &'a [&'static str],
403403

404404
// Placeholder specs, or `None` if all specs are default (as in "{}{}").
405405
fmt: Option<&'a [rt::v1::Argument]>,
@@ -441,7 +441,7 @@ impl<'a> Arguments<'a> {
441441
/// ```
442442
#[unstable(feature = "fmt_as_str", issue = "none")]
443443
#[inline]
444-
pub fn as_str(&self) -> Option<&'a str> {
444+
pub fn as_str(&self) -> Option<&'static str> {
445445
match (self.pieces, self.args) {
446446
([], []) => Some(""),
447447
([s], []) => Some(s),

src/libcore/macros/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ macro_rules! panic {
66
() => (
77
$crate::panic!("explicit panic")
88
);
9-
($msg:expr) => (
9+
($msg:literal) => (
1010
$crate::panicking::panic($msg)
1111
);
12+
($msg:expr) => (
13+
$crate::panic!("{}", $crate::convert::identity::<&str>($msg))
14+
);
1215
($msg:expr,) => (
1316
$crate::panic!($msg)
1417
);

src/libcore/panicking.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use crate::panic::{Location, PanicInfo};
3636
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
3737
#[track_caller]
3838
#[lang = "panic"] // needed by codegen for panic on overflow and other `Assert` MIR terminators
39-
pub fn panic(expr: &str) -> ! {
39+
pub fn panic(expr: &'static str) -> ! {
4040
if cfg!(feature = "panic_immediate_abort") {
4141
super::intrinsics::abort()
4242
}

0 commit comments

Comments
 (0)