rustc_attr_parsing/attributes/
must_use.rs1use rustc_feature::AttributeStability;
2
3use super::prelude::*;
4
5pub(crate) struct MustUseParser;
6
7impl SingleAttributeParser for MustUseParser {
8 const PATH: &[Symbol] = &[sym::must_use];
9 const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnButFutureError;
10 const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowListWarnRest(&[
11 Allow(Target::Fn),
12 Allow(Target::Enum),
13 Allow(Target::Struct),
14 Allow(Target::Union),
15 Allow(Target::Method(MethodKind::Trait { body: false })),
16 Allow(Target::Method(MethodKind::Trait { body: true })),
17 Allow(Target::Method(MethodKind::Inherent)),
18 Allow(Target::ForeignFn),
19 Allow(Target::Trait),
23 Error(Target::WherePredicate),
24 Error(Target::Param),
25 ]);
26 const TEMPLATE: AttributeTemplate = crate::AttributeTemplate {
word: true,
list: None,
one_of: &[],
name_value_str: Some(&["reason"]),
docs: Some("https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute"),
}template!(
27 Word, NameValueStr: "reason",
28 "https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute"
29 );
30 const STABILITY: AttributeStability = AttributeStability::Stable;
31
32 fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
33 Some(AttributeKind::MustUse {
34 span: cx.attr_span,
35 reason: match args {
36 ArgParser::NoArgs => None,
37 ArgParser::NameValue(name_value) => cx.expect_string_literal(name_value),
38 ArgParser::List(list) => {
39 cx.adcx().expected_nv_or_no_args(list.span);
40 return None;
41 }
42 },
43 })
44 }
45}