rustc_attr_parsing/attributes/
rustc_allocator.rs1use 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 Some(name) = nv.value_as_str() else {
31 cx.adcx().expected_string_literal(nv.value_span, Some(nv.value_as_lit()));
32 return None;
33 };
34
35 Some(AttributeKind::RustcAllocatorZeroedVariant { name })
36 }
37}
38
39pub(crate) struct RustcDeallocatorParser;
40
41impl NoArgsAttributeParser for RustcDeallocatorParser {
42 const PATH: &[Symbol] = &[sym::rustc_deallocator];
43 const ALLOWED_TARGETS: AllowedTargets =
44 AllowedTargets::AllowList(&[Allow(Target::Fn), Allow(Target::ForeignFn)]);
45 const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDeallocator;
46}
47
48pub(crate) struct RustcReallocatorParser;
49
50impl NoArgsAttributeParser for RustcReallocatorParser {
51 const PATH: &[Symbol] = &[sym::rustc_reallocator];
52 const ALLOWED_TARGETS: AllowedTargets =
53 AllowedTargets::AllowList(&[Allow(Target::Fn), Allow(Target::ForeignFn)]);
54 const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcReallocator;
55}