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

Allow #![] attributes to work in 0.16 #384

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wycats
Copy link
Contributor

@wycats wycats commented Jun 17, 2018

In 0.16, the default mode for lalrpop will import the generated module
through a macro that include!s the contents.

PR #338 made it possible to use include! with vanilla modules by
moving all of the built-in whole-module attributes to individual
modules. However, #115 places user-generated outer attributes in the
same problematic location.

This PR moves user-supplied outer attributes to the same location as
the fix in #338.

In 0.16, the default mode for lalrpop will import the generated module
through a macro that `include!`s the contents.

PR lalrpop#338 made it possible to use `include!` with vanilla modules by
moving all of the built-in whole-module attributes to individual
modules. However, lalrpop#115 places user-generated outer attributes in the
same problematic location.

This PR moves user-supplied outer attributes to the same location as
the fix in lalrpop#338.
Copy link
Collaborator

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some concerns about this change -- it feels surprising to emit the module attributes also on the internal modules. Maybe we should add some kind of explicit Edition support, if that is the main motivation?

@@ -160,13 +160,6 @@ impl<W: Write> RustWrite<W> {
Ok(())
}

pub fn write_module_attributes(&mut self, grammar: &Grammar) -> io::Result<()> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't usually edit lalrpop-snap

grammar: &r::Grammar,
rust: &mut RustWrite<W>,
) -> io::Result<()> {
rust.write_module_attributes(grammar)
rust!(rust, "#[cfg_attr(rustfmt, rustfmt_skip)]");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something feels fishy about this. This attribute is going to apply to the next module thing that gets emitted ... oh, I see, and the for loop below is intentionally converting #![foo] into #[foo]?

@nikomatsakis
Copy link
Collaborator

OK, re-reading your comment, I think I understand better. So there are two distinct things going on here:

  • Converting #![foo] to #[foo] -- this may indeed be a good idea, given the problems around #![] attributes and include! (IIUC)
  • Apply those attributes to all the generated submodules -- I'm less sure about this, but it may make sense? I'm not sure if there was a direct motivation for this.

@nikomatsakis
Copy link
Collaborator

Ah, probably we apply the attributes to the submodules just because it's not obvious how to apply them .. otherwise?

@Marwes
Copy link
Contributor

Marwes commented Jun 19, 2018

Ah, probably we apply the attributes to the submodules just because it's not obvious how to apply them .. otherwise?

Yep. rust-lang/rust#18810

@Marwes
Copy link
Contributor

Marwes commented Aug 31, 2018

Thinking about it, perhaps we could wrap the generated module as

mod name {
    #![attr]
     // Rest of the code goes here
}
pub use name::{Parser, ..};

@alercah
Copy link
Contributor

alercah commented Jan 17, 2019

Personally I think I'm inclined to the mod_path! workaround, because it allows attaching other attributes from the outside too:

#[deny(...)]
lalrpop_mod!(...);

@alercah
Copy link
Contributor

alercah commented Jan 17, 2019

Oh, nevermind, this is already supported, just with slightly different syntax. But still, I think that's the more elegant solution anyhow.

@alercah
Copy link
Contributor

alercah commented Jan 17, 2019

Would you be interested in a pull request for this?

@franleplant
Copy link

Hi guys! I have a question, #115 allegedly allowed attributes in top of the grammar file, I tried with 0.16.x and it doesnt work, and then I see this PR.

From what I understand, and, as a nice recap for future people, did this feature broke on 0.16.x and that is why this PR exists?

@franleplant
Copy link

@nikomatsakis how about adding by default a #[allow(clippy::all)] to the synthesized module?

@NyxCode
Copy link

NyxCode commented Apr 23, 2020

For everyone who stumbled upon this issue:
the lalrpop_mod! macro can accept attributes like this: lalrpop_mod!(#[allow(clippy::all)] grammar);

@nikomatsakis nikomatsakis added this to the 1.0 milestone Mar 21, 2023
@nikomatsakis
Copy link
Collaborator

Thanks for the PR. We're going to reconsider this as we move towards 1.0, but deferring for now.

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

Successfully merging this pull request may close these issues.

None yet

6 participants