1
Fork 0

Remove "V1" from ArgumentsV1 and FlagsV1.

This commit is contained in:
Mara Bos 2023-04-20 19:53:16 +02:00
parent 64bcb32651
commit 5cf3cbf3b7
6 changed files with 40 additions and 41 deletions

View file

@ -186,7 +186,7 @@ enum ArgumentType {
/// Generates: /// Generates:
/// ///
/// ```text /// ```text
/// <core::fmt::ArgumentV1>::new_…(arg) /// <core::fmt::Argument>::new_…(arg)
/// ``` /// ```
fn make_argument<'hir>( fn make_argument<'hir>(
ctx: &mut LoweringContext<'_, 'hir>, ctx: &mut LoweringContext<'_, 'hir>,
@ -327,7 +327,7 @@ fn make_format_spec<'hir>(
None => sym::Unknown, None => sym::Unknown,
}, },
); );
// This needs to match `FlagV1` in library/core/src/fmt/mod.rs. // This needs to match `Flag` in library/core/src/fmt/mod.rs.
let flags: u32 = ((sign == Some(FormatSign::Plus)) as u32) let flags: u32 = ((sign == Some(FormatSign::Plus)) as u32)
| ((sign == Some(FormatSign::Minus)) as u32) << 1 | ((sign == Some(FormatSign::Minus)) as u32) << 1
| (alternate as u32) << 2 | (alternate as u32) << 2
@ -438,7 +438,7 @@ fn expand_format_args<'hir>(
// If the args array contains exactly all the original arguments once, // If the args array contains exactly all the original arguments once,
// in order, we can use a simple array instead of a `match` construction. // in order, we can use a simple array instead of a `match` construction.
// However, if there's a yield point in any argument except the first one, // However, if there's a yield point in any argument except the first one,
// we don't do this, because an ArgumentV1 cannot be kept across yield points. // we don't do this, because an Argument cannot be kept across yield points.
// //
// This is an optimization, speeding up compilation about 1-2% in some cases. // This is an optimization, speeding up compilation about 1-2% in some cases.
// See https://github.com/rust-lang/rust/pull/106770#issuecomment-1380790609 // See https://github.com/rust-lang/rust/pull/106770#issuecomment-1380790609
@ -449,9 +449,9 @@ fn expand_format_args<'hir>(
let args = if use_simple_array { let args = if use_simple_array {
// Generate: // Generate:
// &[ // &[
// <core::fmt::ArgumentV1>::new_display(&arg0), // <core::fmt::Argument>::new_display(&arg0),
// <core::fmt::ArgumentV1>::new_lower_hex(&arg1), // <core::fmt::Argument>::new_lower_hex(&arg1),
// <core::fmt::ArgumentV1>::new_debug(&arg2), // <core::fmt::Argument>::new_debug(&arg2),
// … // …
// ] // ]
let elements: Vec<_> = arguments let elements: Vec<_> = arguments
@ -477,9 +477,9 @@ fn expand_format_args<'hir>(
// Generate: // Generate:
// &match (&arg0, &arg1, &…) { // &match (&arg0, &arg1, &…) {
// args => [ // args => [
// <core::fmt::ArgumentV1>::new_display(args.0), // <core::fmt::Argument>::new_display(args.0),
// <core::fmt::ArgumentV1>::new_lower_hex(args.1), // <core::fmt::Argument>::new_lower_hex(args.1),
// <core::fmt::ArgumentV1>::new_debug(args.0), // <core::fmt::Argument>::new_debug(args.0),
// … // …
// ] // ]
// } // }

View file

@ -296,7 +296,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
diag_trait(&mut err, self_ty, tcx.require_lang_item(LangItem::Deref, Some(span))); diag_trait(&mut err, self_ty, tcx.require_lang_item(LangItem::Deref, Some(span)));
err err
} }
_ if tcx.opt_parent(callee) == tcx.get_diagnostic_item(sym::ArgumentV1Methods) => ccx _ if tcx.opt_parent(callee) == tcx.get_diagnostic_item(sym::ArgumentMethods) => ccx
.tcx .tcx
.sess .sess
.create_err(errors::NonConstFmtMacroCall { span, kind: ccx.const_kind() }), .create_err(errors::NonConstFmtMacroCall { span, kind: ccx.const_kind() }),

View file

@ -129,8 +129,7 @@ symbols! {
Any, Any,
Arc, Arc,
Argument, Argument,
ArgumentV1, ArgumentMethods,
ArgumentV1Methods,
Arguments, Arguments,
AsMut, AsMut,
AsRef, AsRef,

View file

@ -267,7 +267,7 @@ extern "C" {
#[allow(missing_debug_implementations)] #[allow(missing_debug_implementations)]
#[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")] #[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")]
#[doc(hidden)] #[doc(hidden)]
pub struct ArgumentV1<'a> { pub struct Argument<'a> {
value: &'a Opaque, value: &'a Opaque,
formatter: fn(&Opaque, &mut Formatter<'_>) -> Result, formatter: fn(&Opaque, &mut Formatter<'_>) -> Result,
} }
@ -321,18 +321,18 @@ macro_rules! arg_new {
#[doc(hidden)] #[doc(hidden)]
#[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")] #[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")]
#[inline] #[inline]
pub fn $f<'b, T: $t>(x: &'b T) -> ArgumentV1<'_> { pub fn $f<'b, T: $t>(x: &'b T) -> Argument<'_> {
Self::new(x, $t::fmt) Self::new(x, $t::fmt)
} }
}; };
} }
#[rustc_diagnostic_item = "ArgumentV1Methods"] #[rustc_diagnostic_item = "ArgumentMethods"]
impl<'a> ArgumentV1<'a> { impl<'a> Argument<'a> {
#[doc(hidden)] #[doc(hidden)]
#[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")] #[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")]
#[inline] #[inline]
pub fn new<'b, T>(x: &'b T, f: fn(&T, &mut Formatter<'_>) -> Result) -> ArgumentV1<'b> { pub fn new<'b, T>(x: &'b T, f: fn(&T, &mut Formatter<'_>) -> Result) -> Argument<'b> {
// SAFETY: `mem::transmute(x)` is safe because // SAFETY: `mem::transmute(x)` is safe because
// 1. `&'b T` keeps the lifetime it originated with `'b` // 1. `&'b T` keeps the lifetime it originated with `'b`
// (so as to not have an unbounded lifetime) // (so as to not have an unbounded lifetime)
@ -341,7 +341,7 @@ impl<'a> ArgumentV1<'a> {
// `mem::transmute(f)` is safe since `fn(&T, &mut Formatter<'_>) -> Result` // `mem::transmute(f)` is safe since `fn(&T, &mut Formatter<'_>) -> Result`
// and `fn(&Opaque, &mut Formatter<'_>) -> Result` have the same ABI // and `fn(&Opaque, &mut Formatter<'_>) -> Result` have the same ABI
// (as long as `T` is `Sized`) // (as long as `T` is `Sized`)
unsafe { ArgumentV1 { formatter: mem::transmute(f), value: mem::transmute(x) } } unsafe { Argument { formatter: mem::transmute(f), value: mem::transmute(x) } }
} }
arg_new!(new_display, Display); arg_new!(new_display, Display);
@ -356,8 +356,8 @@ impl<'a> ArgumentV1<'a> {
#[doc(hidden)] #[doc(hidden)]
#[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")] #[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")]
pub fn from_usize(x: &usize) -> ArgumentV1<'_> { pub fn from_usize(x: &usize) -> Argument<'_> {
ArgumentV1::new(x, USIZE_MARKER) Argument::new(x, USIZE_MARKER)
} }
fn as_usize(&self) -> Option<usize> { fn as_usize(&self) -> Option<usize> {
@ -377,7 +377,7 @@ impl<'a> ArgumentV1<'a> {
// flags available in the v1 format of format_args // flags available in the v1 format of format_args
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
enum FlagV1 { enum Flag {
SignPlus, SignPlus,
SignMinus, SignMinus,
Alternate, Alternate,
@ -404,7 +404,7 @@ impl<'a> Arguments<'a> {
#[doc(hidden)] #[doc(hidden)]
#[inline] #[inline]
#[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")] #[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")]
pub fn new_v1(pieces: &'a [&'static str], args: &'a [ArgumentV1<'a>]) -> Arguments<'a> { pub fn new_v1(pieces: &'a [&'static str], args: &'a [Argument<'a>]) -> Arguments<'a> {
if pieces.len() < args.len() || pieces.len() > args.len() + 1 { if pieces.len() < args.len() || pieces.len() > args.len() + 1 {
panic!("invalid args"); panic!("invalid args");
} }
@ -416,7 +416,7 @@ impl<'a> Arguments<'a> {
#[inline] #[inline]
#[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")] #[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")]
#[rustc_const_unstable(feature = "const_fmt_arguments_new", issue = "none")] #[rustc_const_unstable(feature = "const_fmt_arguments_new", issue = "none")]
pub const fn new_v1(pieces: &'a [&'static str], args: &'a [ArgumentV1<'a>]) -> Arguments<'a> { pub const fn new_v1(pieces: &'a [&'static str], args: &'a [Argument<'a>]) -> Arguments<'a> {
if pieces.len() < args.len() || pieces.len() > args.len() + 1 { if pieces.len() < args.len() || pieces.len() > args.len() + 1 {
panic!("invalid args"); panic!("invalid args");
} }
@ -435,7 +435,7 @@ impl<'a> Arguments<'a> {
#[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")] #[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")]
pub fn new_v1_formatted( pub fn new_v1_formatted(
pieces: &'a [&'static str], pieces: &'a [&'static str],
args: &'a [ArgumentV1<'a>], args: &'a [Argument<'a>],
fmt: &'a [rt::Placeholder], fmt: &'a [rt::Placeholder],
_unsafe_arg: UnsafeArg, _unsafe_arg: UnsafeArg,
) -> Arguments<'a> { ) -> Arguments<'a> {
@ -502,7 +502,7 @@ pub struct Arguments<'a> {
// Dynamic arguments for interpolation, to be interleaved with string // Dynamic arguments for interpolation, to be interleaved with string
// pieces. (Every argument is preceded by a string piece.) // pieces. (Every argument is preceded by a string piece.)
args: &'a [ArgumentV1<'a>], args: &'a [Argument<'a>],
} }
impl<'a> Arguments<'a> { impl<'a> Arguments<'a> {
@ -1274,7 +1274,7 @@ pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result {
Ok(()) Ok(())
} }
unsafe fn run(fmt: &mut Formatter<'_>, arg: &rt::Placeholder, args: &[ArgumentV1<'_>]) -> Result { unsafe fn run(fmt: &mut Formatter<'_>, arg: &rt::Placeholder, args: &[Argument<'_>]) -> Result {
fmt.fill = arg.fill; fmt.fill = arg.fill;
fmt.align = arg.align; fmt.align = arg.align;
fmt.flags = arg.flags; fmt.flags = arg.flags;
@ -1295,7 +1295,7 @@ unsafe fn run(fmt: &mut Formatter<'_>, arg: &rt::Placeholder, args: &[ArgumentV1
(value.formatter)(value.value, fmt) (value.formatter)(value.value, fmt)
} }
unsafe fn getcount(args: &[ArgumentV1<'_>], cnt: &rt::Count) -> Option<usize> { unsafe fn getcount(args: &[Argument<'_>], cnt: &rt::Count) -> Option<usize> {
match *cnt { match *cnt {
rt::Count::Is(n) => Some(n), rt::Count::Is(n) => Some(n),
rt::Count::Implied => None, rt::Count::Implied => None,
@ -1878,7 +1878,7 @@ impl<'a> Formatter<'a> {
#[must_use] #[must_use]
#[stable(feature = "fmt_flags", since = "1.5.0")] #[stable(feature = "fmt_flags", since = "1.5.0")]
pub fn sign_plus(&self) -> bool { pub fn sign_plus(&self) -> bool {
self.flags & (1 << FlagV1::SignPlus as u32) != 0 self.flags & (1 << Flag::SignPlus as u32) != 0
} }
/// Determines if the `-` flag was specified. /// Determines if the `-` flag was specified.
@ -1907,7 +1907,7 @@ impl<'a> Formatter<'a> {
#[must_use] #[must_use]
#[stable(feature = "fmt_flags", since = "1.5.0")] #[stable(feature = "fmt_flags", since = "1.5.0")]
pub fn sign_minus(&self) -> bool { pub fn sign_minus(&self) -> bool {
self.flags & (1 << FlagV1::SignMinus as u32) != 0 self.flags & (1 << Flag::SignMinus as u32) != 0
} }
/// Determines if the `#` flag was specified. /// Determines if the `#` flag was specified.
@ -1935,7 +1935,7 @@ impl<'a> Formatter<'a> {
#[must_use] #[must_use]
#[stable(feature = "fmt_flags", since = "1.5.0")] #[stable(feature = "fmt_flags", since = "1.5.0")]
pub fn alternate(&self) -> bool { pub fn alternate(&self) -> bool {
self.flags & (1 << FlagV1::Alternate as u32) != 0 self.flags & (1 << Flag::Alternate as u32) != 0
} }
/// Determines if the `0` flag was specified. /// Determines if the `0` flag was specified.
@ -1961,17 +1961,17 @@ impl<'a> Formatter<'a> {
#[must_use] #[must_use]
#[stable(feature = "fmt_flags", since = "1.5.0")] #[stable(feature = "fmt_flags", since = "1.5.0")]
pub fn sign_aware_zero_pad(&self) -> bool { pub fn sign_aware_zero_pad(&self) -> bool {
self.flags & (1 << FlagV1::SignAwareZeroPad as u32) != 0 self.flags & (1 << Flag::SignAwareZeroPad as u32) != 0
} }
// FIXME: Decide what public API we want for these two flags. // FIXME: Decide what public API we want for these two flags.
// https://github.com/rust-lang/rust/issues/48584 // https://github.com/rust-lang/rust/issues/48584
fn debug_lower_hex(&self) -> bool { fn debug_lower_hex(&self) -> bool {
self.flags & (1 << FlagV1::DebugLowerHex as u32) != 0 self.flags & (1 << Flag::DebugLowerHex as u32) != 0
} }
fn debug_upper_hex(&self) -> bool { fn debug_upper_hex(&self) -> bool {
self.flags & (1 << FlagV1::DebugUpperHex as u32) != 0 self.flags & (1 << Flag::DebugUpperHex as u32) != 0
} }
/// Creates a [`DebugStruct`] builder designed to assist with creation of /// Creates a [`DebugStruct`] builder designed to assist with creation of
@ -2531,13 +2531,13 @@ pub(crate) fn pointer_fmt_inner(ptr_addr: usize, f: &mut Formatter<'_>) -> Resul
// or not to zero extend, and then unconditionally set it to get the // or not to zero extend, and then unconditionally set it to get the
// prefix. // prefix.
if f.alternate() { if f.alternate() {
f.flags |= 1 << (FlagV1::SignAwareZeroPad as u32); f.flags |= 1 << (Flag::SignAwareZeroPad as u32);
if f.width.is_none() { if f.width.is_none() {
f.width = Some((usize::BITS / 4) as usize + 2); f.width = Some((usize::BITS / 4) as usize + 2);
} }
} }
f.flags |= 1 << (FlagV1::Alternate as u32); f.flags |= 1 << (Flag::Alternate as u32);
let ret = LowerHex::fmt(&ptr_addr, f); let ret = LowerHex::fmt(&ptr_addr, f);

View file

@ -201,7 +201,7 @@ macro_rules! format_args {
} }
fn main() { fn main() {
$crate::fmt::Arguments::new_v1(&[], &[$crate::fmt::ArgumentV1::new(&(arg1(a, b, c)), $crate::fmt::Display::fmt), $crate::fmt::ArgumentV1::new(&(arg2), $crate::fmt::Display::fmt), ]); $crate::fmt::Arguments::new_v1(&[], &[$crate::fmt::Argument::new(&(arg1(a, b, c)), $crate::fmt::Display::fmt), $crate::fmt::Argument::new(&(arg2), $crate::fmt::Display::fmt), ]);
} }
"#]], "#]],
); );
@ -229,7 +229,7 @@ macro_rules! format_args {
} }
fn main() { fn main() {
$crate::fmt::Arguments::new_v1(&[], &[$crate::fmt::ArgumentV1::new(&(a::<A, B>()), $crate::fmt::Display::fmt), $crate::fmt::ArgumentV1::new(&(b), $crate::fmt::Display::fmt), ]); $crate::fmt::Arguments::new_v1(&[], &[$crate::fmt::Argument::new(&(a::<A, B>()), $crate::fmt::Display::fmt), $crate::fmt::Argument::new(&(b), $crate::fmt::Display::fmt), ]);
} }
"#]], "#]],
); );
@ -260,7 +260,7 @@ macro_rules! format_args {
fn main() { fn main() {
let _ = let _ =
/* parse error: expected field name or number */ /* parse error: expected field name or number */
$crate::fmt::Arguments::new_v1(&[], &[$crate::fmt::ArgumentV1::new(&(a.), $crate::fmt::Display::fmt), ]); $crate::fmt::Arguments::new_v1(&[], &[$crate::fmt::Argument::new(&(a.), $crate::fmt::Display::fmt), ]);
} }
"#]], "#]],
); );

View file

@ -241,8 +241,8 @@ fn format_args_expand(
// We expand `format_args!("", a1, a2)` to // We expand `format_args!("", a1, a2)` to
// ``` // ```
// $crate::fmt::Arguments::new_v1(&[], &[ // $crate::fmt::Arguments::new_v1(&[], &[
// $crate::fmt::ArgumentV1::new(&arg1,$crate::fmt::Display::fmt), // $crate::fmt::Argument::new(&arg1,$crate::fmt::Display::fmt),
// $crate::fmt::ArgumentV1::new(&arg2,$crate::fmt::Display::fmt), // $crate::fmt::Argument::new(&arg2,$crate::fmt::Display::fmt),
// ]) // ])
// ```, // ```,
// which is still not really correct, but close enough for now // which is still not really correct, but close enough for now
@ -267,7 +267,7 @@ fn format_args_expand(
} }
let _format_string = args.remove(0); let _format_string = args.remove(0);
let arg_tts = args.into_iter().flat_map(|arg| { let arg_tts = args.into_iter().flat_map(|arg| {
quote! { #DOLLAR_CRATE::fmt::ArgumentV1::new(&(#arg), #DOLLAR_CRATE::fmt::Display::fmt), } quote! { #DOLLAR_CRATE::fmt::Argument::new(&(#arg), #DOLLAR_CRATE::fmt::Display::fmt), }
}.token_trees); }.token_trees);
let expanded = quote! { let expanded = quote! {
#DOLLAR_CRATE::fmt::Arguments::new_v1(&[], &[##arg_tts]) #DOLLAR_CRATE::fmt::Arguments::new_v1(&[], &[##arg_tts])