Skip to main content

rustc_attr_parsing/attributes/
lint_helpers.rs

1use super::prelude::*;
2
3pub(crate) struct RustcAsPtrParser;
4impl<S: Stage> NoArgsAttributeParser<S> for RustcAsPtrParser {
5    const PATH: &[Symbol] = &[sym::rustc_as_ptr];
6    const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
7        Allow(Target::Fn),
8        Allow(Target::Method(MethodKind::Inherent)),
9        Allow(Target::Method(MethodKind::Trait { body: false })),
10        Allow(Target::Method(MethodKind::Trait { body: true })),
11        Allow(Target::Method(MethodKind::TraitImpl)),
12    ]);
13    const CREATE: fn(Span) -> AttributeKind = AttributeKind::RustcAsPtr;
14}
15
16pub(crate) struct RustcPubTransparentParser;
17impl<S: Stage> NoArgsAttributeParser<S> for RustcPubTransparentParser {
18    const PATH: &[Symbol] = &[sym::rustc_pub_transparent];
19    const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
20        Allow(Target::Struct),
21        Allow(Target::Enum),
22        Allow(Target::Union),
23    ]);
24    const CREATE: fn(Span) -> AttributeKind = AttributeKind::RustcPubTransparent;
25}
26
27pub(crate) struct RustcPassByValueParser;
28impl<S: Stage> NoArgsAttributeParser<S> for RustcPassByValueParser {
29    const PATH: &[Symbol] = &[sym::rustc_pass_by_value];
30    const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
31        Allow(Target::Struct),
32        Allow(Target::Enum),
33        Allow(Target::TyAlias),
34    ]);
35    const CREATE: fn(Span) -> AttributeKind = AttributeKind::RustcPassByValue;
36}
37
38pub(crate) struct RustcShouldNotBeCalledOnConstItemsParser;
39impl<S: Stage> NoArgsAttributeParser<S> for RustcShouldNotBeCalledOnConstItemsParser {
40    const PATH: &[Symbol] = &[sym::rustc_should_not_be_called_on_const_items];
41    const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
42        Allow(Target::Method(MethodKind::Inherent)),
43        Allow(Target::Method(MethodKind::TraitImpl)),
44    ]);
45    const CREATE: fn(Span) -> AttributeKind = AttributeKind::RustcShouldNotBeCalledOnConstItems;
46}
47
48pub(crate) struct AutomaticallyDerivedParser;
49impl<S: Stage> NoArgsAttributeParser<S> for AutomaticallyDerivedParser {
50    const PATH: &[Symbol] = &[sym::automatically_derived];
51    const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
52    const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowListWarnRest(&[
53        Allow(Target::Impl { of_trait: true }),
54        Error(Target::Crate),
55        Error(Target::WherePredicate),
56    ]);
57    const CREATE: fn(Span) -> AttributeKind = AttributeKind::AutomaticallyDerived;
58}