Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Allow module attributes #686

Open
kleinesfilmroellchen opened this issue Sep 19, 2022 · 1 comment
Open

Feature request: Allow module attributes #686

kleinesfilmroellchen opened this issue Sep 19, 2022 · 1 comment

Comments

@kleinesfilmroellchen
Copy link

My use case for this is to turn off various lints for the LALRPOP generated file, as it violates a lot of pedantic/nursery clippy hints that I like to have in the rest of my project.

Currently, using a module attribute at the beginning of a file:

#![allow(clippy::all, clippy::pedantic, clippy::nursery)]

use some_module::ImportantStruct;
// ...

grammar;

// ...

causes this error:

error: an inner attribute is not permitted in this context
 --> out/generated.rs:3:1
  |
3 | #![allow(clippy::all, clippy::pedantic, clippy::nursery)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4 | use some_module::ImportantStruct;
  | --------------------------------- the inner attribute doesn't annotate this `use` import
  |
  = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files
help: to annotate the `use` import, change the attribute from inner to outer style
  |
3 - #![allow(clippy::all, clippy::pedantic, clippy::nursery)]
3 + #[allow(clippy::all, clippy::pedantic, clippy::nursery)]
  |

This is confusing, because the generated file correctly contains the module attribute at the beginning of the file, just below the sha3 line. However, the generated code contains its module attributes (which includes an allow(clippy::all)) at the beginning of the contained mod __parse__GlobalNonterminal, where GlobalNonTerminal is the (only) pub-declared non-terminal of the grammar. Therefore, it should probably be possible to move these attributes down in in the generated code. After all, it seems like LALRPOP parses them correctly at the beginning of files; in other places they cause a syntax error.

@Pat-Lafon
Copy link
Contributor

Is this still reproducible? I've done something similar with https://github.com/sampsyo/bril/blob/main/bril-rs/bril2json/src/bril_grammar.lalrpop and afaik that works as expected(I've also been trying to get lalrpop to pass more of these lints). How do you include this file so I can try it out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants