Auto merge of #33706 - jseyfried:refactor_cfg, r=nrc
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
This commit is contained in:
@@ -1258,31 +1258,6 @@ impl CodeMap {
|
||||
return a;
|
||||
}
|
||||
|
||||
/// Check if the backtrace `subtrace` contains `suptrace` as a prefix.
|
||||
pub fn more_specific_trace(&self,
|
||||
mut subtrace: ExpnId,
|
||||
suptrace: ExpnId)
|
||||
-> bool {
|
||||
loop {
|
||||
if subtrace == suptrace {
|
||||
return true;
|
||||
}
|
||||
|
||||
let stop = self.with_expn_info(subtrace, |opt_expn_info| {
|
||||
if let Some(expn_info) = opt_expn_info {
|
||||
subtrace = expn_info.call_site.expn_id;
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
});
|
||||
|
||||
if stop {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn record_expansion(&self, expn_info: ExpnInfo) -> ExpnId {
|
||||
let mut expansions = self.expansions.borrow_mut();
|
||||
expansions.push(expn_info);
|
||||
|
||||
Reference in New Issue
Block a user