rustc_attr_parsing/attributes/
lint_helpers.rs1use rustc_hir::attrs::AttributeKind;
2use rustc_hir::{MethodKind, Target};
3use rustc_span::{Span, Symbol, sym};
4
5use crate::attributes::{NoArgsAttributeParser, OnDuplicate};
6use crate::context::MaybeWarn::{Allow, Error};
7use crate::context::{AllowedTargets, Stage};
8pub(crate) struct AsPtrParser;
9impl<S: Stage> NoArgsAttributeParser<S> for AsPtrParser {
10 const PATH: &[Symbol] = &[sym::rustc_as_ptr];
11 const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
12 const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
13 Allow(Target::Fn),
14 Allow(Target::Method(MethodKind::Inherent)),
15 Allow(Target::Method(MethodKind::Trait { body: false })),
16 Allow(Target::Method(MethodKind::Trait { body: true })),
17 Allow(Target::Method(MethodKind::TraitImpl)),
18 ]);
19 const CREATE: fn(Span) -> AttributeKind = AttributeKind::AsPtr;
20}
21
22pub(crate) struct PubTransparentParser;
23impl<S: Stage> NoArgsAttributeParser<S> for PubTransparentParser {
24 const PATH: &[Symbol] = &[sym::rustc_pub_transparent];
25 const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
26 const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
27 Allow(Target::Struct),
28 Allow(Target::Enum),
29 Allow(Target::Union),
30 ]);
31 const CREATE: fn(Span) -> AttributeKind = AttributeKind::PubTransparent;
32}
33
34pub(crate) struct PassByValueParser;
35impl<S: Stage> NoArgsAttributeParser<S> for PassByValueParser {
36 const PATH: &[Symbol] = &[sym::rustc_pass_by_value];
37 const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
38 const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
39 Allow(Target::Struct),
40 Allow(Target::Enum),
41 Allow(Target::TyAlias),
42 ]);
43 const CREATE: fn(Span) -> AttributeKind = AttributeKind::PassByValue;
44}
45
46pub(crate) struct AutomaticallyDerivedParser;
47impl<S: Stage> NoArgsAttributeParser<S> for AutomaticallyDerivedParser {
48 const PATH: &[Symbol] = &[sym::automatically_derived];
49 const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
50 const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowListWarnRest(&[
51 Allow(Target::Impl { of_trait: true }),
52 Error(Target::Crate),
53 Error(Target::WherePredicate),
54 ]);
55 const CREATE: fn(Span) -> AttributeKind = AttributeKind::AutomaticallyDerived;
56}