Skip to content

Commit ea1d9eb

Browse files
committed
Simplify Accepts, part 2.
There only needs to be one `Fn` per symbol, not multiple.
1 parent 92be9b0 commit ea1d9eb

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

compiler/rustc_attr_parsing/src/context.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ macro_rules! attribute_groups {
2828
) => {
2929
type Accepts = BTreeMap<
3030
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| {
@@ -268,16 +269,12 @@ impl<'sess> AttributeParser<'sess> {
268269
let parts = path.segments().map(|i| i.name).collect::<Vec<_>>();
269270

270271
if let [part] = &parts[..]
271-
&& let Some(accepts) = ATTRIBUTE_MAPPING.0.get(part)
272+
&& let Some(accept) = ATTRIBUTE_MAPPING.0.get(part)
272273
{
273-
for f in accepts {
274-
let cx = AcceptContext {
275-
group_cx: &group_cx,
276-
attr_span: lower_span(attr.span),
277-
};
278-
279-
f(&cx, &args)
280-
}
274+
let cx =
275+
AcceptContext { group_cx: &group_cx, attr_span: lower_span(attr.span) };
276+
277+
accept(&cx, &args)
281278
} else {
282279
// if we're here, we must be compiling a tool attribute... Or someone forgot to
283280
// parse their fancy new attribute. Let's warn them in any case. If you are that

0 commit comments

Comments
 (0)