|
| 1 | +use rustc_attr_data_structures::AttributeKind; |
| 2 | +use rustc_attr_data_structures::lints::AttributeLintKind; |
| 3 | +use rustc_feature::{AttributeTemplate, template}; |
| 4 | +use rustc_span::{Symbol, sym}; |
| 5 | + |
| 6 | +use crate::attributes::{AttributeOrder, OnDuplicate, SingleAttributeParser}; |
| 7 | +use crate::context::{AcceptContext, Stage}; |
| 8 | +use crate::parser::ArgParser; |
| 9 | + |
| 10 | +pub(crate) struct IgnoreParser; |
| 11 | + |
| 12 | +impl<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) => name_value.value_as_str(), |
| 24 | + ArgParser::List(_) => { |
| 25 | + let suggestions = |
| 26 | + <Self as SingleAttributeParser<S>>::TEMPLATE.suggestions(false, "ignore"); |
| 27 | + let span = cx.attr_span; |
| 28 | + cx.emit_lint(AttributeLintKind::IllFormedAttributeInput { suggestions }, span); |
| 29 | + return None; |
| 30 | + } |
| 31 | + }, |
| 32 | + }) |
| 33 | + } |
| 34 | +} |
0 commit comments