Skip to content

Fix FormattingOptions instantiation with Default #135977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion library/core/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ pub enum DebugAsHex {
///
/// `FormattingOptions` is a [`Formatter`] without an attached [`Write`] trait.
/// It is mainly used to construct `Formatter` instances.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[unstable(feature = "formatting_options", issue = "118117")]
pub struct FormattingOptions {
flags: u32,
Expand Down Expand Up @@ -508,6 +508,15 @@ impl FormattingOptions {
}
}

#[unstable(feature = "formatting_options", issue = "118117")]
impl Default for FormattingOptions {
/// Same as [`FormattingOptions::new()`].
fn default() -> Self {
// The `#[derive(Default)]` implementation would set `fill` to `\0` instead of space.
Self::new()
}
}

/// Configuration for formatting.
///
/// A `Formatter` represents various options related to formatting. Users do not
Expand Down
6 changes: 6 additions & 0 deletions library/core/tests/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ fn test_maybe_uninit_short() {
assert_eq!(format!("{x:?}"), "MaybeUninit<u32>");
}

#[test]
fn formatting_options_ctor() {
use core::fmt::FormattingOptions;
assert_eq!(FormattingOptions::new(), FormattingOptions::default());
}

#[test]
fn formatting_options_flags() {
use core::fmt::*;
Expand Down
Loading