Skip to main content

rustc_attr_parsing/attributes/
rustc_allocator.rs

1use super::prelude::*;
2
3pub(crate) struct RustcAllocatorParser;
4
5impl<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
13pub(crate) struct RustcAllocatorZeroedParser;
14
15impl<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
23pub(crate) struct RustcAllocatorZeroedVariantParser;
24
25impl<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 = ::rustc_feature::AttributeTemplate {
    word: false,
    list: None,
    one_of: &[],
    name_value_str: Some(&["function"]),
    docs: None,
}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
42pub(crate) struct RustcDeallocatorParser;
43
44impl<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
52pub(crate) struct RustcReallocatorParser;
53
54impl<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}