Ideas around anonymous enum types

The usual stumbling block for anonymous enum proposals is that nobody can seem to come up with a good syntax for matching on the variants. But using anonymous enums solely for their trait impls completely bypasses that problem, so that is an interesting idea.

As you may already know, I've wanted enum impl Trait return types for a long time. That's usually considered separate from anonymous enums because enum impl Trait wouldn't require you to spell out the variants anywhere or allow you to match on them, but it looks like you've essentially merged the two ideas. In past discussions everyone seemed to agree that just impl Trait shouldn't autogenerate an enum and we wanted some kind of explicit opt-in marker like the enum keyword, but I don't recall any knockout argument for that so maybe I could be talked out of it.

My main knee-jerk concerns are that:

  • I'd expect this to wreak havoc with type inference, but we'll need someone far better informed than me to comment on how big of a problem that really is
  • If we're only using trait impls and not proposing a match syntax, then it's unclear how many of the use cases for typical anonymous enum proposals are covered, so this might be little more than two alternate syntaxes for enum impl Trait.
2 Likes