Description
We currently have special syntax and semantics for "newtypes", which are defined as enums with one variant and one argument. For such enums, we overload the *
operator and support autoderef. They can be declared with the rather non-obvious notation of enum Foo = T
.
With the advent of structs, I think this special treatment has little purpose. We could as easily write:
struct Foo { repr: T }
and then create instances of such new types as Foo { repr: v }
. Accessing the representation of a newtype would simply be foo.repr
. It would not be possible to "autoderef" through a newtype'd value, but I am not sure if this is a problem---I have had problems where I introduced a newtype only to find that it was "leaking" out of its newtype wrapper due to implicit derefs I wasn't aware of.
Another advantage is that currently our method lookup rules must have a special case just to accommodate newtype'd enums. Currently we auto-deref as long as we can and then attempt auto-ref---except if one of the intermediate states is an enum, in which case we attempt auto-ref for that enum as well.