Rust-GCC / gccrs

GCC Front-End for Rust
https://rust-gcc.github.io/
GNU General Public License v2.0
2.37k stars 152 forks source link

Enforce rust keyword order #2819

Open P-E-P opened 8 months ago

P-E-P commented 8 months ago

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 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 commented 8 months ago

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 ?

braw-lee commented 7 months ago

I will try this

yomanthunder commented 1 day ago

@P-E-P Can I take up this issue ?

braw-lee commented 17 hours ago

@yomanthunder sure go ahead, you can check the draft PR to get an idea which files will need changes