Skip to content

Enforce rust keyword order #2819

Open
Open
@P-E-P

Description

@P-E-P

Rust keyword should be used in a given order

  1. pub
  2. default
  3. const
  4. async
  5. unsafe
  6. extern

Rust provides multiple messages and notes to help with that:

5 | extern const pub fn myfun() {
  | -------^^^^^
  | |      |
  | |      expected `fn`
  | help: `const` must come before `extern`: `const extern`
  |
  = note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
  • We do have some FunctionQualifier structure to store the state of a function but not all those informations are kept in it.
  • We parse in different ways those qualifiers and provide multiple error message.

We should probably unify all those under one same structure (FunctionQualifier) and create a function to parse a FunctionQualifier that could be used everytime we expect a function.

This function could emit an error as well as a note (rust_note) when the syntax is wrong.

Choose an appropriate API for this function. Should it return an Optional<FunctionQualifier> ? Always return a FunctionQualifier with private/safe/sync attributes ? Probably the latter.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

To do

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions