rustc_attr_parsing/attributes/
rustc_allocator.rs1use 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 fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
32 let Some(name) = args.name_value().and_then(NameValueParser::value_as_str) else {
33 cx.expected_name_value(cx.attr_span, None);
34 return None;
35 };
36
37 Some(AttributeKind::RustcAllocatorZeroedVariant { name })
38 }
39}
40
41pub(crate) struct RustcDeallocatorParser;
42
43impl<S: Stage> NoArgsAttributeParser<S> for RustcDeallocatorParser {
44 const PATH: &[Symbol] = &[sym::rustc_deallocator];
45 const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
46 const ALLOWED_TARGETS: AllowedTargets =
47 AllowedTargets::AllowList(&[Allow(Target::Fn), Allow(Target::ForeignFn)]);
48 const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDeallocator;
49}
50
51pub(crate) struct RustcReallocatorParser;
52
53impl<S: Stage> NoArgsAttributeParser<S> for RustcReallocatorParser {
54 const PATH: &[Symbol] = &[sym::rustc_reallocator];
55 const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
56 const ALLOWED_TARGETS: AllowedTargets =
57 AllowedTargets::AllowList(&[Allow(Target::Fn), Allow(Target::ForeignFn)]);
58 const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcReallocator;
59}