Question on recursive zero sized type

No practical use, just for theory. Recursive but zero-sized structure definition is not allowed.

struct Foo(Foo);

Different from other recursive types, Foo does not contain other fields, thus can be inferred to be zero-sized and can pass compiling, but actually not. Does rustc not recognize this, or is it physically not zero-sized?

I'd say it's just was not worth the trouble making this a special case. Since this is the only case when directly-recursive structures can be non-infintely-sized, it's just treated as any other recursive structure.

The diagnostic is technically wrong, though.

2 Likes

Closer to the former - structurally recursive types are not supported.

"What is the physical size?" is arguably a meaningless question for a type not considered well-formed by the language.

Related issues:

(Some of the issues demonstrate that Foo(Self) is not the only case.)

1 Like

Got it. Thanks.