Skip to content

Commit 5b808b7

Browse files
committed
Simplify Accepts.
There only needs to be one `Fn` per symbol, not multiple.
1 parent e139d26 commit 5b808b7

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ macro_rules! attribute_groups {
2828
) => {
2929
type Accepts = BTreeMap<
3030
&'static [Symbol],
31-
Vec<Box<dyn Send + Sync + Fn(&AcceptContext<'_>, &ArgParser<'_>)>>
31+
Box<dyn Send + Sync + Fn(&AcceptContext<'_>, &ArgParser<'_>)>
3232
>;
3333
type Finalizes = Vec<
3434
Box<dyn Send + Sync + Fn(&FinalizeContext<'_>) -> Option<AttributeKind>>
@@ -43,11 +43,12 @@ macro_rules! attribute_groups {
4343
};
4444

4545
for (k, v) in <$names>::ATTRIBUTES {
46-
accepts.entry(*k).or_default().push(Box::new(|cx, args| {
46+
let old = accepts.insert(*k, Box::new(|cx, args| {
4747
STATE_OBJECT.with_borrow_mut(|s| {
4848
v(s, cx, args)
4949
})
5050
}));
51+
assert!(old.is_none());
5152
}
5253

5354
finalizes.push(Box::new(|cx| {
@@ -267,15 +268,11 @@ impl<'sess> AttributeParser<'sess> {
267268
let (path, args) = parser.deconstruct();
268269
let parts = path.segments().map(|i| i.name).collect::<Vec<_>>();
269270

270-
if let Some(accepts) = ATTRIBUTE_MAPPING.0.get(parts.as_slice()) {
271-
for f in accepts {
272-
let cx = AcceptContext {
273-
group_cx: &group_cx,
274-
attr_span: lower_span(attr.span),
275-
};
271+
if let Some(accept) = ATTRIBUTE_MAPPING.0.get(parts.as_slice()) {
272+
let cx =
273+
AcceptContext { group_cx: &group_cx, attr_span: lower_span(attr.span) };
276274

277-
f(&cx, &args)
278-
}
275+
accept(&cx, &args)
279276
} else {
280277
// if we're here, we must be compiling a tool attribute... Or someone forgot to
281278
// parse their fancy new attribute. Let's warn them in any case. If you are that

0 commit comments

Comments
 (0)