1
Fork 0

Rename known_attrs to expanded_inert_attrs and move to rustc_expand

There's no need for this to be (untracked) global state.
This commit is contained in:
Aaron Hill 2021-07-22 17:40:01 -05:00
parent 4a1f419e64
commit a2ae191295
No known key found for this signature in database
GPG key ID: B4087E510E98B164
3 changed files with 8 additions and 12 deletions

View file

@ -1,6 +1,7 @@
use crate::expand::{self, AstFragment, Invocation}; use crate::expand::{self, AstFragment, Invocation};
use crate::module::DirOwnership; use crate::module::DirOwnership;
use rustc_ast::attr::MarkedAttrs;
use rustc_ast::ptr::P; use rustc_ast::ptr::P;
use rustc_ast::token::{self, Nonterminal}; use rustc_ast::token::{self, Nonterminal};
use rustc_ast::tokenstream::{CanSynthesizeMissingTokens, TokenStream}; use rustc_ast::tokenstream::{CanSynthesizeMissingTokens, TokenStream};
@ -951,6 +952,10 @@ pub struct ExtCtxt<'a> {
/// ///
/// `Ident` is the module name. /// `Ident` is the module name.
pub(super) extern_mod_loaded: OnExternModLoaded<'a>, pub(super) extern_mod_loaded: OnExternModLoaded<'a>,
/// When we 'expand' an inert attribute, we leave it
/// in the AST, but insert it here so that we know
/// not to expand it again.
pub(super) expanded_inert_attrs: MarkedAttrs,
} }
impl<'a> ExtCtxt<'a> { impl<'a> ExtCtxt<'a> {
@ -977,6 +982,7 @@ impl<'a> ExtCtxt<'a> {
}, },
force_mode: false, force_mode: false,
expansions: FxHashMap::default(), expansions: FxHashMap::default(),
expanded_inert_attrs: MarkedAttrs::new(),
} }
} }

View file

@ -754,7 +754,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
} }
} }
SyntaxExtensionKind::NonMacroAttr { mark_used } => { SyntaxExtensionKind::NonMacroAttr { mark_used } => {
self.cx.sess.mark_attr_known(&attr); self.cx.expanded_inert_attrs.mark(&attr);
if *mark_used { if *mark_used {
self.cx.sess.mark_attr_used(&attr); self.cx.sess.mark_attr_used(&attr);
} }
@ -1040,7 +1040,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
item.visit_attrs(|attrs| { item.visit_attrs(|attrs| {
attr = attrs attr = attrs
.iter() .iter()
.position(|a| !self.cx.sess.is_attr_known(a) && !is_builtin_attr(a)) .position(|a| !self.cx.expanded_inert_attrs.is_marked(a) && !is_builtin_attr(a))
.map(|attr_pos| { .map(|attr_pos| {
let attr = attrs.remove(attr_pos); let attr = attrs.remove(attr_pos);
let following_derives = attrs[attr_pos..] let following_derives = attrs[attr_pos..]

View file

@ -219,7 +219,6 @@ pub struct Session {
/// Set of enabled features for the current target. /// Set of enabled features for the current target.
pub target_features: FxHashSet<Symbol>, pub target_features: FxHashSet<Symbol>,
known_attrs: Lock<MarkedAttrs>,
used_attrs: Lock<MarkedAttrs>, used_attrs: Lock<MarkedAttrs>,
/// `Span`s for `if` conditions that we have suggested turning into `if let`. /// `Span`s for `if` conditions that we have suggested turning into `if let`.
@ -1076,14 +1075,6 @@ impl Session {
== config::InstrumentCoverage::ExceptUnusedFunctions == config::InstrumentCoverage::ExceptUnusedFunctions
} }
pub fn mark_attr_known(&self, attr: &Attribute) {
self.known_attrs.lock().mark(attr)
}
pub fn is_attr_known(&self, attr: &Attribute) -> bool {
self.known_attrs.lock().is_marked(attr)
}
pub fn mark_attr_used(&self, attr: &Attribute) { pub fn mark_attr_used(&self, attr: &Attribute) {
self.used_attrs.lock().mark(attr) self.used_attrs.lock().mark(attr)
} }
@ -1389,7 +1380,6 @@ pub fn build_session(
miri_unleashed_features: Lock::new(Default::default()), miri_unleashed_features: Lock::new(Default::default()),
asm_arch, asm_arch,
target_features: FxHashSet::default(), target_features: FxHashSet::default(),
known_attrs: Lock::new(MarkedAttrs::new()),
used_attrs: Lock::new(MarkedAttrs::new()), used_attrs: Lock::new(MarkedAttrs::new()),
if_let_suggestions: Default::default(), if_let_suggestions: Default::default(),
}; };