Skip to content

Commit 5cf3cbf

Browse files
committed
Remove "V1" from ArgumentsV1 and FlagsV1.
1 parent 64bcb32 commit 5cf3cbf

File tree

6 files changed

+40
-41
lines changed

6 files changed

+40
-41
lines changed

compiler/rustc_ast_lowering/src/format.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ enum ArgumentType {
186186
/// Generates:
187187
///
188188
/// ```text
189-
/// <core::fmt::ArgumentV1>::new_…(arg)
189+
/// <core::fmt::Argument>::new_…(arg)
190190
/// ```
191191
fn make_argument<'hir>(
192192
ctx: &mut LoweringContext<'_, 'hir>,
@@ -327,7 +327,7 @@ fn make_format_spec<'hir>(
327327
None => sym::Unknown,
328328
},
329329
);
330-
// This needs to match `FlagV1` in library/core/src/fmt/mod.rs.
330+
// This needs to match `Flag` in library/core/src/fmt/mod.rs.
331331
let flags: u32 = ((sign == Some(FormatSign::Plus)) as u32)
332332
| ((sign == Some(FormatSign::Minus)) as u32) << 1
333333
| (alternate as u32) << 2
@@ -438,7 +438,7 @@ fn expand_format_args<'hir>(
438438
// If the args array contains exactly all the original arguments once,
439439
// in order, we can use a simple array instead of a `match` construction.
440440
// However, if there's a yield point in any argument except the first one,
441-
// we don't do this, because an ArgumentV1 cannot be kept across yield points.
441+
// we don't do this, because an Argument cannot be kept across yield points.
442442
//
443443
// This is an optimization, speeding up compilation about 1-2% in some cases.
444444
// See https://github.com/rust-lang/rust/pull/106770#issuecomment-1380790609
@@ -449,9 +449,9 @@ fn expand_format_args<'hir>(
449449
let args = if use_simple_array {
450450
// Generate:
451451
// &[
452-
// <core::fmt::ArgumentV1>::new_display(&arg0),
453-
// <core::fmt::ArgumentV1>::new_lower_hex(&arg1),
454-
// <core::fmt::ArgumentV1>::new_debug(&arg2),
452+
// <core::fmt::Argument>::new_display(&arg0),
453+
// <core::fmt::Argument>::new_lower_hex(&arg1),
454+
// <core::fmt::Argument>::new_debug(&arg2),
455455
// …
456456
// ]
457457
let elements: Vec<_> = arguments
@@ -477,9 +477,9 @@ fn expand_format_args<'hir>(
477477
// Generate:
478478
// &match (&arg0, &arg1, &…) {
479479
// args => [
480-
// <core::fmt::ArgumentV1>::new_display(args.0),
481-
// <core::fmt::ArgumentV1>::new_lower_hex(args.1),
482-
// <core::fmt::ArgumentV1>::new_debug(args.0),
480+
// <core::fmt::Argument>::new_display(args.0),
481+
// <core::fmt::Argument>::new_lower_hex(args.1),
482+
// <core::fmt::Argument>::new_debug(args.0),
483483
// …
484484
// ]
485485
// }

compiler/rustc_const_eval/src/transform/check_consts/ops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
296296
diag_trait(&mut err, self_ty, tcx.require_lang_item(LangItem::Deref, Some(span)));
297297
err
298298
}
299-
_ if tcx.opt_parent(callee) == tcx.get_diagnostic_item(sym::ArgumentV1Methods) => ccx
299+
_ if tcx.opt_parent(callee) == tcx.get_diagnostic_item(sym::ArgumentMethods) => ccx
300300
.tcx
301301
.sess
302302
.create_err(errors::NonConstFmtMacroCall { span, kind: ccx.const_kind() }),

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ symbols! {
129129
Any,
130130
Arc,
131131
Argument,
132-
ArgumentV1,
133-
ArgumentV1Methods,
132+
ArgumentMethods,
134133
Arguments,
135134
AsMut,
136135
AsRef,

library/core/src/fmt/mod.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ extern "C" {
267267
#[allow(missing_debug_implementations)]
268268
#[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")]
269269
#[doc(hidden)]
270-
pub struct ArgumentV1<'a> {
270+
pub struct Argument<'a> {
271271
value: &'a Opaque,
272272
formatter: fn(&Opaque, &mut Formatter<'_>) -> Result,
273273
}
@@ -321,18 +321,18 @@ macro_rules! arg_new {
321321
#[doc(hidden)]
322322
#[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")]
323323
#[inline]
324-
pub fn $f<'b, T: $t>(x: &'b T) -> ArgumentV1<'_> {
324+
pub fn $f<'b, T: $t>(x: &'b T) -> Argument<'_> {
325325
Self::new(x, $t::fmt)
326326
}
327327
};
328328
}
329329

330-
#[rustc_diagnostic_item = "ArgumentV1Methods"]
331-
impl<'a> ArgumentV1<'a> {
330+
#[rustc_diagnostic_item = "ArgumentMethods"]
331+
impl<'a> Argument<'a> {
332332
#[doc(hidden)]
333333
#[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")]
334334
#[inline]
335-
pub fn new<'b, T>(x: &'b T, f: fn(&T, &mut Formatter<'_>) -> Result) -> ArgumentV1<'b> {
335+
pub fn new<'b, T>(x: &'b T, f: fn(&T, &mut Formatter<'_>) -> Result) -> Argument<'b> {
336336
// SAFETY: `mem::transmute(x)` is safe because
337337
// 1. `&'b T` keeps the lifetime it originated with `'b`
338338
// (so as to not have an unbounded lifetime)
@@ -341,7 +341,7 @@ impl<'a> ArgumentV1<'a> {
341341
// `mem::transmute(f)` is safe since `fn(&T, &mut Formatter<'_>) -> Result`
342342
// and `fn(&Opaque, &mut Formatter<'_>) -> Result` have the same ABI
343343
// (as long as `T` is `Sized`)
344-
unsafe { ArgumentV1 { formatter: mem::transmute(f), value: mem::transmute(x) } }
344+
unsafe { Argument { formatter: mem::transmute(f), value: mem::transmute(x) } }
345345
}
346346

347347
arg_new!(new_display, Display);
@@ -356,8 +356,8 @@ impl<'a> ArgumentV1<'a> {
356356

357357
#[doc(hidden)]
358358
#[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")]
359-
pub fn from_usize(x: &usize) -> ArgumentV1<'_> {
360-
ArgumentV1::new(x, USIZE_MARKER)
359+
pub fn from_usize(x: &usize) -> Argument<'_> {
360+
Argument::new(x, USIZE_MARKER)
361361
}
362362

363363
fn as_usize(&self) -> Option<usize> {
@@ -377,7 +377,7 @@ impl<'a> ArgumentV1<'a> {
377377

378378
// flags available in the v1 format of format_args
379379
#[derive(Copy, Clone)]
380-
enum FlagV1 {
380+
enum Flag {
381381
SignPlus,
382382
SignMinus,
383383
Alternate,
@@ -404,7 +404,7 @@ impl<'a> Arguments<'a> {
404404
#[doc(hidden)]
405405
#[inline]
406406
#[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")]
407-
pub fn new_v1(pieces: &'a [&'static str], args: &'a [ArgumentV1<'a>]) -> Arguments<'a> {
407+
pub fn new_v1(pieces: &'a [&'static str], args: &'a [Argument<'a>]) -> Arguments<'a> {
408408
if pieces.len() < args.len() || pieces.len() > args.len() + 1 {
409409
panic!("invalid args");
410410
}
@@ -416,7 +416,7 @@ impl<'a> Arguments<'a> {
416416
#[inline]
417417
#[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")]
418418
#[rustc_const_unstable(feature = "const_fmt_arguments_new", issue = "none")]
419-
pub const fn new_v1(pieces: &'a [&'static str], args: &'a [ArgumentV1<'a>]) -> Arguments<'a> {
419+
pub const fn new_v1(pieces: &'a [&'static str], args: &'a [Argument<'a>]) -> Arguments<'a> {
420420
if pieces.len() < args.len() || pieces.len() > args.len() + 1 {
421421
panic!("invalid args");
422422
}
@@ -435,7 +435,7 @@ impl<'a> Arguments<'a> {
435435
#[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")]
436436
pub fn new_v1_formatted(
437437
pieces: &'a [&'static str],
438-
args: &'a [ArgumentV1<'a>],
438+
args: &'a [Argument<'a>],
439439
fmt: &'a [rt::Placeholder],
440440
_unsafe_arg: UnsafeArg,
441441
) -> Arguments<'a> {
@@ -502,7 +502,7 @@ pub struct Arguments<'a> {
502502

503503
// Dynamic arguments for interpolation, to be interleaved with string
504504
// pieces. (Every argument is preceded by a string piece.)
505-
args: &'a [ArgumentV1<'a>],
505+
args: &'a [Argument<'a>],
506506
}
507507

508508
impl<'a> Arguments<'a> {
@@ -1274,7 +1274,7 @@ pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result {
12741274
Ok(())
12751275
}
12761276

1277-
unsafe fn run(fmt: &mut Formatter<'_>, arg: &rt::Placeholder, args: &[ArgumentV1<'_>]) -> Result {
1277+
unsafe fn run(fmt: &mut Formatter<'_>, arg: &rt::Placeholder, args: &[Argument<'_>]) -> Result {
12781278
fmt.fill = arg.fill;
12791279
fmt.align = arg.align;
12801280
fmt.flags = arg.flags;
@@ -1295,7 +1295,7 @@ unsafe fn run(fmt: &mut Formatter<'_>, arg: &rt::Placeholder, args: &[ArgumentV1
12951295
(value.formatter)(value.value, fmt)
12961296
}
12971297

1298-
unsafe fn getcount(args: &[ArgumentV1<'_>], cnt: &rt::Count) -> Option<usize> {
1298+
unsafe fn getcount(args: &[Argument<'_>], cnt: &rt::Count) -> Option<usize> {
12991299
match *cnt {
13001300
rt::Count::Is(n) => Some(n),
13011301
rt::Count::Implied => None,
@@ -1878,7 +1878,7 @@ impl<'a> Formatter<'a> {
18781878
#[must_use]
18791879
#[stable(feature = "fmt_flags", since = "1.5.0")]
18801880
pub fn sign_plus(&self) -> bool {
1881-
self.flags & (1 << FlagV1::SignPlus as u32) != 0
1881+
self.flags & (1 << Flag::SignPlus as u32) != 0
18821882
}
18831883

18841884
/// Determines if the `-` flag was specified.
@@ -1907,7 +1907,7 @@ impl<'a> Formatter<'a> {
19071907
#[must_use]
19081908
#[stable(feature = "fmt_flags", since = "1.5.0")]
19091909
pub fn sign_minus(&self) -> bool {
1910-
self.flags & (1 << FlagV1::SignMinus as u32) != 0
1910+
self.flags & (1 << Flag::SignMinus as u32) != 0
19111911
}
19121912

19131913
/// Determines if the `#` flag was specified.
@@ -1935,7 +1935,7 @@ impl<'a> Formatter<'a> {
19351935
#[must_use]
19361936
#[stable(feature = "fmt_flags", since = "1.5.0")]
19371937
pub fn alternate(&self) -> bool {
1938-
self.flags & (1 << FlagV1::Alternate as u32) != 0
1938+
self.flags & (1 << Flag::Alternate as u32) != 0
19391939
}
19401940

19411941
/// Determines if the `0` flag was specified.
@@ -1961,17 +1961,17 @@ impl<'a> Formatter<'a> {
19611961
#[must_use]
19621962
#[stable(feature = "fmt_flags", since = "1.5.0")]
19631963
pub fn sign_aware_zero_pad(&self) -> bool {
1964-
self.flags & (1 << FlagV1::SignAwareZeroPad as u32) != 0
1964+
self.flags & (1 << Flag::SignAwareZeroPad as u32) != 0
19651965
}
19661966

19671967
// FIXME: Decide what public API we want for these two flags.
19681968
// https://github.com/rust-lang/rust/issues/48584
19691969
fn debug_lower_hex(&self) -> bool {
1970-
self.flags & (1 << FlagV1::DebugLowerHex as u32) != 0
1970+
self.flags & (1 << Flag::DebugLowerHex as u32) != 0
19711971
}
19721972

19731973
fn debug_upper_hex(&self) -> bool {
1974-
self.flags & (1 << FlagV1::DebugUpperHex as u32) != 0
1974+
self.flags & (1 << Flag::DebugUpperHex as u32) != 0
19751975
}
19761976

19771977
/// 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
25312531
// or not to zero extend, and then unconditionally set it to get the
25322532
// prefix.
25332533
if f.alternate() {
2534-
f.flags |= 1 << (FlagV1::SignAwareZeroPad as u32);
2534+
f.flags |= 1 << (Flag::SignAwareZeroPad as u32);
25352535

25362536
if f.width.is_none() {
25372537
f.width = Some((usize::BITS / 4) as usize + 2);
25382538
}
25392539
}
2540-
f.flags |= 1 << (FlagV1::Alternate as u32);
2540+
f.flags |= 1 << (Flag::Alternate as u32);
25412541

25422542
let ret = LowerHex::fmt(&ptr_addr, f);
25432543

src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/builtin_fn_macro.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ macro_rules! format_args {
201201
}
202202
203203
fn main() {
204-
$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), ]);
204+
$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), ]);
205205
}
206206
"#]],
207207
);
@@ -229,7 +229,7 @@ macro_rules! format_args {
229229
}
230230
231231
fn main() {
232-
$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), ]);
232+
$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), ]);
233233
}
234234
"#]],
235235
);
@@ -260,7 +260,7 @@ macro_rules! format_args {
260260
fn main() {
261261
let _ =
262262
/* parse error: expected field name or number */
263-
$crate::fmt::Arguments::new_v1(&[], &[$crate::fmt::ArgumentV1::new(&(a.), $crate::fmt::Display::fmt), ]);
263+
$crate::fmt::Arguments::new_v1(&[], &[$crate::fmt::Argument::new(&(a.), $crate::fmt::Display::fmt), ]);
264264
}
265265
"#]],
266266
);

src/tools/rust-analyzer/crates/hir-expand/src/builtin_fn_macro.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ fn format_args_expand(
241241
// We expand `format_args!("", a1, a2)` to
242242
// ```
243243
// $crate::fmt::Arguments::new_v1(&[], &[
244-
// $crate::fmt::ArgumentV1::new(&arg1,$crate::fmt::Display::fmt),
245-
// $crate::fmt::ArgumentV1::new(&arg2,$crate::fmt::Display::fmt),
244+
// $crate::fmt::Argument::new(&arg1,$crate::fmt::Display::fmt),
245+
// $crate::fmt::Argument::new(&arg2,$crate::fmt::Display::fmt),
246246
// ])
247247
// ```,
248248
// which is still not really correct, but close enough for now
@@ -267,7 +267,7 @@ fn format_args_expand(
267267
}
268268
let _format_string = args.remove(0);
269269
let arg_tts = args.into_iter().flat_map(|arg| {
270-
quote! { #DOLLAR_CRATE::fmt::ArgumentV1::new(&(#arg), #DOLLAR_CRATE::fmt::Display::fmt), }
270+
quote! { #DOLLAR_CRATE::fmt::Argument::new(&(#arg), #DOLLAR_CRATE::fmt::Display::fmt), }
271271
}.token_trees);
272272
let expanded = quote! {
273273
#DOLLAR_CRATE::fmt::Arguments::new_v1(&[], &[##arg_tts])

0 commit comments

Comments
 (0)