derive(Debug) on simple enums should emit a single call to Formatter::write_str #106875
Labels
A-macros
Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
A-proc-macros
Area: Procedural macros
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
Currently, this code:
Expands to this:
It should expand to this instead:
The current version compiles to MIR that looks like this:
Hoisting the
write_str
out of the match should dramatically reduce the amount of MIR we generate.@Kixiron suggested that storing all the string literals in an array and indexing into it with the discriminant might be even better, with the extra requirement that the discriminants are consecutive. That sounds more complicated to me in implementation, though it would have the nice extra benefit of generating a function body that is O(1) with respect to the number of variants in the enum.
This is similar to #88793, the change I'm looking for here would let such an optimization apply.
@rustbot label +C-enhancement +A-macros +A-proc-macros
The text was updated successfully, but these errors were encountered: