|
| 1 | +use rustc_ast::{LitIntType, LitKind, MetaItemLit}; |
| 2 | + |
1 | 3 | use super::prelude::*; |
2 | 4 | use super::util::parse_single_integer; |
3 | 5 |
|
@@ -76,3 +78,47 @@ impl<S: Stage> SingleAttributeParser<S> for RustcSimdMonomorphizeLaneLimitParser |
76 | 78 | Some(AttributeKind::RustcSimdMonomorphizeLaneLimit(cx.parse_limit_int(nv)?)) |
77 | 79 | } |
78 | 80 | } |
| 81 | + |
| 82 | +pub(crate) struct RustcLegacyConstGenericsParser; |
| 83 | + |
| 84 | +impl<S: Stage> SingleAttributeParser<S> for RustcLegacyConstGenericsParser { |
| 85 | + const PATH: &[Symbol] = &[sym::rustc_legacy_const_generics]; |
| 86 | + const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost; |
| 87 | + const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error; |
| 88 | + const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Fn)]); |
| 89 | + const TEMPLATE: AttributeTemplate = template!(List: &["N"]); |
| 90 | + |
| 91 | + fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> { |
| 92 | + let ArgParser::List(meta_items) = args else { |
| 93 | + cx.expected_list(cx.attr_span, args); |
| 94 | + return None; |
| 95 | + }; |
| 96 | + |
| 97 | + let mut parsed_indexes = ThinVec::new(); |
| 98 | + let mut errored = false; |
| 99 | + |
| 100 | + for possible_index in meta_items.mixed() { |
| 101 | + if let MetaItemOrLitParser::Lit(MetaItemLit { |
| 102 | + kind: LitKind::Int(index, LitIntType::Unsuffixed), |
| 103 | + .. |
| 104 | + }) = possible_index |
| 105 | + { |
| 106 | + parsed_indexes.push((index.0 as usize, possible_index.span())); |
| 107 | + } else { |
| 108 | + cx.expected_integer_literal(possible_index.span()); |
| 109 | + errored = true; |
| 110 | + } |
| 111 | + } |
| 112 | + if errored { |
| 113 | + return None; |
| 114 | + } else if parsed_indexes.is_empty() { |
| 115 | + cx.expected_at_least_one_argument(args.span()?); |
| 116 | + return None; |
| 117 | + } |
| 118 | + |
| 119 | + Some(AttributeKind::RustcLegacyConstGenerics { |
| 120 | + fn_indexes: parsed_indexes, |
| 121 | + attr_span: cx.attr_span, |
| 122 | + }) |
| 123 | + } |
| 124 | +} |
0 commit comments