mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Rollup merge of #135977 - nyurik:fix-fmt-options, r=joboet
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`. Note that `FormattingOptions` is being released as part of 1.85 (unstable) - so this might warrant a backport to that branch. Tracking issue: https://github.com/rust-lang/rust/issues/118117 Follow up from https://github.com/rust-lang/rust/pull/118159 CC: ``@EliasHolzmann`` ``@programmerjake`` r? ``@m-ou-se``
This commit is contained in:
commit
5c821ae4e8
@ -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
|
||||
|
@ -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::*;
|
||||
|
Loading…
Reference in New Issue
Block a user