Wouldn’t it have to map to normal fields to allow normal function? If it looks like a field you’d probably want to support &mut val.foo
which won’t work with a const
, and taking a reference will generally be problematic if it’s a computed owned value. The latter would also mean you could hide computation behind field access, meaning foo.x + foo.x
could perform two computations (and maybe even mutations).
Another thing I’ve been wondering is how destructuring is going to work. E.g. let Foo { x, y } = value
when a trait supplies a new z
field. Without the mapping to fields, you might break code that destructures things if they have to be mentioned as well, or if you don’t have to mention it, you might introduce invisible and unexpected Drop::drop
invocations.
In general I’d be opposed to anything that can make x.foo
or let Foo { x }
panic.