rustc_attr_parsing/attributes/
test_attrs.rs1use rustc_attr_data_structures::AttributeKind;
2use rustc_attr_data_structures::lints::AttributeLintKind;
3use rustc_feature::{AttributeTemplate, template};
4use rustc_span::{Symbol, sym};
5
6use crate::attributes::{AttributeOrder, OnDuplicate, SingleAttributeParser};
7use crate::context::{AcceptContext, Stage};
8use crate::parser::ArgParser;
9
10pub(crate) struct IgnoreParser;
11
12impl<S: Stage> SingleAttributeParser<S> for IgnoreParser {
13 const PATH: &[Symbol] = &[sym::ignore];
14 const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepLast;
15 const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
16 const TEMPLATE: AttributeTemplate = template!(Word, NameValueStr: "reason");
17
18 fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
19 Some(AttributeKind::Ignore {
20 span: cx.attr_span,
21 reason: match args {
22 ArgParser::NoArgs => None,
23 ArgParser::NameValue(name_value) => {
24 let Some(str_value) = name_value.value_as_str() else {
25 let suggestions = <Self as SingleAttributeParser<S>>::TEMPLATE
26 .suggestions(false, "ignore");
27 let span = cx.attr_span;
28 cx.emit_lint(
29 AttributeLintKind::IllFormedAttributeInput { suggestions },
30 span,
31 );
32 return None;
33 };
34 Some(str_value)
35 }
36 ArgParser::List(_) => {
37 let suggestions =
38 <Self as SingleAttributeParser<S>>::TEMPLATE.suggestions(false, "ignore");
39 let span = cx.attr_span;
40 cx.emit_lint(AttributeLintKind::IllFormedAttributeInput { suggestions }, span);
41 return None;
42 }
43 },
44 })
45 }
46}