Skip to content

Generate less code in impl TryFrom<EnumT> for VariantT impls.

Suppose you have an enum with n variants. We generate n TryFrom<EnumT> impls, one for each variant.

Previously each TryFrom impl would special-case each variant, to give a helpful error message saying "can't convert enum to variant X because it's actually Y".

The problem is that the amount of code generated is O(n^2). In my project, the TryFrom impls from just one enum are more than 10% of the project's total code post macro expansion! These LoC correspond fairly well to compile time.

This patch changes things so we generate just one error branch in each TryFrom impl, letting us generate O(n) code again.

Merge request reports

Loading