Skip to content

Require structs to use newtype form or have at least one field #5167

Closed
@nikomatsakis

Description

@nikomatsakis
Contributor

Per this thread on the mailing list, structs should be required to either be written struct Foo; or to have at least one field. This avoids various ambiguities when parsing.

Activity

thomaslee

thomaslee commented on Apr 4, 2013

@thomaslee
Contributor

Is this as simple as modifying the parser to prevent the "struct Foo {}" syntax (i.e. a struct with no fields) & modifying it to support the braceless syntax, or is more work needed to make it a newtype? And if so, what?

huonw

huonw commented on Apr 4, 2013

@huonw
Member

@thomaslee, this seems to have been done already:

$ cat empty-struct.rs
struct A {}
fn main() {}

$ rustc empty-struct.rs
empty-struct.rs:1:10: 1:11 error: Unit-like struct should be written as: struct A;
empty-struct.rs:1 struct A {}
                            ^

(ping @nikomatsakis, you can probably close this.)

thomaslee

thomaslee commented on Apr 4, 2013

@thomaslee
Contributor

Ah good catch @dbaupp -- thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-parserArea: The lexing & parsing of Rust source code to an AST

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @thomaslee@nikomatsakis@huonw@thestinger

        Issue actions

          Require structs to use newtype form or have at least one field · Issue #5167 · rust-lang/rust