-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
tracking issue for debug_non_exhaustive
feature
#67364
Comments
Any ETA as to when this might be stabilized? What is blocking this being stabilized? |
AFAIK there aren't any blockers to stabilizing. Things normally live in nightly so they can be tested, but in this case it's unlikely someone will drop stable support just so they can use this feature. I think it will only be used once it's stable. |
It's a small low-risk change (since the methods can be reimplemented or deprecated if they are really broken). |
Although not its primary intention I also find this feature quite useful when implementing struct Example {
field: String,
func: Box<dyn Fn(&str) -> bool + 'static>
}
impl fmt::Debug for Example {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Example")
.field("field", &self.field)
.finish_non_exhaustive()
}
} |
It could be possible to extend |
I also have a use-case for partially printing structs. In my case printing all of struct's fields in a meaningful way would be rather complex and require potentially-expensive FFI calls, so I'd rather omit them from debug output, but I still want to leave a hint that they exist. |
I have a use case for printing expensive structs as well. |
It would be nice to have a |
Maybe its time to revisit the open question. I could implement this if there were consensus it's a good idea. |
Looks like there are no blockers. There's still the question of whether this is also wanted on |
I think that at least for DebugTuple finish_non_exhaustive makes sense as its at least partially is intended to be used with tuple structs. As for DebugList, DebugMap, and DebugSet, I would guess that people wanting this would be less common, but it is likely a small enough api surface to be uncontroversial. @derekdreery For me, |
Hey @guswynn can you put a note on here if you start working on adding support for the other struct types, to make sure that we don't duplicate work. :) |
@rfcbot merge
Similar functionality on |
Team member @m-ou-se has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
I've added a to do item to the steps above:
Not critical, but it'd be nice if we ( |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. The RFC will be merged soon. |
@pickfire I believe that would be a significant departure from how debug_struct works, as it currently knows nothing about what fields are in the struct. As far as I can tell, what you describe would have to be supported by the derive(Debug) macro or something like that |
@pickfire https://docs.rs/debug_stub_derive/0.3.0/debug_stub_derive/ may cover what you want? |
stabilize debug_non_exhaustive tracking issue: rust-lang#67364 but it is still an open question whether the other `Debug*` struct's should have a similar method. I would guess that would best be put underneath a new feature gate, as this one seems uncontroversial enough to stabilize as is
…r=jackh726 Use DebugStruct::finish_non_exhaustive() in std. See rust-lang#67364
Improve Debug implementations of Mutex and RwLock. This improves the Debug implementations of Mutex and RwLock. They now show the poison flag and use debug_non_exhaustive. (See rust-lang#67364.)
What is preventing this from being stabilized? As far as I can tell, all the requirements are met. |
@hamza1311 It's stable on nightly. It will land in Rust 1.53. |
This was stablized a month ago: #83041 Closing this issue, since the other action items are now also completed. |
I, too, would like to see this on In my case, I wanted to shorten the debug representation of a tuple when any of the fields are |
If anyone wanted to have a go at writing a PR, this (implementing for |
I found this issue while wondering why there wasn't an equivalent You can (ab?)use the fact that f.debug_tuple("Foo").field(&{..}).finish() Playground example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=d1b7f91c84969e0de54f70b90d9570bc This may not be as nice as a first-class Also worth noting, perhaps, is how rust docs display private fields on tuple structs, e.g. I think you could emulate this with a struct that has |
That's a great hack! Honestly though AFAIK the only thing stopping there being an impl for this on tuples is someone writing the patch. It should be relatively straightforward even for someone who doesn't know the rustc codebase if you use this PR as a template. |
Feature gate:
#![feature(debug_non_exhaustive)]
This is a tracking issue for adding the ability to add an ellipsis to the end of the
Debug
representation of a struct, to indicate that the struct has more fields, but that these fields are not displayable. This involves adding thefinish_non_exhaustive
method toDebugStruct
, that produces output likewhere the
..
indicate that there are more hidden fields.Public API
Steps / History
DebugStruct::non_exhaustive
. #66716debug_non_exhaustive
feature #67364 (comment).finish()
by.finish_non_exhaustive()
within the standard library where it makes sense: Use DebugStruct::finish_non_exhaustive() in std. #83558 Improve Debug implementations of Mutex and RwLock. #83561Unresolved Questions
DebugTuple
andDebugMap
as well?The text was updated successfully, but these errors were encountered: