File tree Expand file tree Collapse file tree 3 files changed +18
-11
lines changed Expand file tree Collapse file tree 3 files changed +18
-11
lines changed Original file line number Diff line number Diff line change 116116#![ feature( exact_size_is_empty) ]
117117#![ feature( extend_one) ]
118118#![ feature( extend_one_unchecked) ]
119+ #![ feature( fmt_arguments_from_str) ]
119120#![ feature( fmt_internals) ]
120121#![ feature( fn_traits) ]
121122#![ feature( formatting_options) ]
Original file line number Diff line number Diff line change @@ -734,7 +734,21 @@ impl<'a> Arguments<'a> {
734734 unsafe { Arguments { template : mem:: transmute ( template) , args : mem:: transmute ( args) } }
735735 }
736736
737+ // Same as `from_str`, but not const.
738+ // Used by format_args!() expansion when arguments are inlined,
739+ // e.g. format_args!("{}", 123), which is not allowed in const.
737740 #[ inline]
741+ pub fn from_str_nonconst ( s : & ' static str ) -> Arguments < ' a > {
742+ Arguments :: from_str ( s)
743+ }
744+ }
745+
746+ impl < ' a > Arguments < ' a > {
747+ /// Create a `fmt::Arguments` object for a single static string.
748+ ///
749+ /// Formatting this `fmt::Arguments` will just produce the string as-is.
750+ #[ inline]
751+ #[ unstable( feature = "fmt_arguments_from_str" , issue = "148905" ) ]
738752 pub const fn from_str ( s : & ' static str ) -> Arguments < ' a > {
739753 // SAFETY: This is the "static str" representation of fmt::Arguments; see above.
740754 unsafe {
@@ -744,14 +758,6 @@ impl<'a> Arguments<'a> {
744758 }
745759 }
746760 }
747-
748- // Same as `from_str`, but not const.
749- // Used by format_args!() expansion when arguments are inlined,
750- // e.g. format_args!("{}", 123), which is not allowed in const.
751- #[ inline]
752- pub fn from_str_nonconst ( s : & ' static str ) -> Arguments < ' a > {
753- Arguments :: from_str ( s)
754- }
755761}
756762
757763#[ doc( hidden) ]
Original file line number Diff line number Diff line change @@ -991,7 +991,7 @@ pub(crate) mod builtin {
991991 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
992992 #[ rustc_diagnostic_item = "format_args_macro" ]
993993 #[ allow_internal_unsafe]
994- #[ allow_internal_unstable( fmt_internals) ]
994+ #[ allow_internal_unstable( fmt_internals, fmt_arguments_from_str ) ]
995995 #[ rustc_builtin_macro]
996996 #[ macro_export]
997997 macro_rules! format_args {
@@ -1005,7 +1005,7 @@ pub(crate) mod builtin {
10051005 ///
10061006 /// This macro will be removed once `format_args` is allowed in const contexts.
10071007 #[ unstable( feature = "const_format_args" , issue = "none" ) ]
1008- #[ allow_internal_unstable( fmt_internals, const_fmt_arguments_new ) ]
1008+ #[ allow_internal_unstable( fmt_internals, fmt_arguments_from_str ) ]
10091009 #[ rustc_builtin_macro]
10101010 #[ macro_export]
10111011 macro_rules! const_format_args {
@@ -1020,7 +1020,7 @@ pub(crate) mod builtin {
10201020 reason = "`format_args_nl` is only for internal \
10211021 language use and is subject to change"
10221022 ) ]
1023- #[ allow_internal_unstable( fmt_internals) ]
1023+ #[ allow_internal_unstable( fmt_internals, fmt_arguments_from_str ) ]
10241024 #[ rustc_builtin_macro]
10251025 #[ doc( hidden) ]
10261026 #[ macro_export]
You can’t perform that action at this time.
0 commit comments