-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 gate clean #32791
Feature gate clean #32791
Conversation
r? @nrc (rust_highfive has picked a reviewer for you, use r? to override) |
fc6a691
to
0629913
Compare
@eddyb: Ha, I see we used the same trick for spans for |
@LeoTestard AFAICT syntex was fixed not to generate code that trips over such a check, but @nikomatsakis would still like a warning for a release cycle (old syntex output might still be around). |
You mean (well, he means) generate a warning instead of an error? That sounds tricky with my approach since the check in |
@LeoTestard the error is not "from syntex", but rather you get a file that syntex pretty-printed. I can't think of a way to distinguish that, since the actual code could be anything the user put through syntex. |
0629913
to
71c4e6f
Compare
Ok now it should only warn for Note that this PR is still a breaking change for all the other uses of feature-gated attributes that were not checked in macro expansion (see #32782) and that are now checked and just reported as errors. r? |
71c4e6f
to
5074c7c
Compare
☔ The latest upstream changes (presumably #32016) made this pull request unmergeable. Please resolve the merge conflicts. |
7493c3c
to
f654c8c
Compare
Rebased onto master. r? |
@LeoTestard I believe this PR is only feature gate checking attributes of macros in item positions. For example, the following would be erroneously allowed (it is an currently error): macro_rules! method {
() => { fn f() {} }
}
struct S;
impl S {
#[allow_internal_unstable]
method! {}
} |
@@ -96,6 +96,36 @@ fn expand_derive(cx: &mut ExtCtxt, | |||
let mut found_partial_eq = false; | |||
let mut found_eq = false; | |||
|
|||
// This span is **very** sensitive and crucial to | |||
// getting the stability behavior we want. What we are | |||
// doing is marking `#[structural_match]` with the |
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.
If I understand correctly, we could also be marking #[derive_*]
with this span -- the comment should probably reflect that.
Reviewed, LGTM modulo comments. |
6151172
to
aa36987
Compare
@jseyfried Ok, I fixed what you said. I added another commit for removing useless code since it's not directly related. Let me know if you want me to squash it/rebase it/whatever. |
if let Some(&Features { pushpop_unsafe: false, .. }) = | ||
fld.cx.ecfg.features { | ||
feature_gate::emit_feature_err( | ||
&fld.cx.parse_sess.span_diagnostic, "pushpop_unsafe", expr_span, |
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.
This should be "placement_in_syntax"
(Travis is failing because of this).
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.
Yeah I saw that but I didn't have the time to fix it earlier... I guess I copy-pasted too fast. Sorry about that.
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.
No prob!
2650886
to
cb29b20
Compare
&fld.cx.parse_sess.codemap(), | ||
&fld.cx.ecfg.features.unwrap()); | ||
} | ||
|
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 believe we still need to stability check macros in expression and statement positions (search for drop(attrs)
in this file).
I would refactor this out into a new function in expand.rs
(something like check_attributes(attr: &ast::Attribute, fld: &mut MacroExpander)
) and then inline and remove feature_gate::check_attribute
.
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.
Are you sure we should inline? feature_gate::Context
is private for the moment...
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.
Good point -- not inlining is ok
Done. r? |
@LeoTestard it seems like tidy doesn't build on this branch? |
@nikomatsakis Huh, yeah, my bad, I thought I tested this but that was before I had to rebase it against the complete rewriting of tidy checks I guess. u__u |
fa121f4
to
21bf716
Compare
@nikomatsakis Fixed, I think. |
21bf716
to
fa23d10
Compare
This pass was supposed to check use of gated features before `#[cfg]`-stripping but this was not the case since it in fact happens after. Checks that are actually important and must be done before macro expansion are now made where the features are actually used. Close rust-lang#32648. Also ensure that attributes on macro-generated macro invocations are checked as well. Close rust-lang#32782 and rust-lang#32655.
@bors r+ |
📌 Commit fa23d10 has been approved by |
Feature gate clean This PR does a bit of cleaning in the feature-gate-handling code of libsyntax. It also fixes two bugs (#32782 and #32648). Changes include: * Change the way the existing features are declared in `feature_gate.rs`. The array of features and the `Features` struct are now defined together by a single macro. `featureck.py` has been updated accordingly. Note: there are now three different arrays for active, removed and accepted features instead of a single one with a `Status` item to tell wether a feature is active, removed, or accepted. This is mainly due to the way I implemented my macro in the first time and I can switch back to a single array if needed. But an advantage of the way it is now is that when an active feature is used, the parser only searches through the list of active features. It goes through the other arrays only if the feature is not found. I like to think that error checking (in this case, checking that an used feature is active) does not slow down compilation of valid code. :) But this is not very important... * Feature-gate checking pass now use the `Features` structure instead of looking through a string vector. This should speed them up a bit. The construction of the `Features` struct should be faster too since it is build directly when parsing features instead of calling `has_feature` dozens of times. * The MacroVisitor pass has been removed, it was mostly useless since the `#[cfg]-stripping` phase happens before (fixes #32648). The features that must actually be checked before expansion are now checked at the time they are used. This also allows us to check attributes that are generated by macro expansion and not visible to MacroVisitor, but are also removed by macro expansion and thus not visible to PostExpansionVisitor either. This fixes #32782. Note that in order for `#[derive_*]` to be feature-gated but still accepted when generated by `#[derive(Trait)]`, I had to do a little bit of trickery with spans that I'm not totally confident into. Please review that part carefully. (It's in `libsyntax_ext/deriving/mod.rs`.):: Note: this is a [breaking change], since programs with feature-gated attributes on macro-generated macro invocations were not rejected before. For example: ```rust macro_rules! bar ( () => () ); macro_rules! foo ( () => ( #[allow_internal_unstable] //~ ERROR allow_internal_unstable side-steps bar!(); ); ); ``` foo!();
This PR does a bit of cleaning in the feature-gate-handling code of libsyntax. It also fixes two bugs (#32782 and #32648). Changes include:
feature_gate.rs
. The array of features and theFeatures
struct are now defined together by a single macro.featureck.py
has been updated accordingly. Note: there are now three different arrays for active, removed and accepted features instead of a single one with aStatus
item to tell wether a feature is active, removed, or accepted. This is mainly due to the way I implemented my macro in the first time and I can switch back to a single array if needed. But an advantage of the way it is now is that when an active feature is used, the parser only searches through the list of active features. It goes through the other arrays only if the feature is not found. I like to think that error checking (in this case, checking that an used feature is active) does not slow down compilation of valid code. :) But this is not very important...Features
structure instead of looking through a string vector. This should speed them up a bit. The construction of theFeatures
struct should be faster too since it is build directly when parsing features instead of callinghas_feature
dozens of times.#[cfg]-stripping
phase happens before (fixes Invocation of feature-gated macros inside#[cfg]
-guarded code is not checked. #32648). The features that must actually be checked before expansion are now checked at the time they are used. This also allows us to check attributes that are generated by macro expansion and not visible to MacroVisitor, but are also removed by macro expansion and thus not visible to PostExpansionVisitor either. This fixes Attributes on macro-generated macro invocations are not feature-gate-checked #32782. Note that in order for#[derive_*]
to be feature-gated but still accepted when generated by#[derive(Trait)]
, I had to do a little bit of trickery with spans that I'm not totally confident into. Please review that part carefully. (It's inlibsyntax_ext/deriving/mod.rs
.)::Note: this is a [breaking change], since programs with feature-gated attributes on macro-generated macro invocations were not rejected before. For example:
foo!();