-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Stop leaking implementation detail in Debug
impls of opaque types
#82416
Stop leaking implementation detail in Debug
impls of opaque types
#82416
Conversation
This changes the `Debug` impl of: - `core::any::TypeId` - `core::mem::Discriminant` - `std::thread::ThreadId` - `std::time::Instant` All these types are explicitly described as "opaque" in the documentation, so they shouldn't print implementation details in their `Debug` implementation. The change for `ThreadId` can possibly be reverted in the future, once the method `thread_id_value` is stabilized: rust-lang#67939 The same goes for `Discriminant` once/if the `DiscriminantKind` trait gets stabilized. But until then, these are opaque types.
r? @dtolnay (rust-highfive has picked a reviewer for you, use r? to override) |
My own instinct is that the While exposing internal details in In any case, I also think that the benefits of leaving the information exposed are merely hypotheses on my part; I cannot currently point to an instance where a bug was resolved because the concrete TypeId was included in the Debug output. (If our debugger support were more robust, to the point where one could reliably get debug-formatted output of values from So I guess I'm waiting to see what others think, but if it were my decision alone, I'd probably decline merging this PR, at least in the absence of more concrete motivation. |
Your reasoning makes sense to me. I would say that "parsing the To still add one piece of motivation for merging this PR: I vaguely remember that, as a Rust beginner, I was confused a few times about being able to see fields and their values in the I very much hope this PR will not distract too much from more important work and does not waste a lot of t-libs time. I'm fine with either merging or closing! |
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.
I would prefer not to make this change. IMO the correct way to design Debug
impls is by putting in whatever makes them most useful, and it would be hard to argue that TypeId(_)
is "more useful" than TypeId(0)
, for reasons pointed out in #82416 (comment).
There is an improvement opportunity however to make the Debug representation of all these types consistent among one another. Currently we're printing TypeId { t: 0 }
as a struct and Discriminant(0)
, ThreadId(0)
as tuple structs. I wouldn't mind agreeing on one or the other representation.
Regarding "if they are shown to me here, then surely there is a way to access them", changing the format to TypeId(private 0)
would be quite reasonable and effective I think.
Lets just close this PR then. Everyone (including me by now) seems to agree that this specific change is not a good idea. The debug output could be improved still, but that will have to happen in a different PR. |
This changes the
Debug
impl of:core::any::TypeId
core::mem::Discriminant
std::thread::ThreadId
std::time::Instant
All these types are explicitly described as "opaque" in the documentation, so they shouldn't print implementation details in their
Debug
implementation IMO.The change for
ThreadId
can possibly be reverted in the future, when the methodthread_id_value
is stabilized: #67939. The same goes forDiscriminant
once/if theDiscriminantKind
trait gets stabilized. But until then, these are opaque types.No one should rely on the output of
Debug
impls, so this shouldn't break anything. However, just to be sure, crater was used before for changes like this.Curious to hear what you think about this change.