Uh oh!
There was an error while loading. Please reload this page.
Implement DebugStruct::non_exhaustive. - #66716
Conversation
rust-highfive
commented
Nov 24, 2019
r? @kennytm (rust_highfive has picked a reviewer for you, use r? to override) |
richard-uk1
commented
Nov 24, 2019
r? @scottmcm since they saw the internals post. |
There was a problem hiding this comment.
I'd add a field foo to this structure, just for clarity's sake.
Probably Box<dyn (pick your favorite object safe trait that isn't `Debug`)>.
CAD97
commented
Nov 24, 2019
Would it be simpler to print e.g. smth like pubfnnon_exhaustive(&mutself) -> &mutDebugStruct<'a,'b>{self.result = self.result.and_then(|_| {ifself.is_pretty(){if !self.has_fields{self.fmt.write_str(" {\n")?;}letmut slot = None;letmut state = Default::default();letmut writer = PadAdapter::wrap(&mutself.fmt,&mut slot,&mut state);
writer.write_str("..\n")}else{let prefix = ifself.has_fields{", "}else{" { "};self.fmt.write_str(prefix)?;self.fmt.write_str("..")}});self.has_fields = true;self}pubfnfinish_non_exhaustive(&mutself) -> fmt::Result{self.non_exhaustive().finish()} |
richard-uk1
commented
Nov 24, 2019
That is certainly another possibility, I'd be interested to hear other people's opinions. |
There was a problem hiding this comment.
🚩🚩🚩🚩🚩🚩
You do not want to use .into_iter().copied() here. This takes an autoref to &[_] and will break when we eventually add impl IntoIterator for [_]. Use .iter() instead.
JohnCSimon
commented
Nov 30, 2019
Ping from triage: @scottmcm - all checks pass, can you please review this PR? |
JohnCSimon
commented
Dec 7, 2019
Pinging again from triage: |
Dylan-DPC-zz
commented
Dec 10, 2019
r? @dtolnay |
dtolnay
left a comment
There was a problem hiding this comment.
Thanks! I would be on board with supporting .. in DebugStruct.
I think opaque_field should be removed from this PR. It is easy enough to get the same behavior with
field("field", &format_args!("_")). But the representationStruct { field: _ }is not one that I find intuitive or would want to encourage. Almost anything would be better, for examplefield("field", &format_args!("<some Iterator>")). I would prefer to leave this up to the caller rather than dictating a default representation for opaque fields. This way the caller can write an impl that is as useful as possible within their constraints.The bool argument of non_exhaustive doesn't seem useful. The caller would pretty much always need to pass true which is just noisy. In the rare case that a struct may or may not print as nonexhaustive depending on a runtime decision, the Debug impl can use an
ifaround the non_exhaustive call.I would lean toward making this an alternative to
finishto sidestep the ambiguity about what it should do if you print more fields after calling non_exhaustive.f.debug_struct("Struct").field("field", &self.field).finish_non_exhaustive()
rust-highfive
commented
Dec 16, 2019
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
dtolnay
commented
Dec 16, 2019
Thanks @derekdreery! This looks good to me. Could you please file a tracking issue and put the issue number into the #[unstable(...)] attribute in the PR? After that I'm happy to merge this. |
DebugStruct::non_exhaustive and DebugStruct::opaque_field.DebugStruct::non_exhaustive.richard-uk1
commented
Dec 17, 2019
Tracking issue added :) |
Mark-Simulacrum
commented
Dec 17, 2019
Could you also squash the commits down into just one? Thanks! It would also be good to update the PR description to be slightly more commit-y -- e.g., removing open questions, etc. -- since it'll go into the bors merge commit, so is preserved for all history. This is more of a personal pet peeve of mine though :) |
CAD97
commented
Dec 17, 2019
Off topic question: bors-ng has a setting where you can ignore any part of the PR description after some special line, which I often set to e.g. Is this something that the rust-lang bors is capable of doing? If not, should we add it? If so, should we enable it and teach people to use it? |
6303a13 to
985127cComparerichard-uk1
commented
Dec 17, 2019
Done and done. |
Mark-Simulacrum
commented
Dec 17, 2019
bors
commented
Dec 17, 2019
📌 Commit 985127c has been approved by |
bors
commented
Dec 17, 2019
🌲 The tree is currently closed for pull requests below priority 100, this pull request will be tested once the tree is reopened |
…=dtolnay
Implement `DebugStruct::non_exhaustive`.
This patch adds a function (finish_non_exhaustive) to add ellipsis before the closing brace when formatting using `DebugStruct`.
## Example
```rust
#![feature(debug_non_exhaustive)]
use std::fmt;
struct Bar {
bar: i32,
hidden: f32,
}
impl fmt::Debug for Bar {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("Bar")
.field("bar", &self.bar)
.non_exhaustive(true) // Show that some other field(s) exist.
.finish()
}
}
assert_eq!(
format!("{:?}", Bar { bar: 10, hidden: 1.0 }),
"Bar { bar: 10, .. }",
);
```rust-highfive
commented
Dec 19, 2019
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
bors
commented
Dec 19, 2019
💔 Test failed - checks-azure |
bors
commented
Dec 23, 2019
☔ The latest upstream changes (presumably #67540) made this pull request unmergeable. Please resolve the merge conflicts. |
dtolnay
commented
Jan 14, 2020
This needs a rebase but is otherwise ready to land. |
rust-highfive
commented
Jan 14, 2020
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
dd04a56 to
9864ec4Comparerichard-uk1
commented
Jan 14, 2020
Should be up-to-date now. |
rust-highfive
commented
Jan 14, 2020
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
dtolnay
commented
Jan 14, 2020
https://dev.azure.com/rust-lang/e71b0ddf-dd27-435a-873c-e30f86eea377/_apis/build/builds/18417/logs/66 looks like it wants a rustfmt of these files. |
richard-uk1
commented
Jan 16, 2020
ready for review |
dtolnay
commented
Jan 16, 2020
Thanks! @bors r+ |
bors
commented
Jan 16, 2020
📌 Commit 73124df has been approved by |
bors
commented
Jan 17, 2020
Implement `DebugStruct::non_exhaustive`.
This patch adds a function (finish_non_exhaustive) to add ellipsis before the closing brace when formatting using `DebugStruct`.
## Example
```rust
#![feature(debug_non_exhaustive)]
use std::fmt;
struct Bar {
bar: i32,
hidden: f32,
}
impl fmt::Debug for Bar {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("Bar")
.field("bar", &self.bar)
.non_exhaustive(true) // Show that some other field(s) exist.
.finish()
}
}
assert_eq!(
format!("{:?}", Bar { bar: 10, hidden: 1.0 }),
"Bar { bar: 10, .. }",
);
```bors
commented
Jan 17, 2020
☀️ Test successful - checks-azure |
This patch adds a function (finish_non_exhaustive) to add ellipsis before the closing brace when formatting using
DebugStruct.Example