Skip to content

Commit f5f72c1

Browse files
committed
[generic_assert] Constify methods used by the formatting system
1 parent dcfa38f commit f5f72c1

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

library/core/src/fmt/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ impl<'a> Arguments<'a> {
596596
/// When using the format_args!() macro, this function is used to generate the
597597
/// Arguments structure.
598598
#[inline]
599-
pub fn new_v1<const P: usize, const A: usize>(
599+
pub const fn new_v1<const P: usize, const A: usize>(
600600
pieces: &'a [&'static str; P],
601601
args: &'a [rt::Argument<'a>; A],
602602
) -> Arguments<'a> {
@@ -612,7 +612,7 @@ impl<'a> Arguments<'a> {
612612
/// 2. Every `rt::Placeholder::position` value within `fmt` must be a valid index of `args`.
613613
/// 3. Every `rt::Count::Param` within `fmt` must contain a valid index of `args`.
614614
#[inline]
615-
pub fn new_v1_formatted(
615+
pub const fn new_v1_formatted(
616616
pieces: &'a [&'static str],
617617
args: &'a [rt::Argument<'a>],
618618
fmt: &'a [rt::Placeholder],

library/core/src/fmt/rt.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ pub struct Argument<'a> {
9696
#[rustc_diagnostic_item = "ArgumentMethods"]
9797
impl Argument<'_> {
9898
#[inline]
99-
fn new<'a, T>(x: &'a T, f: fn(&T, &mut Formatter<'_>) -> Result) -> Argument<'a> {
99+
const fn new<'a, T>(x: &'a T, f: fn(&T, &mut Formatter<'_>) -> Result) -> Argument<'a> {
100100
Argument {
101101
// INVARIANT: this creates an `ArgumentType<'a>` from a `&'a T` and
102102
// a `fn(&T, ...)`, so the invariant is maintained.
103103
ty: ArgumentType::Placeholder {
104-
value: NonNull::from(x).cast(),
104+
value: NonNull::from_ref(x).cast(),
105105
// SAFETY: function pointers always have the same layout.
106106
formatter: unsafe { mem::transmute(f) },
107107
_lifetime: PhantomData,
@@ -150,7 +150,7 @@ impl Argument<'_> {
150150
Self::new(x, UpperExp::fmt)
151151
}
152152
#[inline]
153-
pub fn from_usize(x: &usize) -> Argument<'_> {
153+
pub const fn from_usize(x: &usize) -> Argument<'_> {
154154
Argument { ty: ArgumentType::Count(*x) }
155155
}
156156

@@ -181,7 +181,7 @@ impl Argument<'_> {
181181
}
182182

183183
#[inline]
184-
pub(super) fn as_usize(&self) -> Option<usize> {
184+
pub(super) const fn as_usize(&self) -> Option<usize> {
185185
match self.ty {
186186
ArgumentType::Count(count) => Some(count),
187187
ArgumentType::Placeholder { .. } => None,
@@ -199,7 +199,7 @@ impl Argument<'_> {
199199
/// println!("{f}");
200200
/// ```
201201
#[inline]
202-
pub fn none() -> [Self; 0] {
202+
pub const fn none() -> [Self; 0] {
203203
[]
204204
}
205205
}
@@ -216,7 +216,7 @@ impl UnsafeArg {
216216
/// See documentation where `UnsafeArg` is required to know when it is safe to
217217
/// create and use `UnsafeArg`.
218218
#[inline]
219-
pub unsafe fn new() -> Self {
219+
pub const unsafe fn new() -> Self {
220220
Self { _private: () }
221221
}
222222
}

0 commit comments

Comments
 (0)