|
| 1 | +use rustc_feature::AttributeTemplate; |
| 2 | +use rustc_hir::attrs::{AttributeKind, CfgEntry}; |
| 3 | +use rustc_span::{Symbol, sym}; |
| 4 | + |
| 5 | +use crate::{parse_cfg_entry, CFG_TEMPLATE}; |
| 6 | +use crate::attributes::{CombineAttributeParser, ConvertFn}; |
| 7 | +use crate::context::{AcceptContext, Stage}; |
| 8 | +use crate::parser::ArgParser; |
| 9 | +use crate::target_checking::{ALL_TARGETS, AllowedTargets}; |
| 10 | + |
| 11 | +pub(crate) struct CfgTraceParser; |
| 12 | + |
| 13 | +impl<S: Stage> CombineAttributeParser<S> for CfgTraceParser { |
| 14 | + const PATH: &[Symbol] = &[sym::cfg_trace]; |
| 15 | + type Item = CfgEntry; |
| 16 | + const CONVERT: ConvertFn<Self::Item> = AttributeKind::CfgTrace; |
| 17 | + const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS); |
| 18 | + const TEMPLATE: AttributeTemplate = CFG_TEMPLATE; |
| 19 | + |
| 20 | + fn extend( |
| 21 | + cx: &mut AcceptContext<'_, '_, S>, |
| 22 | + args: &ArgParser, |
| 23 | + ) -> impl IntoIterator<Item = Self::Item> { |
| 24 | + let Some(list) = args.list() else { |
| 25 | + cx.expected_list(cx.attr_span, args); |
| 26 | + return None; |
| 27 | + }; |
| 28 | + let Some(entry) = list.single() else { |
| 29 | + cx.expected_single_argument(list.span); |
| 30 | + return None; |
| 31 | + }; |
| 32 | + |
| 33 | + parse_cfg_entry(cx, entry).ok() |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +pub(crate) struct CfgAttrTraceParser; |
| 38 | + |
| 39 | +impl<S: Stage> CombineAttributeParser<S> for CfgAttrTraceParser { |
| 40 | + const PATH: &[Symbol] = &[sym::cfg_attr_trace]; |
| 41 | + type Item = (); |
| 42 | + const CONVERT: ConvertFn<Self::Item> = AttributeKind::CfgAttrTrace; |
| 43 | + const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS); |
| 44 | + const TEMPLATE: AttributeTemplate = CFG_TEMPLATE; |
| 45 | + |
| 46 | + fn extend( |
| 47 | + _cx: &mut AcceptContext<'_, '_, S>, |
| 48 | + _args: &ArgParser, |
| 49 | + ) -> impl IntoIterator<Item = Self::Item> { |
| 50 | + Some(()) |
| 51 | + } |
| 52 | +} |
0 commit comments