Imagine you're knee deep in some library code that is generics heavy when something unexpected happens.
You'd like to
dbg!(...) a few things to take a peek at what's going on. Alas, while they very likely concretely implement
Debug, you haven't littered
Debug all over your generic trait bounds so Rust politely tells you it can't do it.
What to do?
The obvious answer is to go litter
Debug over all of your trait bounds until things work and, as far as I'm aware, is all you really can do today short of stepping through with a debugger which isn't really the same thing and slightly misses the point.
What I want to reach for (and what doesn't exist) is some magic to just let me auto-
Debug::fmt(...) this dang thing I want to peek at during development without adjusting a half dozen or more trait bounds across my code base.
In principle, there is no reason this couldn't be done in a number of ways (some more horrifying than others):
Debugfor all items, manual Debug impls specialize (discussed previously) - doesn't really fix the trait bounds thing but maybe the compiler could then assume all types are
- A magic
debug_dbg!(...)function/macro that, similar to
debug_assertion!(...)is stripped outside of debug builds. It would (in-effect, if not in practice)
impl Debugfor its argument if it wasn't already implemented. There might need to be an intrinsic for that because macros can't do that without more trickery than I'm aware of.
- I'm sure there are other options I'm not sufficiently clever to think of.
To re-iterate and head off some questions:
- the desire is for something like
dbg!(foo)to "just work"
- the reason why
#[derive(Debug)]doesn't necessarily fix this (and really invalidates some of the above options too), is that the problem can be trait bounds which shouldn't need to convey
Debugbounds down several layers of generics to have sane debugging during development.
I realize that the current situation isn't too bad, but I think it could be better and I'm interested in hearing what people think or if this is a ergonomics paper cut only I feel.