Skip to content

Commit 0fc0807

Browse files
committed
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`
1 parent 1c9837d commit 0fc0807

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

library/core/src/fmt/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ pub enum DebugAsHex {
288288
///
289289
/// `FormattingOptions` is a [`Formatter`] without an attached [`Write`] trait.
290290
/// It is mainly used to construct `Formatter` instances.
291-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)]
291+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
292292
#[unstable(feature = "formatting_options", issue = "118117")]
293293
pub struct FormattingOptions {
294294
flags: u32,
@@ -508,6 +508,12 @@ impl FormattingOptions {
508508
}
509509
}
510510

511+
impl Default for FormattingOptions {
512+
fn default() -> Self {
513+
Self::new()
514+
}
515+
}
516+
511517
/// Configuration for formatting.
512518
///
513519
/// A `Formatter` represents various options related to formatting. Users do not

library/core/tests/fmt/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use core::num::fmt::Formatted;
2+
13
mod builders;
24
mod float;
35
mod num;
@@ -51,6 +53,11 @@ fn test_maybe_uninit_short() {
5153
assert_eq!(format!("{x:?}"), "MaybeUninit<u32>");
5254
}
5355

56+
#[test]
57+
fn formatting_options_ctor() {
58+
assert_eq!(FormattingOptions::new(), FormattingOptions::default());
59+
}
60+
5461
#[test]
5562
fn formatting_options_flags() {
5663
use core::fmt::*;

0 commit comments

Comments
 (0)