diff options
| author | Yuri Astrakhan <YuriAstrakhan@gmail.com> | 2025-01-24 01:41:00 -0500 |
|---|---|---|
| committer | Yuri Astrakhan <YuriAstrakhan@gmail.com> | 2025-01-24 01:58:33 -0500 |
| commit | c9ae0bbffb86d45e313bfe9515af513ce6ab49c9 (patch) | |
| tree | da61bf25c3df3449d944b38d2f060e6e858ccd1e | |
| parent | 1c9837df1dde9b234229709e89b3672bd3cf04a4 (diff) | |
| download | rust-c9ae0bbffb86d45e313bfe9515af513ce6ab49c9.tar.gz rust-c9ae0bbffb86d45e313bfe9515af513ce6ab49c9.zip | |
Fix `FormattingOptions` instantiation with `Default`
The `fill` value by default should be set to `' '` (space), but the current implementation uses `#[derive(Default)]` which sets it to `\0`
| -rw-r--r-- | library/core/src/fmt/mod.rs | 11 | ||||
| -rw-r--r-- | library/core/tests/fmt/mod.rs | 6 |
2 files changed, 16 insertions, 1 deletions
diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index a033b8bd305..a1bf3a4d7a7 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -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, @@ -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 diff --git a/library/core/tests/fmt/mod.rs b/library/core/tests/fmt/mod.rs index 2c93a9bc80d..025c69c4f62 100644 --- a/library/core/tests/fmt/mod.rs +++ b/library/core/tests/fmt/mod.rs @@ -52,6 +52,12 @@ fn test_maybe_uninit_short() { } #[test] +fn formatting_options_ctor() { + use core::fmt::FormattingOptions; + assert_eq!(FormattingOptions::new(), FormattingOptions::default()); +} + +#[test] fn formatting_options_flags() { use core::fmt::*; for sign in [None, Some(Sign::Plus), Some(Sign::Minus)] { |
