Skip to content

Commit 3e969d4

Browse files
committed
Move core::fmt::Arguments::new_v1* to rt.rs.
1 parent 6e23095 commit 3e969d4

File tree

2 files changed

+44
-36
lines changed

2 files changed

+44
-36
lines changed

library/core/src/fmt/mod.rs

-35
Original file line numberDiff line numberDiff line change
@@ -622,44 +622,9 @@ pub struct Arguments<'a> {
622622
args: &'a [rt::Argument<'a>],
623623
}
624624

625-
/// Used by the format_args!() macro to create a fmt::Arguments object.
626625
#[doc(hidden)]
627626
#[unstable(feature = "fmt_internals", issue = "none")]
628627
impl<'a> Arguments<'a> {
629-
#[inline]
630-
pub const fn new_const<const N: usize>(pieces: &'a [&'static str; N]) -> Self {
631-
const { assert!(N <= 1) };
632-
Arguments { pieces, fmt: None, args: &[] }
633-
}
634-
635-
/// When using the format_args!() macro, this function is used to generate the
636-
/// Arguments structure.
637-
#[inline]
638-
pub const fn new_v1<const P: usize, const A: usize>(
639-
pieces: &'a [&'static str; P],
640-
args: &'a [rt::Argument<'a>; A],
641-
) -> Arguments<'a> {
642-
const { assert!(P >= A && P <= A + 1, "invalid args") }
643-
Arguments { pieces, fmt: None, args }
644-
}
645-
646-
/// Specifies nonstandard formatting parameters.
647-
///
648-
/// An `rt::UnsafeArg` is required because the following invariants must be held
649-
/// in order for this function to be safe:
650-
/// 1. The `pieces` slice must be at least as long as `fmt`.
651-
/// 2. Every `rt::Placeholder::position` value within `fmt` must be a valid index of `args`.
652-
/// 3. Every `rt::Count::Param` within `fmt` must contain a valid index of `args`.
653-
#[inline]
654-
pub const fn new_v1_formatted(
655-
pieces: &'a [&'static str],
656-
args: &'a [rt::Argument<'a>],
657-
fmt: &'a [rt::Placeholder],
658-
_unsafe_arg: rt::UnsafeArg,
659-
) -> Arguments<'a> {
660-
Arguments { pieces, fmt: Some(fmt), args }
661-
}
662-
663628
/// Estimates the length of the formatted text.
664629
///
665630
/// This is intended to be used for setting initial `String` capacity

library/core/src/fmt/rt.rs

+44-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#![allow(missing_debug_implementations)]
22
#![unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")]
33

4-
//! These are the lang items used by format_args!().
4+
//! All types and methods in this file are used by the compiler in
5+
//! the expansion/lowering of format_args!().
6+
//!
7+
//! Do not modify them without understanding the consequences for the format_args!() macro.
58
69
use super::*;
710
use crate::hint::unreachable_unchecked;
@@ -229,3 +232,43 @@ impl UnsafeArg {
229232
Self { _private: () }
230233
}
231234
}
235+
236+
/// Used by the format_args!() macro to create a fmt::Arguments object.
237+
#[doc(hidden)]
238+
#[unstable(feature = "fmt_internals", issue = "none")]
239+
#[rustc_diagnostic_item = "FmtArgumentsNew"]
240+
impl<'a> Arguments<'a> {
241+
#[inline]
242+
pub const fn new_const<const N: usize>(pieces: &'a [&'static str; N]) -> Self {
243+
const { assert!(N <= 1) };
244+
Arguments { pieces, fmt: None, args: &[] }
245+
}
246+
247+
/// When using the format_args!() macro, this function is used to generate the
248+
/// Arguments structure.
249+
#[inline]
250+
pub const fn new_v1<const P: usize, const A: usize>(
251+
pieces: &'a [&'static str; P],
252+
args: &'a [rt::Argument<'a>; A],
253+
) -> Arguments<'a> {
254+
const { assert!(P >= A && P <= A + 1, "invalid args") }
255+
Arguments { pieces, fmt: None, args }
256+
}
257+
258+
/// Specifies nonstandard formatting parameters.
259+
///
260+
/// An `rt::UnsafeArg` is required because the following invariants must be held
261+
/// in order for this function to be safe:
262+
/// 1. The `pieces` slice must be at least as long as `fmt`.
263+
/// 2. Every `rt::Placeholder::position` value within `fmt` must be a valid index of `args`.
264+
/// 3. Every `rt::Count::Param` within `fmt` must contain a valid index of `args`.
265+
#[inline]
266+
pub const fn new_v1_formatted(
267+
pieces: &'a [&'static str],
268+
args: &'a [rt::Argument<'a>],
269+
fmt: &'a [rt::Placeholder],
270+
_unsafe_arg: rt::UnsafeArg,
271+
) -> Arguments<'a> {
272+
Arguments { pieces, fmt: Some(fmt), args }
273+
}
274+
}

0 commit comments

Comments
 (0)