-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Shorten the MaybeUninit
Debug
implementation
#133282
Open
tgross35
wants to merge
1
commit into
rust-lang:master
Choose a base branch
from
tgross35:maybe-uninit-debug
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+12
−1
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tgross35
force-pushed
the
maybe-uninit-debug
branch
from
November 21, 2024 09:06
fafb15f
to
d7e21eb
Compare
rustbot
added
the
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
label
Nov 21, 2024
rustbot
added
the
S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
label
Nov 21, 2024
jieyouxu
reviewed
Nov 21, 2024
Amanieu
reviewed
Nov 23, 2024
library/core/src/mem/maybe_uninit.rs
Outdated
@@ -255,7 +255,10 @@ impl<T: Copy> Clone for MaybeUninit<T> { | |||
#[stable(feature = "maybe_uninit_debug", since = "1.41.0")] | |||
impl<T> fmt::Debug for MaybeUninit<T> { | |||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | |||
f.pad(type_name::<Self>()) | |||
let full_name = type_name::<Self>(); | |||
// NB: this needs to be adjusted if `MaybeUninit` moves modules |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a test for this? Otherwise we're likely to miss it if it does move modules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, done with test_maybe_uninit_short
tgross35
force-pushed
the
maybe-uninit-debug
branch
from
November 23, 2024 00:45
d7e21eb
to
b76a411
Compare
Currently the `Debug` implementation for `MaybeUninit` winds up being pretty verbose. This struct: #[derive(Debug)] pub struct Foo { pub a: u32, pub b: &'static str, pub c: MaybeUninit<u32>, pub d: MaybeUninit<String>, } Prints as: Foo { a: 0, b: "hello", c: core::mem::maybe_uninit::MaybeUninit<u32>, d: core::mem::maybe_uninit::MaybeUninit<alloc::string::String>, } The goal is just to be a standin for content so the path prefix doesn't add any useful information. Change the implementation to trim `MaybeUninit`'s leading path, meaning the new result is now: Foo { a: 0, b: "hello", c: MaybeUninit<u32>, d: MaybeUninit<alloc::string::String>, }
tgross35
force-pushed
the
maybe-uninit-debug
branch
from
November 23, 2024 00:46
b76a411
to
c1707aa
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently the
Debug
implementation forMaybeUninit
winds up being pretty verbose. This struct:Prints as:
The goal is just to be a standin for content so the path prefix doesn't add any useful information. Change the implementation to trim
MaybeUninit
's leading path, meaning the new result is now: