-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Suggest more helpful formatting string #50441
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
Conversation
r? @Kimundi (rust_highfive has picked a reviewer for you, use r? to override) |
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 |
src/libcore/fmt/mod.rs
Outdated
@@ -610,7 +610,7 @@ pub trait Debug { | |||
#[rustc_on_unimplemented( | |||
message="`{Self}` doesn't implement `{Display}`", | |||
label="`{Self}` cannot be formatted with the default formatter; \ | |||
try using `:?` instead if you are using a format string", | |||
try using `{:#?}` instead if you are using a format string", |
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.
Could you include both:
try using
{:?}
or{:#?}
instead if you are using a format string
Or maybe something like:
try using
{:?}
(or{:#?}
for extra padding) instead if you are using a format string
I think both are useful in their own right, so I don't think in making one clearer, we should hide the other.
There was additional feedback to point to the use of |
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 |
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 |
a03d236
to
d297d8d
Compare
@varkor Just getting the string changed took me five tries, so I'll leave more advanced changes for another time :) |
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.
👍
src/libcore/fmt/mod.rs
Outdated
@@ -542,10 +542,10 @@ impl<'a> Display for Arguments<'a> { | |||
/// ``` | |||
#[stable(feature = "rust1", since = "1.0.0")] | |||
#[rustc_on_unimplemented( | |||
on(crate_local, label="`{Self}` cannot be formatted using `:?`; \ | |||
on(crate_local, label="`{Self}` cannot be formatted using `{{:?}}`; \ | |||
add `#[derive(Debug)]` or manually implement `{Debug}`"), | |||
message="`{Self}` doesn't implement `{Debug}`", |
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.
Could you change the label to be just
`{Self}` cannot be formatted using `{{:?}}`
and add
note="you can add `#[derive(Debug)]` to `{Self}` or manually implement `{Debug}` for it",
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.
ok, added labels
src/libcore/fmt/mod.rs
Outdated
@@ -611,7 +611,8 @@ pub trait Debug { | |||
#[rustc_on_unimplemented( | |||
message="`{Self}` doesn't implement `{Display}`", | |||
label="`{Self}` cannot be formatted with the default formatter; \ | |||
try using `:?` instead if you are using a format string", | |||
try using `{{:?}}` (or {{:#?}} for pretty-print) instead \ | |||
if you are using a format string", |
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.
Same as above, could this be a note
instead?
Also, I would alter the wording slightly:
label="`{Self}` cannot be formatted with the default formatter",
note="you might be able to use `{{:?}}` (or {{:#?}} for pretty-print) instead if `{Self}` implements `Debug`",
| | ||
= help: the trait `std::fmt::Display` is not implemented for `Foo` | ||
= note: in format strings you may be albe to use `{:?}` (or {:#?} for pretty-print) instead |
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.
"you might be albe to use" 👀
r me once the typo is fixed. @bors delegate=kornelski |
✌️ @kornelski can now approve this pull request |
@bors r+ |
📌 Commit 1e38eee has been approved by |
@estebank typo fixed |
Suggest more helpful formatting string Based on [user feedback](https://users.rust-lang.org/t/ux-feedback-from-a-rust-newbie/17220) the minimal suggestion of `:?` is unclear. Also `{:#?}` is much more readable than the standard debug, so this PR suggests it to help surface this nice feature.
☀️ Test successful - status-appveyor, status-travis |
Based on user feedback the minimal suggestion of
:?
is unclear.Also
{:#?}
is much more readable than the standard debug, so this PR suggests it to help surface this nice feature.