Skip to content

Commit c673d3f

Browse files
authored
Rollup merge of #87389 - Aaron1011:expand-known-attrs, r=wesleywiser
Rename `known_attrs` to `expanded_inert_attrs` and move to rustc_expand There's no need for this to be (untracked) global state.
2 parents 9d45a01 + a2ae191 commit c673d3f

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

compiler/rustc_expand/src/base.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::expand::{self, AstFragment, Invocation};
22
use crate::module::DirOwnership;
33

4+
use rustc_ast::attr::MarkedAttrs;
45
use rustc_ast::ptr::P;
56
use rustc_ast::token::{self, Nonterminal};
67
use rustc_ast::tokenstream::{CanSynthesizeMissingTokens, TokenStream};
@@ -951,6 +952,10 @@ pub struct ExtCtxt<'a> {
951952
///
952953
/// `Ident` is the module name.
953954
pub(super) extern_mod_loaded: OnExternModLoaded<'a>,
955+
/// When we 'expand' an inert attribute, we leave it
956+
/// in the AST, but insert it here so that we know
957+
/// not to expand it again.
958+
pub(super) expanded_inert_attrs: MarkedAttrs,
954959
}
955960

956961
impl<'a> ExtCtxt<'a> {
@@ -977,6 +982,7 @@ impl<'a> ExtCtxt<'a> {
977982
},
978983
force_mode: false,
979984
expansions: FxHashMap::default(),
985+
expanded_inert_attrs: MarkedAttrs::new(),
980986
}
981987
}
982988

compiler/rustc_expand/src/expand.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
754754
}
755755
}
756756
SyntaxExtensionKind::NonMacroAttr { mark_used } => {
757-
self.cx.sess.mark_attr_known(&attr);
757+
self.cx.expanded_inert_attrs.mark(&attr);
758758
if *mark_used {
759759
self.cx.sess.mark_attr_used(&attr);
760760
}
@@ -1040,7 +1040,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
10401040
item.visit_attrs(|attrs| {
10411041
attr = attrs
10421042
.iter()
1043-
.position(|a| !self.cx.sess.is_attr_known(a) && !is_builtin_attr(a))
1043+
.position(|a| !self.cx.expanded_inert_attrs.is_marked(a) && !is_builtin_attr(a))
10441044
.map(|attr_pos| {
10451045
let attr = attrs.remove(attr_pos);
10461046
let following_derives = attrs[attr_pos..]

compiler/rustc_session/src/session.rs

-10
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ pub struct Session {
219219
/// Set of enabled features for the current target.
220220
pub target_features: FxHashSet<Symbol>,
221221

222-
known_attrs: Lock<MarkedAttrs>,
223222
used_attrs: Lock<MarkedAttrs>,
224223

225224
/// `Span`s for `if` conditions that we have suggested turning into `if let`.
@@ -1076,14 +1075,6 @@ impl Session {
10761075
== config::InstrumentCoverage::ExceptUnusedFunctions
10771076
}
10781077

1079-
pub fn mark_attr_known(&self, attr: &Attribute) {
1080-
self.known_attrs.lock().mark(attr)
1081-
}
1082-
1083-
pub fn is_attr_known(&self, attr: &Attribute) -> bool {
1084-
self.known_attrs.lock().is_marked(attr)
1085-
}
1086-
10871078
pub fn mark_attr_used(&self, attr: &Attribute) {
10881079
self.used_attrs.lock().mark(attr)
10891080
}
@@ -1389,7 +1380,6 @@ pub fn build_session(
13891380
miri_unleashed_features: Lock::new(Default::default()),
13901381
asm_arch,
13911382
target_features: FxHashSet::default(),
1392-
known_attrs: Lock::new(MarkedAttrs::new()),
13931383
used_attrs: Lock::new(MarkedAttrs::new()),
13941384
if_let_suggestions: Default::default(),
13951385
};

0 commit comments

Comments
 (0)