One thing that makes debugging kind of a pain is that the panics in
*::expect()) report the file and line inside the
unwrap() function when this is hardly ever relevant. The primary interest is almost always the call site of the
unwrap() instead, but this requires having backtraces and debug info; backtraces from panics in optimized code are rarely helpful because of aggressive inlining. This can be remedied just hand-inlining
unwrap() (or using a macro for convenience) but this is far from an optimal solution.
The idea itself is really basic: during inlining, replace the result of this block (and the one below it) as expanded in the panicking function with the values for the function’s call site.
I’m thinking it would add two attributes, one for stabilization and one internal to rustc. The first would be to annotate a function which wants to replace these values with those of its call-site, and then the second attribute annotates the aforementioned block so that the inlining pass knows that it should be replaced.
However, this would probably require some sort of inlining pass at the HIR level (when we still have access to this information) and sounds nontrivial. I’m not sure the slight gain to ergonomics compared to some high-level solution, like a version of
unwrap() that takes this file/line tuple, is worth the work, but maybe I’m underestimating the frustration that comes from misleading backtraces in release mode.