-
Notifications
You must be signed in to change notification settings - Fork 293
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
base: master
Are you sure you want to change the base?
Conversation
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.
There was a problem hiding this 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<()> { |
There was a problem hiding this comment.
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)]"); |
There was a problem hiding this comment.
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]
?
OK, re-reading your comment, I think I understand better. So there are two distinct things going on here:
|
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 |
Thinking about it, perhaps we could wrap the generated module as
|
Personally I think I'm inclined to the #[deny(...)]
lalrpop_mod!(...); |
Oh, nevermind, this is already supported, just with slightly different syntax. But still, I think that's the more elegant solution anyhow. |
Would you be interested in a pull request for this? |
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? |
@nikomatsakis how about adding by default a |
For everyone who stumbled upon this issue: |
Thanks for the PR. We're going to reconsider this as we move towards 1.0, but deferring for now. |
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 bymoving 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.