Skip to main content

rustc_attr_parsing/attributes/
rustc_allocator.rs

1use super::prelude::*;
2
3pub(crate) struct RustcAllocatorParser;
4
5impl NoArgsAttributeParser for RustcAllocatorParser {
6    const PATH: &[Symbol] = &[sym::rustc_allocator];
7    const ALLOWED_TARGETS: AllowedTargets =
8        AllowedTargets::AllowList(&[Allow(Target::Fn), Allow(Target::ForeignFn)]);
9    const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcAllocator;
10}
11
12pub(crate) struct RustcAllocatorZeroedParser;
13
14impl NoArgsAttributeParser for RustcAllocatorZeroedParser {
15    const PATH: &[Symbol] = &[sym::rustc_allocator_zeroed];
16    const ALLOWED_TARGETS: AllowedTargets =
17        AllowedTargets::AllowList(&[Allow(Target::Fn), Allow(Target::ForeignFn)]);
18    const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcAllocatorZeroed;
19}
20
21pub(crate) struct RustcAllocatorZeroedVariantParser;
22
23impl SingleAttributeParser for RustcAllocatorZeroedVariantParser {
24    const PATH: &[Symbol] = &[sym::rustc_allocator_zeroed_variant];
25    const ALLOWED_TARGETS: AllowedTargets =
26        AllowedTargets::AllowList(&[Allow(Target::Fn), Allow(Target::ForeignFn)]);
27    const TEMPLATE: AttributeTemplate = ::rustc_feature::AttributeTemplate {
    word: false,
    list: None,
    one_of: &[],
    name_value_str: Some(&["function"]),
    docs: None,
}template!(NameValueStr: "function");
28    fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
29        let nv = cx.expect_name_value(args, cx.attr_span, None)?;
30        let name = cx.expect_string_literal(nv)?;
31
32        Some(AttributeKind::RustcAllocatorZeroedVariant { name })
33    }
34}
35
36pub(crate) struct RustcDeallocatorParser;
37
38impl NoArgsAttributeParser for RustcDeallocatorParser {
39    const PATH: &[Symbol] = &[sym::rustc_deallocator];
40    const ALLOWED_TARGETS: AllowedTargets =
41        AllowedTargets::AllowList(&[Allow(Target::Fn), Allow(Target::ForeignFn)]);
42    const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDeallocator;
43}
44
45pub(crate) struct RustcReallocatorParser;
46
47impl NoArgsAttributeParser for RustcReallocatorParser {
48    const PATH: &[Symbol] = &[sym::rustc_reallocator];
49    const ALLOWED_TARGETS: AllowedTargets =
50        AllowedTargets::AllowList(&[Allow(Target::Fn), Allow(Target::ForeignFn)]);
51    const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcReallocator;
52}