Skip to content

box syntax #405

Closed
Closed
@ftxqxd

Description

@ftxqxd

The current box syntax (box(PLACE) EXPR) has a few flaws in my opinion:

  • it makes it difficult to parenthesise the expression if the place is omitted, which is quite a commonly-encountered scenario;
  • it resembles a function call, although it’s not really a function.

This syntax never went through a proper RFC, so it didn’t get much feedback. Here are some ideas I’ve come up with or have maybe seen about the place; I don’t really like any of them much, but they mostly fix my issues with the current syntax:

  • box(in PLACE) EXPR: resolves parsing issues, but looks a bit weird;
  • box EXPR in PLACE: resolves parsing issues and looks less like a function call, but moves the place to the end, which is not usually desirable as the expression is usually longer;
  • box::(PLACE) EXPR: resolves parsing issues and looks very weird, but less like a function call. Steals syntax from disambiguating generic method calls;
  • box(PLACE) EXPR (the current syntax), but after parsing the ) after the place, check that the next token can start an expression (the strategy adopted by Parse bracketed box expressions rust#16863). Still has a bit of ambiguity in if/while/for expressions (e.g., if foo == box (bar) { ... }), but otherwise resolves most parsing issues. Has the advantage of simplicity.

If the current syntax stays, we should at least omit a helpful message whenever the expression is missing from a box expression. I plan on implementing this shortly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions