Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
#![feature(exact_size_is_empty)]
#![feature(extend_one)]
#![feature(extend_one_unchecked)]
#![feature(fmt_arguments_from_str)]
#![feature(fmt_internals)]
#![feature(fn_traits)]
#![feature(formatting_options)]
Expand Down
22 changes: 14 additions & 8 deletions library/core/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,21 @@ impl<'a> Arguments<'a> {
unsafe { Arguments { template: mem::transmute(template), args: mem::transmute(args) } }
}

// Same as `from_str`, but not const.
// Used by format_args!() expansion when arguments are inlined,
// e.g. format_args!("{}", 123), which is not allowed in const.
#[inline]
pub fn from_str_nonconst(s: &'static str) -> Arguments<'a> {
Arguments::from_str(s)
}
}

impl<'a> Arguments<'a> {
/// Create a `fmt::Arguments` object for a single static string.
///
/// Formatting this `fmt::Arguments` will just produce the string as-is.
#[inline]
#[unstable(feature = "fmt_arguments_from_str", issue = "148905")]
pub const fn from_str(s: &'static str) -> Arguments<'a> {
// SAFETY: This is the "static str" representation of fmt::Arguments; see above.
unsafe {
Expand All @@ -744,14 +758,6 @@ impl<'a> Arguments<'a> {
}
}
}

// Same as `from_str`, but not const.
// Used by format_args!() expansion when arguments are inlined,
// e.g. format_args!("{}", 123), which is not allowed in const.
#[inline]
pub fn from_str_nonconst(s: &'static str) -> Arguments<'a> {
Arguments::from_str(s)
}
}

#[doc(hidden)]
Expand Down
6 changes: 3 additions & 3 deletions library/core/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ pub(crate) mod builtin {
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_diagnostic_item = "format_args_macro"]
#[allow_internal_unsafe]
#[allow_internal_unstable(fmt_internals)]
#[allow_internal_unstable(fmt_internals, fmt_arguments_from_str)]
#[rustc_builtin_macro]
#[macro_export]
macro_rules! format_args {
Expand All @@ -1005,7 +1005,7 @@ pub(crate) mod builtin {
///
/// This macro will be removed once `format_args` is allowed in const contexts.
#[unstable(feature = "const_format_args", issue = "none")]
#[allow_internal_unstable(fmt_internals, const_fmt_arguments_new)]
#[allow_internal_unstable(fmt_internals, fmt_arguments_from_str)]
#[rustc_builtin_macro]
#[macro_export]
macro_rules! const_format_args {
Expand All @@ -1020,7 +1020,7 @@ pub(crate) mod builtin {
reason = "`format_args_nl` is only for internal \
language use and is subject to change"
)]
#[allow_internal_unstable(fmt_internals)]
#[allow_internal_unstable(fmt_internals, fmt_arguments_from_str)]
#[rustc_builtin_macro]
#[doc(hidden)]
#[macro_export]
Expand Down
Loading