-
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
Document that Debug
output of structures is unstable
#62794
Comments
cfg(windows)
)cfg!(windows)
)
- customize expected pretty-print output for windows platforms - work-around for unexpected trailing commas on windows platforms (see <rust-lang/rust#62794>)
Isn't the formatting of Debug implementations (at least the derived ones) considered an implementation detail and you shouldn't be testing against those? Also you seem to be using an outdated compiler on Linux. The formatting changed to include the commas and it does so for me on Linux as well: [cfg!(windows) == false]
Foo { bar: 1, baz: Some(1) }
Foo {
bar: 1,
baz: Some(
1,
),
} |
- customize expected pretty-print output for windows platforms - work-around for unexpected trailing commas on windows platforms (see <rust-lang/rust#62794>)
@rivy could you do |
I was using fairly recent version of I ran across this while trying to fix some failing windows tests for "ansi-term". I've fixed that by converting to a regex comparison with optional trailing commas. So, that issue is essentially solved. And, I'm just fine if it's an "implementation detail" and subject to change, but that's not mentioned anywhere within the usual documentation that I could find. Pretty-print seems to be a convenient way to compare structures visually, so, I suspect that others are using it for comparisons. A mention in the official documentation about what can be expected to remain stable and what might change would be helpful. |
That would explain the difference then. Could you adjust the issue title? This has nothing to do with Windows vs non-Windows. The output simply changed between two versions. |
cfg!(windows)
)rustc
versions
Yes, you're correct. The pretty-print is differing between versions, not platforms. It's the same, per platform, when using the same Since at least the Also, any recommendations for structural comparison during testing? I'd like to give @ogham a PR for a better way to test his structure (see https://github.com/ogham/rust-ansi-term/blob/master/src/debug.rs#L104-L122). I've already supplied a regex comparison which fixes the specific trailing-comma / no-trailing-comma problem (see ogham/rust-ansi-term#52), but that seems quite fragile if pretty-print has no output guarantees. |
rustc
versionsDebug
output of structures differs between rustc
versions
Debug
output of structures differs between rustc
versionsDebug
output of structures differs between rustc
versions
I have adjusted the title to include
The expected way for people to compare structures is to use |
Hi, In this case, I'm literally testing against the auto-generated |
What is the point of the test? If you want to test the debug output itself, you will just have to live with the fact that it can change arbitrarily any time. It's like testing |
@ogham & @RalfJung , I think I've made the current testing a bit more robust in the face changing debug formatting between I understand the motivation to check for an expected structure instantiation via testing. But using I'm happy to flesh it out and add it to a new PR for And maybe we should direct further discussion to that PR? |
I am still wondering what it is that you are trying to achieve here. Please explain what the test is testing. :)
You do not have to write the |
I'm going to close this issue -- auto-generated Debug implementations are explicitly not guaranteed to produce the same output over time, and the libs team has discussed this (I believe for both this specific change, and in general) and confirmed as such. Further discussion can happen on internals.rust-lang.org. |
@Mark-Simulacrum , when you say "explicitly not guaranteed to produce the same output", where is that documented? When researching this, I found no such documentation. While I don't have a problem with closing this issue as "works as designed", I don't think the issue should be closed until the behavior is documented in a place that is reasonably easy for users to find/see. |
Debug
output of structures differs between rustc
versionsDebug
output of structures is unstable
Reopening as such, I was also unable to find such a place. I think a note on stability in |
- customize expected pretty-print output for windows platforms - work-around for debug print format changes between versions (see <rust-lang/rust#62794>)
Huh, In particular, |
To be clear, I'm not an authority here -- I don't know that the libs team has made the assertion about Display impls before. I do think that it may make sense to say that Display impls are stable in terms of output, though perhaps such a broad claim might be excessive (an audit might be in order for where we implement Display). |
Technically, this changes behavior of the library, but it is considered that `Debug` output is unstable in general (rust-lang/rust#62794) so you should not be relying on it anyway.
Doesn't look like anything has happened on this. I'm happy to attempt an explanation in the docs. The question is where to put it. My first thought is at the end of the last paragraph before "Examples" in the API docs for Current/// This trait can be used with `#[derive]` if all fields implement `Debug`. When
/// `derive`d for structs, it will use the name of the `struct`, then `{`, then a
/// comma-separated list of each field's name and `Debug` value, then `}`. For
/// `enum`s, it will use the name of the variant and, if applicable, `(`, then the
/// `Debug` values of the fields, then `)`. Possible Change/// This trait can be used with `#[derive]` if all fields implement `Debug`. When
/// `derive`d for structs, it will use the name of the `struct`, then `{`, then a
/// comma-separated list of each field's name and `Debug` value, then `}`. For
/// `enum`s, it will use the name of the variant and, if applicable, `(`, then the
/// `Debug` values of the fields, then `)`. __Derived `Debug` formats are not
/// stable, and so may change with future Rust versions.__ Is this notice enough? Should there be an additional notice in |
@alilleybrinker that seems like a good start! Orthogonally to this, though,
Not that I know of. And as @Mark-Simulacrum said, an audit of the existing impls should probably be done before we promise anything like that. |
Hm. Alright, I think you're right that a new Stability section is probably best. Thanks! |
…lity, r=KodrAus First draft documenting Debug stability. Debug implementations of std types aren't stable, and neither are derived Debug implementations for any types, including user-defined types. This commit adds a section to the Debug documentation noting this stability status. This issue is tracked by rust-lang#62794.
With #72551 addressing the |
@alilleybrinker sure. In either case I am closing this issue now. Thanks for the PR! |
- customize expected pretty-print output for windows platforms - work-around for debug print format changes between versions (see <rust-lang/rust#62794>)
Pretty printed structures for
cfg!(windows)
have trailing commas, which is inconsistent with the debug output format documentation and output on non-windows platforms.The text was updated successfully, but these errors were encountered: