←back to thread

146 points returningfory2 | 1 comments | | HN request time: 0.637s | source
Show context
ComputerGuru ◴[] No.43650446[source]
I have actually requested an even more intelligent/aggressive size optimization for nested enums, where values are automatically reassigned to not coincide/conflict to enable tag-less differentiation. Consensus was that it’s a big ask though doable, but maybe possible to implement in a more restrictive version.

https://rust-lang.zulipchat.com/#narrow/channel/131828-t-com...

replies(1): >>43650788 #
1. infogulch ◴[] No.43650788[source]
Good idea! I like the solution of an explicit annotation setting the first variant's discriminant (the rest autoicrement?), which enables you to manually coordinate your enums to not overlap. Then an optimization for nested enums where if all cases are other enums with no overlapping discriminants they can all share one field. This seems achievable.

The "but do it automatically" part seems rather problematic. Requiring global analysis is a big ask indeed.

Say, if you change a variant's discriminant value, does that count as a semver breaking change? Probably. Would it be an ABI breaking change? Probably.