|
| 1 | +use super::prelude::*; |
| 2 | + |
| 3 | +pub(crate) struct RustcAllocatorParser; |
| 4 | + |
| 5 | +impl<S: Stage> NoArgsAttributeParser<S> for RustcAllocatorParser { |
| 6 | + const PATH: &[Symbol] = &[sym::rustc_allocator]; |
| 7 | + const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error; |
| 8 | + const ALLOWED_TARGETS: AllowedTargets = |
| 9 | + AllowedTargets::AllowList(&[Allow(Target::Fn), Allow(Target::ForeignFn)]); |
| 10 | + const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcAllocator; |
| 11 | +} |
| 12 | + |
| 13 | +pub(crate) struct RustcAllocatorZeroedParser; |
| 14 | + |
| 15 | +impl<S: Stage> NoArgsAttributeParser<S> for RustcAllocatorZeroedParser { |
| 16 | + const PATH: &[Symbol] = &[sym::rustc_allocator_zeroed]; |
| 17 | + const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error; |
| 18 | + const ALLOWED_TARGETS: AllowedTargets = |
| 19 | + AllowedTargets::AllowList(&[Allow(Target::Fn), Allow(Target::ForeignFn)]); |
| 20 | + const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcAllocatorZeroed; |
| 21 | +} |
| 22 | + |
| 23 | +pub(crate) struct RustcAllocatorZeroedVariantParser; |
| 24 | + |
| 25 | +impl<S: Stage> SingleAttributeParser<S> for RustcAllocatorZeroedVariantParser { |
| 26 | + const PATH: &[Symbol] = &[sym::rustc_allocator_zeroed_variant]; |
| 27 | + const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error; |
| 28 | + const ALLOWED_TARGETS: AllowedTargets = |
| 29 | + AllowedTargets::AllowList(&[Allow(Target::Fn), Allow(Target::ForeignFn)]); |
| 30 | + const TEMPLATE: AttributeTemplate = template!(NameValueStr: "function"); |
| 31 | + const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost; |
| 32 | + fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> { |
| 33 | + let Some(name) = args.name_value().and_then(NameValueParser::value_as_str) else { |
| 34 | + cx.expected_name_value(cx.attr_span, None); |
| 35 | + return None; |
| 36 | + }; |
| 37 | + |
| 38 | + Some(AttributeKind::RustcAllocatorZeroedVariant { name }) |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +pub(crate) struct RustcDeallocatorParser; |
| 43 | + |
| 44 | +impl<S: Stage> NoArgsAttributeParser<S> for RustcDeallocatorParser { |
| 45 | + const PATH: &[Symbol] = &[sym::rustc_deallocator]; |
| 46 | + const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error; |
| 47 | + const ALLOWED_TARGETS: AllowedTargets = |
| 48 | + AllowedTargets::AllowList(&[Allow(Target::Fn), Allow(Target::ForeignFn)]); |
| 49 | + const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDeallocator; |
| 50 | +} |
| 51 | + |
| 52 | +pub(crate) struct RustcReallocatorParser; |
| 53 | + |
| 54 | +impl<S: Stage> NoArgsAttributeParser<S> for RustcReallocatorParser { |
| 55 | + const PATH: &[Symbol] = &[sym::rustc_reallocator]; |
| 56 | + const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error; |
| 57 | + const ALLOWED_TARGETS: AllowedTargets = |
| 58 | + AllowedTargets::AllowList(&[Allow(Target::Fn), Allow(Target::ForeignFn)]); |
| 59 | + const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcReallocator; |
| 60 | +} |
0 commit comments