gccrs icon indicating copy to clipboard operation
gccrs copied to clipboard

Enforce rust keyword order

Open P-E-P opened this issue 1 year ago • 4 comments

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.

P-E-P avatar Jan 29 '24 16:01 P-E-P

Maybe we should wait for #2815 to be merged ? Also, rustc use unified Function and ExternalFunction, maybe we should do the same since function body is now optional ?

P-E-P avatar Jan 29 '24 16:01 P-E-P

I will try this

braw-lee avatar Feb 24 '24 02:02 braw-lee