diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2025-05-01 16:09:16 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2025-05-20 09:12:24 +1000 |
| commit | 5b808b7da8df062f1c4d5d73c98e19e6cc4b283b (patch) | |
| tree | dd01a37a62ddbfb808f84ae3d26ac7f28a4de8d1 | |
| parent | e139d268f0d863fb45111b64dff7c981a377c8af (diff) | |
| download | rust-5b808b7da8df062f1c4d5d73c98e19e6cc4b283b.tar.gz rust-5b808b7da8df062f1c4d5d73c98e19e6cc4b283b.zip | |
Simplify `Accepts`.
There only needs to be one `Fn` per symbol, not multiple.
| -rw-r--r-- | compiler/rustc_attr_parsing/src/context.rs | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs index 6edb9133eab..aef803c7442 100644 --- a/compiler/rustc_attr_parsing/src/context.rs +++ b/compiler/rustc_attr_parsing/src/context.rs @@ -28,7 +28,7 @@ macro_rules! attribute_groups { ) => { type Accepts = BTreeMap< &'static [Symbol], - Vec<Box<dyn Send + Sync + Fn(&AcceptContext<'_>, &ArgParser<'_>)>> + Box<dyn Send + Sync + Fn(&AcceptContext<'_>, &ArgParser<'_>)> >; type Finalizes = Vec< Box<dyn Send + Sync + Fn(&FinalizeContext<'_>) -> Option<AttributeKind>> @@ -43,11 +43,12 @@ macro_rules! attribute_groups { }; for (k, v) in <$names>::ATTRIBUTES { - accepts.entry(*k).or_default().push(Box::new(|cx, args| { + let old = accepts.insert(*k, Box::new(|cx, args| { STATE_OBJECT.with_borrow_mut(|s| { v(s, cx, args) }) })); + assert!(old.is_none()); } finalizes.push(Box::new(|cx| { @@ -267,15 +268,11 @@ impl<'sess> AttributeParser<'sess> { let (path, args) = parser.deconstruct(); let parts = path.segments().map(|i| i.name).collect::<Vec<_>>(); - if let Some(accepts) = ATTRIBUTE_MAPPING.0.get(parts.as_slice()) { - for f in accepts { - let cx = AcceptContext { - group_cx: &group_cx, - attr_span: lower_span(attr.span), - }; + if let Some(accept) = ATTRIBUTE_MAPPING.0.get(parts.as_slice()) { + let cx = + AcceptContext { group_cx: &group_cx, attr_span: lower_span(attr.span) }; - f(&cx, &args) - } + accept(&cx, &args) } else { // if we're here, we must be compiling a tool attribute... Or someone forgot to // parse their fancy new attribute. Let's warn them in any case. If you are that |
