Skip to content

Wrong error message trying to initialise an empty struct  #3192

Closed
@bblum

Description

@bblum

Updated bug report

Compiling this (erroneous) program:

struct mutex;
fn main() {
    let x = mutex { }; // this should be `let x = mutex;`
    println(fmt!("%?", x));
}

yields:

/tmp/foo.rs:3:18: 3:19 error: expected `;` but found `{`
/tmp/foo.rs:3     let x = mutex { };

We currently emit a nice error message if you incorrectly write the struct mutex definition as:

struct mutex { }

that tells you that you need to write the Unit-like struct as struct mutex;; we should do the same for the struct initialization expression.

Original bug report

struct mutex { }
fn main() {
    let x = mutex { };
}

gives:

struct.rs:3:18: 3:19 error: expected `;` but found `{`
struct.rs:3     let x = mutex { };

but if you comment out the let x line, it gives:

struct.rs:1:0: 1:16 error: a class must have at least one field
struct.rs:1 struct mutex { }

Personally, I think we should be allowed to have empty structs, but either way, the latter error message should have higher priority(?) than the former.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-frontendArea: Compiler frontend (errors, parsing and HIR)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions