Rollup merge of #145915 - coolreader18:stabilize-fmt_from_fn, r=dtolnay

Stabilize `fmt::from_fn`

Resolves rust-lang/rust#146705, pending its FCP.

As discussed in that tracking issue and rust-lang/rust#117729, this splits `fmt::from_fn` out from the `debug_closure_helpers` feature.
This commit is contained in:
Stuart Cook 2025-11-04 13:44:47 +11:00 committed by GitHub
commit 22e4575672
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 14 additions and 17 deletions

View file

@ -3,9 +3,9 @@
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html
// tidy-alphabetical-start
#![cfg_attr(bootstrap, feature(debug_closure_helpers))]
#![feature(associated_type_defaults)]
#![feature(closure_track_caller)]
#![feature(debug_closure_helpers)]
#![feature(exhaustive_patterns)]
#![feature(never_type)]
#![feature(variant_count)]

View file

@ -59,10 +59,10 @@ This API is completely unstable and subject to change.
#![allow(internal_features)]
#![allow(rustc::diagnostic_outside_of_impl)]
#![allow(rustc::untranslatable_diagnostic)]
#![cfg_attr(bootstrap, feature(debug_closure_helpers))]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![doc(rust_logo)]
#![feature(assert_matches)]
#![feature(debug_closure_helpers)]
#![feature(gen_blocks)]
#![feature(if_let_guard)]
#![feature(iter_intersperse)]

View file

@ -9,9 +9,9 @@
// tidy-alphabetical-start
#![allow(internal_features)]
#![cfg_attr(bootstrap, feature(debug_closure_helpers))]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![doc(rust_logo)]
#![feature(debug_closure_helpers)]
#![feature(iter_intersperse)]
#![feature(rustdoc_internals)]
// tidy-alphabetical-end

View file

@ -602,7 +602,7 @@ pub use core::fmt::{DebugAsHex, FormattingOptions, Sign};
pub use core::fmt::{DebugList, DebugMap, DebugSet, DebugStruct, DebugTuple};
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::fmt::{Formatter, Result, Write};
#[unstable(feature = "debug_closure_helpers", issue = "117729")]
#[stable(feature = "fmt_from_fn", since = "CURRENT_RUSTC_VERSION")]
pub use core::fmt::{FromFn, from_fn};
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::fmt::{LowerExp, UpperExp};

View file

@ -1210,13 +1210,12 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
}
}
/// Creates a type whose [`fmt::Debug`] and [`fmt::Display`] impls are provided with the function
/// `f`.
/// Creates a type whose [`fmt::Debug`] and [`fmt::Display`] impls are
/// forwarded to the provided closure.
///
/// # Examples
///
/// ```
/// #![feature(debug_closure_helpers)]
/// use std::fmt;
///
/// let value = 'a';
@ -1227,21 +1226,19 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
/// assert_eq!(format!("{}", wrapped), "'a'");
/// assert_eq!(format!("{:?}", wrapped), "'a'");
/// ```
#[unstable(feature = "debug_closure_helpers", issue = "117729")]
#[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 fn from_fn<F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result>(f: F) -> FromFn<F> {
FromFn(f)
}
/// Implements [`fmt::Debug`] and [`fmt::Display`] using a function.
/// Implements [`fmt::Debug`] and [`fmt::Display`] via the provided closure.
///
/// Created with [`from_fn`].
#[unstable(feature = "debug_closure_helpers", issue = "117729")]
pub struct FromFn<F>(F)
where
F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result;
#[stable(feature = "fmt_from_fn", since = "CURRENT_RUSTC_VERSION")]
pub struct FromFn<F>(F);
#[unstable(feature = "debug_closure_helpers", issue = "117729")]
#[stable(feature = "fmt_from_fn", since = "CURRENT_RUSTC_VERSION")]
impl<F> fmt::Debug for FromFn<F>
where
F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result,
@ -1251,7 +1248,7 @@ where
}
}
#[unstable(feature = "debug_closure_helpers", issue = "117729")]
#[stable(feature = "fmt_from_fn", since = "CURRENT_RUSTC_VERSION")]
impl<F> fmt::Display for FromFn<F>
where
F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result,

View file

@ -39,7 +39,7 @@ pub use num_buffer::{NumBuffer, NumBufferTrait};
#[stable(feature = "debug_builders", since = "1.2.0")]
pub use self::builders::{DebugList, DebugMap, DebugSet, DebugStruct, DebugTuple};
#[unstable(feature = "debug_closure_helpers", issue = "117729")]
#[stable(feature = "fmt_from_fn", since = "CURRENT_RUSTC_VERSION")]
pub use self::builders::{FromFn, from_fn};
/// The type returned by formatter methods.

View file

@ -1,4 +1,5 @@
// tidy-alphabetical-start
#![cfg_attr(bootstrap, feature(debug_closure_helpers))]
#![doc(
html_root_url = "https://doc.rust-lang.org/nightly/",
html_playground_url = "https://play.rust-lang.org/"
@ -8,7 +9,6 @@
#![feature(assert_matches)]
#![feature(box_into_inner)]
#![feature(box_patterns)]
#![feature(debug_closure_helpers)]
#![feature(file_buffered)]
#![feature(formatting_options)]
#![feature(if_let_guard)]