-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Perform cfg attribute processing during macro expansion and fix bugs
#33706
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
Conversation
61e9e91 to
aa36f63
Compare
|
☔ The latest upstream changes (presumably #33742) made this pull request unmergeable. Please resolve the merge conflicts. |
|
Rebased. |
src/libsyntax/config.rs
Outdated
|
|
||
| pub trait CfgFolder: fold::Folder { | ||
| fn in_cfg(&mut self, attrs: &[ast::Attribute]) -> bool; | ||
| fn visit_unconfigurable_expr(&mut self, _expr: &ast::Expr) {} |
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.
Could you document these methods please?
|
r+ with the comment added |
|
@nrc I made sure we process |
|
☔ The latest upstream changes (presumably #33766) made this pull request unmergeable. Please resolve the merge conflicts. |
…ng into `StripUnconfigured`
…ured item is allowed
9d84921 to
3636ce7
Compare
|
Rebased. |
|
@bors: r+ @jseyfried yes and yes |
|
📌 Commit 9d84921 has been approved by |
|
⌛ Testing commit 9d84921 with merge 4d92f83... |
|
💔 Test failed - auto-win-gnu-32-opt-rustbuild |
|
@bors retry |
|
⌛ Testing commit 9d84921 with merge 8be1128... |
|
💔 Test failed - auto-win-gnu-32-opt-rustbuild |
|
@bors r=nrc |
|
📌 Commit 53ab137 has been approved by |
Perform `cfg` attribute processing during macro expansion and fix bugs
This PR refactors `cfg` attribute processing and fixes bugs. More specifically:
- It merges gated feature checking for stmt/expr attributes, `cfg_attr` processing, and `cfg` processing into a single fold.
- This allows feature gated `cfg` variables to be used in `cfg_attr` on unconfigured items. All other feature gated attributes can already be used on unconfigured items.
- It performs `cfg` attribute processing during macro expansion instead of after expansion so that macro-expanded items are configured the same as ordinary items. In particular, to match their non-expanded counterparts,
- macro-expanded unconfigured macro invocations are no longer expanded,
- macro-expanded unconfigured macro definitions are no longer usable, and
- feature gated `cfg` variables on macro-expanded macro definitions/invocations are now errors.
This is a [breaking-change]. For example, the following would break:
```rust
macro_rules! m {
() => {
#[cfg(attr)]
macro_rules! foo { () => {} }
foo!(); // This will be an error
macro_rules! bar { () => { fn f() {} } }
#[cfg(attr)] bar!(); // This will no longer be expanded ...
fn g() { f(); } // ... so that `f` will be unresolved.
#[cfg(target_thread_local)] // This will be a gated feature error
macro_rules! baz { () => {} }
}
}
m!();
```
r? @nrc
|
Fixes #22250. |
|
Fixes #31369. |
This PR refactors
cfgattribute processing and fixes bugs. More specifically:cfg_attrprocessing, andcfgprocessing into a single fold.cfgvariables to be used incfg_attron unconfigured items. All other feature gated attributes can already be used on unconfigured items.cfgattribute processing during macro expansion instead of after expansion so that macro-expanded items are configured the same as ordinary items. In particular, to match their non-expanded counterparts,cfgvariables on macro-expanded macro definitions/invocations are now errors.This is a [breaking-change]. For example, the following would break:
EDIT: fixes #22250, fixes #31369.
r? @nrc