Skip to main content

rustc_attr_parsing/attributes/
lint_helpers.rs

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