Skip to content

Should types that contain zero-length vectors of themselves be allowed? #11924

Open
@isabelmu

Description

@isabelmu

In the discussion of pull request #11839, which aims to check the representability of structs and enums properly in typeck, @huonw pointed out that the semantics for types that directly contain zero-length vectors of themselves are potentially still undecided.

Consider for example (play):

struct Foo {
    recur: [Foo; 0],
}

fn main() { }

If typeck allows enum Foo { A([Foo; 0]) } or
struct Bar { x: [Bar; 0] } then there is an infinite recursion + stack overflow in trans::adt::represent_type, so I will amend #11839 to disallow these cases and add a FIXME referencing this issue.

To me, it seems more consistent to allow any zero-length vector than to allow only some, but the only use case I can think of is that it may make some macros simpler to write.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-arrayArea: `[T; N]`A-type-systemArea: Type systemA-zstArea: Zero-sized types (ZSTs).C-bugCategory: This is a bug.T-langRelevant to the language team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions