-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Debug impl of Any could be improved #46261
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
Comments
panic! and assert! produce (usually) &str and String, so those would be good to cover. |
I could try to create a pull request. What format does the audience prefer? Delegate to the strings' |
One problem is that |
It would be nice if Any would write contents of any standard strings it contained in the implementation of Debug. Unfortunately, it cannot be done without hacking dynamic type resolution, since many strings that are typically dumped as Any exist as owned String values and String is up the foodchain from libcore where Any is defined. See rust-lang#46261 for some discussion.
So perhaps, the |
More discussion here: rust-lang/rfcs#1389 |
@abonander Thank you, I failed to search in the RFC issues. |
If we're just talking about changing the internals of an impl, I don't think it needs an RFC. I think most people would be happy with it printing the value if the internal type is |
The RFC-qualifying issue is that, as libcore does not know anything about owned types, it would need a special-case hook for what liballoc, or conceivably another library in the program's runtime stack, would supply as the typecheck and |
I can't think of a way that wouldn't be incredibly hacky or violate coherence. I think a specialized |
I'm going to go ahead and close this as it seems like it's quite hard to do in practice (due to not having the relevant types around). A PR for this would be the best way to land changes here, and discussion can happen on internals. |
The
Debug
impl ofAny
is currently very simple, it always returns"Any"
:This shows up in panic messages when e.g.
unwrap()
is called on athread::Result
of a panicked thread. The implementation could do what the default panic hook already does and try to downcast the reference to&'static str
andString
(and maybe alsoCow<'static, str>
, though that might be very unusual) and, if successful, include the contents into the output or simply delegate to the string'sDebug
.The text was updated successfully, but these errors were encountered: