From 7f6dce43829b915cbaa5d49625506fd060e2c6d6 Mon Sep 17 00:00:00 2001 From: EFanZh Date: Tue, 23 Dec 2025 12:41:42 +0800 Subject: [PATCH 1/2] Constify `fmt::from_fn` --- library/core/src/fmt/builders.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/fmt/builders.rs b/library/core/src/fmt/builders.rs index 197cddd3fa9de..1a7db8719b404 100644 --- a/library/core/src/fmt/builders.rs +++ b/library/core/src/fmt/builders.rs @@ -1228,7 +1228,7 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> { /// ``` #[stable(feature = "fmt_from_fn", since = "1.93.0")] #[must_use = "returns a type implementing Debug and Display, which do not have any effects unless they are used"] -pub fn from_fn) -> fmt::Result>(f: F) -> FromFn { +pub const fn from_fn) -> fmt::Result>(f: F) -> FromFn { FromFn(f) } From 44be649dceb7faa64e5370f0ffd902ec604b9a04 Mon Sep 17 00:00:00 2001 From: EFanZh Date: Tue, 23 Dec 2025 10:25:46 -0800 Subject: [PATCH 2/2] Stabilization the constification --- library/core/src/fmt/builders.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/core/src/fmt/builders.rs b/library/core/src/fmt/builders.rs index 1a7db8719b404..4d12ca383455e 100644 --- a/library/core/src/fmt/builders.rs +++ b/library/core/src/fmt/builders.rs @@ -1227,6 +1227,7 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> { /// assert_eq!(format!("{:?}", wrapped), "'a'"); /// ``` #[stable(feature = "fmt_from_fn", since = "1.93.0")] +#[rustc_const_stable(feature = "fmt_from_fn", since = "CURRENT_RUSTC_VERSION")] #[must_use = "returns a type implementing Debug and Display, which do not have any effects unless they are used"] pub const fn from_fn) -> fmt::Result>(f: F) -> FromFn { FromFn(f)