Skip to content

Cannot name a struct field new due to ancient syntax #8088

Closed
@huonw

Description

@huonw
rusti> struct Foo { new: int }
<anon>:2:14: 2:17 error: obsolete syntax: struct constructor
<anon>:2  struct Foo { new: int } 
                       ^~~
note: structs are now constructed with `MyStruct { foo: val }` syntax. Structs with private fields cannot be created outside of their defining module
<anon>:2:17: 2:18 error: expected `(` but found `:`
<anon>:2  struct Foo { new: int } 
                          ^
rust: task failed at 'explicit failure', /home/huon/rust/src/libsyntax/diagnostic.rs:70

Note that new is a perfectly legal ident:

rusti> let new: uint = 1; new
1

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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions